react-admin icon indicating copy to clipboard operation
react-admin copied to clipboard

EditableDatagridConfigurable more than one in same page does not refresh after save when mutationMode is pessimistic

Open Ferlorin opened this issue 2 years ago • 3 comments

What you were expecting: After saving a row, the data should refresh with the latest updates

What happened instead: The data remained the same

Steps to reproduce: Create an EditableDatagridConfigurable and add a second one in the same page for the same Resource, each one under their own ReferenceManyField then set storeKey and change mutationMode to pessimistic in the EditableDatagridConfigurable

Related code:

<ReferenceManyField target="booking" reference={"bookingCharges"} filter={{ receivable: true}} storeKey={preferenceKey}>
            {record &&
                <EditableDatagridConfigurable
                    omit={['id', 'booking']}
                    data-testid="store-datagrid"
                    rowClick="edit"
                    createForm={<ChargeForm bookingId={record?.id} receivable={true} >{children}</ChargeForm>}
                    editForm={<ChargeForm bookingId={record?.id} receivable={true} >{children}</ChargeForm>}
                    mutationMode="pessimistic"
                    style={{ marginBottom: '1em' }}
                    preferenceKey={preferenceKey}
                >
                    <TextField source="id" />
                    <NumberField source="amount" />
                    <NumberField source="quantity" />
                    <TextField source="remarks" component={"pre"} aria-multiline={true} />
                    <TextField source="booking" />
                </EditableDatagridConfigurable>
            }
        </ReferenceManyField>
<ReferenceManyField target="booking" reference={"bookingCharges"} filter={{ receivable: false}} storeKey={preferenceKey}>
            {record &&
                <EditableDatagridConfigurable
                    omit={['id', 'booking']}
                    data-testid="store-datagrid"
                    rowClick="edit"
                    createForm={<ChargeForm bookingId={record?.id} receivable={false}  />}
                    editForm={<ChargeForm bookingId={record?.id} receivable={false} />}
                    mutationMode="pessimistic"
                    style={{ marginBottom: '1em' }}
                    preferenceKey={preferenceKey}
                >
                    <TextField source="id" />
                    <NumberField source="amount" />
                    <NumberField source="quantity" />
                    <TextField source="remarks" component={"pre"} aria-multiline={true} />
                    <TextField source="booking" />
                </EditableDatagridConfigurable>
            }
        </ReferenceManyField>

and

interface ChargeFormProps {
   bookingId: Identifier,
   receivable: boolean,
}

const ChargeForm = (props: ChargeFormProps) => {

   return (
       <RowForm>
           <NumberInput source="amount" />
           <NumberInput source="quantity" />
           <TextInput source="remarks" multiline />
           <div style={{ display: 'none' }}> {/* display none doesnt seem to work on boolean input */}
               <BooleanInput source="receivable" defaultValue={props.receivable} disabled />
           </div>
           <TextInput source={"booking"} defaultValue={props.bookingId} style={{ display: 'none' }} />
       </RowForm>
   )
};

Environment

  • React-admin version: 5.2.0
  • Last version that did not exhibit the issue (if applicable): N/A because in earlier versions there was no storeKey
  • React version: 18.3.1
  • Browser: Chrome

Ferlorin avatar Sep 23 '24 12:09 Ferlorin

Hi @Ferlorin ,

I don't reproduce your bug. I create my own instance with the following code and your issue doesn't happen.

export const test = () => (
    <TestMemoryRouter>
        <Admin
            dataProvider={dataProvider()}
            store={memoryStore()}
            layout={MyLayout}
        >
            <Resource
                name="artists"
                list={/* ... */}
                edit={
                    <Edit>
                        <SimpleForm>
                            <ReferenceManyField
                                target="author_id"
                                reference="books"
                                storeKey={preferenceKey}
                            >
                                <EditableDatagridConfigurable
                                    createForm={
                                        <RowFormConfigurable>
                                            <TextInput source="title" />
                                        </RowFormConfigurable>
                                    }
                                    editForm={
                                        <RowFormConfigurable>
                                            <TextInput source="title" />
                                        </RowFormConfigurable>
                                    }
                                    preferenceKey={preferenceKey}
                                >
                                    <TextField source="title" />
                                </EditableDatagridConfigurable>
                            </ReferenceManyField>
                            <ReferenceManyField
                                target="author_id"
                                reference="books"
                                storeKey={preferenceKey}
                            >
                                <EditableDatagridConfigurable
                                    createForm={
                                        <RowFormConfigurable>
                                            <TextInput source="title" />
                                        </RowFormConfigurable>
                                    }
                                    editForm={
                                        <RowFormConfigurable>
                                            <TextInput source="title" />
                                        </RowFormConfigurable>
                                    }
                                    preferenceKey={preferenceKey}
                                >
                                    <TextField source="title" />
                                </EditableDatagridConfigurable>
                            </ReferenceManyField>
                        </SimpleForm>
                    </Edit>
                }
            />
        </Admin>
    </TestMemoryRouter>
);

Please provide a sample application showing the issue by forking the following Stackblitz (https://stackblitz.com/github/marmelab/react-admin/tree/master/examples/simple).

nawan-b avatar Sep 25 '24 12:09 nawan-b

It seems that later version of react-admin have the issue fixed. Will further investigate if this happens again.

Ferlorin avatar Oct 18 '24 11:10 Ferlorin

Thanks. We'll close the issue for now. Feel free to reopen if you find something.

slax57 avatar Oct 18 '24 12:10 slax57