Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR4814: fix deeply nested replace on row edit #4818

Merged
merged 1 commit into from
Sep 5, 2023

Conversation

bu3alwa
Copy link
Contributor

@bu3alwa bu3alwa commented Aug 24, 2023

Fix #4814 issue with deeply nested object

@Tsareff feel free to test it

@vercel
Copy link

vercel bot commented Aug 24, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
primereact ⬜️ Ignored (Inspect) Visit Preview Aug 27, 2023 11:24pm

@bu3alwa
Copy link
Contributor Author

bu3alwa commented Aug 24, 2023

@melloware can't add you as a reviewer but let me know if this is sufficient for a fix.

@bu3alwa bu3alwa changed the title PR4818: fix deeply nested replace on row edit PR4814: fix deeply nested replace on row edit Aug 24, 2023
@Tsareff
Copy link

Tsareff commented Aug 24, 2023

Hi @bu3alwa! Thanks for such a quick response! Unfortunately, I receive an error "Uncaught TypeError: "somePropertyName" is read-only". It traces to this new mutation method you've added.

@bu3alwa
Copy link
Contributor Author

bu3alwa commented Aug 24, 2023

Hi @bu3alwa! Thanks for such a quick response! Unfortunately, I receive an error "Uncaught TypeError: "somePropertyName" is read-only". It traces to this new mutation method you've added.

Thanks for testing it. What I tested yesterday didn't have anything that's read-only. I am wondering what is read-only that is causing this issue.

Are you using the same example from the reproducer link or a different one?

@Tsareff
Copy link

Tsareff commented Aug 24, 2023

Hi @bu3alwa! Thanks for such a quick response! Unfortunately, I receive an error "Uncaught TypeError: "somePropertyName" is read-only". It traces to this new mutation method you've added.

Thanks for testing it. What I tested yesterday didn't have anything that's read-only. I am wondering what is read-only that is causing this issue.

Are you using the same example from the reproducer link or a different one?

No, I'm using it in my project as a yalc linked library. As far as I understand it can't perform a mutation on currentData in editorCallback function. Moreover, line 272 let = editingRowData = { ...editingRowDataState } also was with an error. I was able to fix it with full copy const editingRowData = JSON.parse(JSON.stringify(editingRowDataState));.

@bu3alwa
Copy link
Contributor Author

bu3alwa commented Aug 24, 2023

Thanks I'll take a look soon. The json.parse method generally gets into more complications than its worth. And I think you lose Date as well. I'll do a clone instead of mutating the object.

@bu3alwa
Copy link
Contributor Author

bu3alwa commented Aug 25, 2023

ok so I am having a hard time reproducing the error you got. Can you provide and example of how you are passing the data to the column? The example you had before works well and it sound like s read only property in the object is being sent to the prop.

@Tsareff
Copy link

Tsareff commented Aug 25, 2023

ok so I am having a hard time reproducing the error you got. Can you provide and example of how you are passing the data to the column? The example you had before works well and it sound like s read only property in the object is being sent to the prop.

Hi @bu3alwa! Thank you for the feedback. Let me double-check my data then.

@melloware melloware added Type: Bug Issue contains a defect related to a specific component. Status: Pending Review Issue or pull request is being reviewed by Core Team labels Aug 25, 2023
@bu3alwa bu3alwa force-pushed the PR4814 branch 2 times, most recently from 2c2551f to 09b4123 Compare August 26, 2023 22:03
@bu3alwa
Copy link
Contributor Author

bu3alwa commented Aug 26, 2023

ok, tested and its working with the new implementation.

One thing to note that should be a separate issue when you are on the price in row edit mode example. Typing a number triggers twice when you type. There is some useEffect somewhere that's triggering twice on strict mode. Should probably be investigated on a separate ticket. My suspicion is its in InputNumber.

@bu3alwa bu3alwa requested a review from melloware August 26, 2023 22:08
components/lib/utils/ObjectUtils.js Outdated Show resolved Hide resolved
components/lib/utils/ObjectUtils.js Outdated Show resolved Hide resolved
components/lib/utils/ObjectUtils.js Show resolved Hide resolved
components/lib/utils/ObjectUtils.js Outdated Show resolved Hide resolved
components/lib/datatable/BodyCell.js Show resolved Hide resolved
components/lib/utils/utils.d.ts Outdated Show resolved Hide resolved
@bu3alwa bu3alwa force-pushed the PR4814 branch 2 times, most recently from eff5831 to 42740f9 Compare August 27, 2023 21:08
@Tsareff
Copy link

Tsareff commented Aug 28, 2023

Hi @bu3alwa! I checked one more time and the problem with read-only is indeed on my side. I found also another tricky thing. When I create Columns from array of arrays, the method onEditChange can't find editingRowIndex and row is always focused. In my case I just need 28 number inputs in one row, 4 inputs for each day of the week, that is why I'm using such a rendering.

@Tsareff
Copy link

Tsareff commented Aug 28, 2023

Hi @bu3alwa! I checked one more time and the problem with read-only is indeed on my side. I found also another tricky thing. When I create Columns from array of arrays, the method onEditChange can't find editingRowIndex and row is always focused. In my case I just need 28 number inputs in one row, 4 inputs for each day of the week, that is why I'm using such a rendering.

Maybe it is connected with the bug you mentioned earlier about useEffect in InputNumber

