Skip to content

Commit

Permalink
feat: rename prop to filterCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
ogustavo-pereira committed Aug 31, 2022
1 parent c42c9f1 commit ce15352
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions docs/useList.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ const {
refetch, // a function that throws an error, as refetch doesn't make sense for local data
} = getGetList({ data });
```
## `setCustomFilter`
## `filterCallback`

Property for custom filter definition. Being able to apply more complex filters using operators

Expand All @@ -254,7 +254,7 @@ const { data } = useList({
{ id: 3, name: 'Jean-Claude' },
],
sort: { field: 'name', order: 'ASC' },
setCustomFilter: (record) => record.id > 1 && record.name !== 'Jean-Claude'
filterCallback: (record) => record.id > 1 && record.name !== 'Jean-Claude'
});
// data will be
// [
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-core/src/controller/list/useList.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ describe('<useList />', () => {
<UseList
data={data}
sort={{ field: 'id', order: 'ASC' }}
setCustomFilter={record => record.id > 2}
filterCallback={record => record.id > 2}
callback={callback}
/>
);
Expand Down
8 changes: 4 additions & 4 deletions packages/ra-core/src/controller/list/useList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const refetch = () => {
* @param {Number} props.page: Optional. The initial page index
* @param {Number} props.perPage: Optional. The initial page size
* @param {SortPayload} props.sort: Optional. The initial sort (field and order)
* @param {setCustomFilter} prop.setCustomFilter Optional. A function that allows you to make a custom filter
* @param {filterCallback} prop.filterCallback Optional. A function that allows you to make a custom filter
*/
export const useList = <RecordType extends RaRecord = any>(
props: UseListOptions<RecordType>
Expand All @@ -62,7 +62,7 @@ export const useList = <RecordType extends RaRecord = any>(
page: initialPage = 1,
perPage: initialPerPage = 1000,
sort: initialSort,
setCustomFilter = (record: RecordType) => Boolean(record),
filterCallback = (record: RecordType) => Boolean(record),
} = props;
const resource = useResourceContext(props);

Expand Down Expand Up @@ -181,7 +181,7 @@ export const useList = <RecordType extends RaRecord = any>(
}
)
)
.filter(setCustomFilter);
.filter(filterCallback);
}
const filteredLength = tempData.length;

Expand Down Expand Up @@ -273,7 +273,7 @@ export interface UseListOptions<RecordType extends RaRecord = any> {
perPage?: number;
sort?: SortPayload;
resource?: string;
setCustomFilter?: (record: RecordType) => boolean;
filterCallback?: (record: RecordType) => boolean;
}

export type UseListValue<
Expand Down

0 comments on commit ce15352

Please sign in to comment.