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

Datagrids are conflicting when the resources use the same id #10382

Open
fxdave opened this issue Nov 25, 2024 · 1 comment
Open

Datagrids are conflicting when the resources use the same id #10382

fxdave opened this issue Nov 25, 2024 · 1 comment

Comments

@fxdave
Copy link

fxdave commented Nov 25, 2024

Image

What you were expecting:
first Datagrid is isolated from the second

What happened instead:
changing the first Datagrid's state changes the second Datagrid's state.

Steps to reproduce:
Have two Datagrid, both should have a row with the same id.

Related code:

export const OrganizationShow = () => (
  <Show>
    <SimpleShowLayout>
      <TextField source="id" />
      <TextField source="name" />
      <NumberField source="customMaxAllowedProperties" />
      <ArrayField source="memberships">
        <Datagrid itemID="asd">
          <TextField source="id" />
          <ReferenceField source="userId" reference="users" />
          <TextField source="role" />
          <ReferenceField source="organizationId" reference="organizations" />
          <DateField source="createdAt" />
          <DateField source="updatedAt" />
        </Datagrid>
      </ArrayField>
      <ReferenceField reference="subscriptions" source="subscription.id" />
      <ArrayField source="portfolios">
        <Datagrid>
          <TextField source="id" />
          <TextField source="name" />
          <ReferenceField source="creatorId" reference="users" />
          <ReferenceField source="organizationId" reference="organizations" />
          <DateField source="createdAt" />
          <DateField source="updatedAt" />
        </Datagrid>
      </ArrayField>
    </SimpleShowLayout>
  </Show>
);

Environment

  • React-admin version: 5.3.4
  • React version: 18.3.1
  • Browser: firefox 132.0.2-1
@fzaninotto
Copy link
Member

Thanks for your report.

By default, the selection state is linked to the current resource. This is necessary so that an existing selection can be erased in a side effect, e.g. when deleting a record.

Some list contexts can opt out of that shared global state (see for instance <ReferenceManyField storeKey>. We probably need to add support for the same storeKey to the <ArrayField> as well. A PR adding this support is welcome!

In the meantime, try passing a different resource for each ArrayField:

export const OrganizationShow = () => (
  <Show>
    <SimpleShowLayout>
      <TextField source="id" />
      <TextField source="name" />
      <NumberField source="customMaxAllowedProperties" />
-     <ArrayField source="memberships">
+     <ArrayField source="memberships" resource="memberships">
        <Datagrid itemID="asd">
          <TextField source="id" />
          <ReferenceField source="userId" reference="users" />
          <TextField source="role" />
          <ReferenceField source="organizationId" reference="organizations" />
          <DateField source="createdAt" />
          <DateField source="updatedAt" />
        </Datagrid>
      </ArrayField>
      <ReferenceField reference="subscriptions" source="subscription.id" />
-     <ArrayField source="portfolios">
+     <ArrayField source="portfolios" resource="portfolios">
        <Datagrid>
          <TextField source="id" />
          <TextField source="name" />
          <ReferenceField source="creatorId" reference="users" />
          <ReferenceField source="organizationId" reference="organizations" />
          <DateField source="createdAt" />
          <DateField source="updatedAt" />
        </Datagrid>
      </ArrayField>
    </SimpleShowLayout>
  </Show>
);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants