Skip to content

Commit

Permalink
chore: add storeKey to arrayfield to handle resources with same ids
Browse files Browse the repository at this point in the history
  • Loading branch information
Aijeyomah committed Dec 1, 2024
1 parent f35fb60 commit bd5b4a4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
9 changes: 5 additions & 4 deletions packages/ra-core/src/controller/list/useList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import get from 'lodash/get';
import isEqual from 'lodash/isEqual';
import { removeEmpty } from '../../util';
import { FilterPayload, RaRecord, SortPayload } from '../../types';
import { useResourceContext } from '../../core';
import { ResourceContextValue, useResourceContext } from '../../core';
import usePaginationState from '../usePaginationState';
import useSortState from '../useSortState';
import { useRecordSelection } from './useRecordSelection';
Expand Down Expand Up @@ -66,8 +66,8 @@ export const useList = <RecordType extends RaRecord = any>(
sort: initialSort,
filterCallback = (record: RecordType) => Boolean(record),
} = props;
const resource = useResourceContext(props);

const resourceFromContext = useResourceContext(props);
const resource = props.storeKey ?? resourceFromContext;
const [fetchingState, setFetchingState] = useState<boolean>(isFetching) as [
boolean,
(isFetching: boolean) => void,
Expand Down Expand Up @@ -287,7 +287,7 @@ export const useList = <RecordType extends RaRecord = any>(
onUnselectItems: selectionModifiers.clearSelection,
page,
perPage,
resource: '',
resource: resource,
refetch,
selectedIds,
setFilters,
Expand All @@ -310,6 +310,7 @@ export interface UseListOptions<RecordType extends RaRecord = any> {
perPage?: number;
sort?: SortPayload;
resource?: string;
storeKey?: string;
filterCallback?: (record: RecordType) => boolean;
}

Expand Down
12 changes: 10 additions & 2 deletions packages/ra-ui-materialui/src/field/ArrayField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,16 @@ const ArrayFieldImpl = <
>(
props: ArrayFieldProps<RecordType>
) => {
const { children, resource, perPage, sort, filter } = props;
const { children, resource, perPage, sort, filter, storeKey } = props;
const data = useFieldValue(props) || emptyArray;
const listContext = useList({ data, resource, perPage, sort, filter });
const listContext = useList({
data,
resource,
perPage,
sort,
filter,
storeKey,
});
return (
<ListContextProvider value={listContext}>
{children}
Expand All @@ -99,6 +106,7 @@ export interface ArrayFieldProps<
perPage?: number;
sort?: SortPayload;
filter?: FilterPayload;
storeKey?: string;
}

const emptyArray = [];

0 comments on commit bd5b4a4

Please sign in to comment.