@Tsareff
Copy link

Tsareff commented Aug 28, 2023

I've tried also to do it manually running this app locally, not my own. If you add several Columns which should edit the same object <Column field="meta.1.code" header="Code" editor={(options) => numberEditor(options)} style={{ width: '20%' }}></Column> <Column field="meta.1.code1" header="Code 1" editor={(options) => numberEditor(options)} style={{ width: '20%' }}></Column> in the onEditChange method inBodyRow component props.editingRows will have an updated object, but e.data the previous version of it. In this case the row will be always in focused mode.

@Tsareff
Copy link

Tsareff commented Aug 28, 2023

Sorry, one more condition for an error. It happens when you have custom onRowEditChange callback. In this case the pre-built logic is not working, so I need handle the editingRows state like this
const onEditChange = ({ data = [] }) => { setEditingRows([...data].slice(-1)); }

@bu3alwa
Copy link
Contributor Author

bu3alwa commented Aug 28, 2023

To be clear are we talking about a new issue or is this part of the same issue?

And if you could please provide a example link so I can understand the problem better and use it to test locally.

@Tsareff
Copy link

Tsareff commented Aug 28, 2023

To be clear are we talking about a new issue or is this part of the same issue?

And if you could please provide a example link so I can understand the problem better and use it to test locally.

I really can't tell for sure if it connected to this problem. For me it is, since I cannot perform update if the structure of the table consist of several rows which are getting data from nested object.

Could you please tell me how to create a demo example using the PR code? I mean is it even possible to use codesandbox or smth similar?

@bu3alwa
Copy link
Contributor Author

bu3alwa commented Aug 28, 2023

To be clear are we talking about a new issue or is this part of the same issue?
And if you could please provide a example link so I can understand the problem better and use it to test locally.

I really can't tell for sure if it connected to this problem. For me it is, since I cannot perform update if the structure of the table consist of several rows which are getting data from nested object.

Could you please tell me how to create a demo example using the PR code? I mean is it even possible to use codesandbox or smth similar?

I am not sure with a specific PR but I just need it as an example code and I can copy and paste it to my local build.

@Tsareff
Copy link

Tsareff commented Aug 29, 2023

Hi @bu3alwa! I figured the problem, it is on my side, but I still would like to mention it. I'm using roweditdoc.js file for this.
This is the products array
useEffect(() => { setProducts([ {meta: {1: {code1: 123, code2: 234}}, inventoryStatus: 'INSTOCK', name: 'Bamboo Watch', price: 66} ]); }, []);

This code is for handling editing rows change. The reason for that is to use additional logic onRowEditChange.
const [editingRows, setEditingRows] = useState([]);
const onEditChange = ({ data = [] }) => { setEditingRows([...data].slice(-1)); }

Number editor:
const numberEditor = (options) => { return <InputNumber value={options.value} onChange={(e) => options.editorCallback(e.value)} />; }

These are the Columns :
<DataTable value={cloneDeep(products)} editMode="row" onRowEditComplete={onRowEditComplete} tableStyle={{ minWidth: '50rem' }} onRowEditChange={onEditChange} editingRows={editingRows}> <Column field="meta.1.code1" header="Code 1" editor={(options) => numberEditor(options)} style={{ width: '20%' }}></Column> <Column field="meta.1.code2" header="Code 2" editor={(options) => numberEditor(options)} style={{ width: '20%' }}></Column> <Column field="name" header="Name" editor={(options) => textEditor(options)} style={{ width: '20%' }}></Column> <Column field="inventoryStatus" header="Status" body={statusBodyTemplate} editor={(options) => statusEditor(options)} style={{ width: '20%' }}></Column> <Column field="price" header="Price" body={priceBodyTemplate} editor={(options) => priceEditor(options)} style={{ width: '20%' }}></Column> <Column rowEditor headerStyle={{ width: '10%', minWidth: '8rem' }} bodyStyle={{ textAlign: 'center' }}></Column> </DataTable>

I'm using cloneDeep from lodash here because in my project data is coming from the redux state and that is why I receive read-only errors. But when I use clone method the result is unexpected somehow.

@Tsareff
Copy link

Tsareff commented Sep 4, 2023

Hi @bu3alwa! Could you please tell me when this fix can be expected to be released?

@bu3alwa
Copy link
Contributor Author

bu3alwa commented Sep 4, 2023

@Tsareff I'm not an actual maintainer on here so can't give you any estimates

@melloware
Copy link
Member

Is this fix final I thought you guys were working out more scenarios?

@bu3alwa
Copy link
Contributor Author

bu3alwa commented Sep 4, 2023

@melloware I think the other issues were resolved on @Tsareff end, he can confirm. My PR should be ready to go from my end

@melloware melloware merged commit 2389547 into primefaces:master Sep 5, 2023
5 checks passed
@melloware melloware removed the Status: Pending Review Issue or pull request is being reviewed by Core Team label Sep 5, 2023
@Tsareff
Copy link

Tsareff commented Sep 6, 2023

Hi @bu3alwa @melloware! Yes, this fix is working, all other things on my side. Maybe I'm looking at a wrong place, but I don't see the new version. Could you please tell me when can I expect to use it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a defect related to a specific component.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DataTable: editorCallback does not update a value if the field name of column has nested elements
3 participants