Skip to content

Commit 3a259c9

Browse files
committed
chore: add storeKey to arrayfield to handle resources with same ids
1 parent 795bf7b commit 3a259c9

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

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

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import isEqual from 'lodash/isEqual';
44

55
import { removeEmpty } from '../../util';
66
import { FilterPayload, RaRecord, SortPayload } from '../../types';
7-
import { useResourceContext } from '../../core';
7+
import { ResourceContextValue, useResourceContext } from '../../core';
88
import usePaginationState from '../usePaginationState';
99
import useSortState from '../useSortState';
1010
import { useRecordSelection } from './useRecordSelection';
@@ -67,8 +67,8 @@ export const useList = <RecordType extends RaRecord = any, ErrorType = Error>(
6767
sort: initialSort,
6868
filterCallback = (record: RecordType) => Boolean(record),
6969
} = props;
70-
const resource = useResourceContext(props);
71-
70+
const resourceFromContext = useResourceContext(props);
71+
const resource = props.storeKey ?? resourceFromContext;
7272
const [fetchingState, setFetchingState] = useState<boolean>(isFetching) as [
7373
boolean,
7474
(isFetching: boolean) => void,
@@ -295,7 +295,7 @@ export const useList = <RecordType extends RaRecord = any, ErrorType = Error>(
295295
onUnselectItems: selectionModifiers.clearSelection,
296296
page,
297297
perPage,
298-
resource: '',
298+
resource: resource,
299299
refetch,
300300
selectedIds,
301301
setFilters,
@@ -321,6 +321,7 @@ export interface UseListOptions<
321321
perPage?: number;
322322
sort?: SortPayload;
323323
resource?: string;
324+
storeKey?: string;
324325
filterCallback?: (record: RecordType) => boolean;
325326
}
326327

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

+10-2
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)