Skip to content

Commit bd5b4a4

Browse files
committed
chore: add storeKey to arrayfield to handle resources with same ids
1 parent f35fb60 commit bd5b4a4

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

packages/ra-core/src/controller/list/useList.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import get from 'lodash/get';
33
import isEqual from 'lodash/isEqual';
44
import { removeEmpty } from '../../util';
55
import { FilterPayload, RaRecord, SortPayload } from '../../types';
6-
import { useResourceContext } from '../../core';
6+
import { ResourceContextValue, useResourceContext } from '../../core';
77
import usePaginationState from '../usePaginationState';
88
import useSortState from '../useSortState';
99
import { useRecordSelection } from './useRecordSelection';
@@ -66,8 +66,8 @@ export const useList = <RecordType extends RaRecord = any>(
6666
sort: initialSort,
6767
filterCallback = (record: RecordType) => Boolean(record),
6868
} = props;
69-
const resource = useResourceContext(props);
70-
69+
const resourceFromContext = useResourceContext(props);
70+
const resource = props.storeKey ?? resourceFromContext;
7171
const [fetchingState, setFetchingState] = useState<boolean>(isFetching) as [
7272
boolean,
7373
(isFetching: boolean) => void,
@@ -287,7 +287,7 @@ export const useList = <RecordType extends RaRecord = any>(
287287
onUnselectItems: selectionModifiers.clearSelection,
288288
page,
289289
perPage,
290-
resource: '',
290+
resource: resource,
291291
refetch,
292292
selectedIds,
293293
setFilters,
@@ -310,6 +310,7 @@ export interface UseListOptions<RecordType extends RaRecord = any> {
310310
perPage?: number;
311311
sort?: SortPayload;
312312
resource?: string;
313+
storeKey?: string;
313314
filterCallback?: (record: RecordType) => boolean;
314315
}
315316

packages/ra-ui-materialui/src/field/ArrayField.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,16 @@ const ArrayFieldImpl = <
7979
>(
8080
props: ArrayFieldProps<RecordType>
8181
) => {
82-
const { children, resource, perPage, sort, filter } = props;
82+
const { children, resource, perPage, sort, filter, storeKey } = props;
8383
const data = useFieldValue(props) || emptyArray;
84-
const listContext = useList({ data, resource, perPage, sort, filter });
84+
const listContext = useList({
85+
data,
86+
resource,
87+
perPage,
88+
sort,
89+
filter,
90+
storeKey,
91+
});
8592
return (
8693
<ListContextProvider value={listContext}>
8794
{children}
@@ -99,6 +106,7 @@ export interface ArrayFieldProps<
99106
perPage?: number;
100107
sort?: SortPayload;
101108
filter?: FilterPayload;
109+
storeKey?: string;
102110
}
103111

104112
const emptyArray = [];

0 commit comments

Comments
 (0)