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

Change the definition of sort order to ASC|DESC #8466

Merged
merged 5 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/demo/src/invoices/InvoiceList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const InvoiceList = () => (
<List
filters={listFilters}
perPage={25}
sort={{ field: 'date', order: 'desc' }}
sort={{ field: 'date', order: 'DESC' }}
>
<Datagrid
rowClick="expand"
Expand Down
4 changes: 2 additions & 2 deletions packages/ra-core/src/controller/input/useReferenceParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ export interface ReferenceParamsOptions {

export interface ReferenceParams {
sort: string;
order: string;
order: 'ASC' | 'DESC';
page: number;
perPage: number;
filter: any;
Expand Down Expand Up @@ -320,6 +320,6 @@ const emptyObject = {};
const defaultSort = {
field: 'id',
order: SORT_ASC,
};
} as const;

const defaultParams = {};
2 changes: 1 addition & 1 deletion packages/ra-core/src/controller/list/useListController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export interface ListControllerProps<RecordType extends RaRecord = any> {
const defaultSort = {
field: 'id',
order: SORT_ASC,
};
} as const;

export interface ListControllerResult<RecordType extends RaRecord = any> {
sort: SortPayload;
Expand Down
4 changes: 2 additions & 2 deletions packages/ra-core/src/controller/list/useListParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { useIsMounted } from '../../util/hooks';

export interface ListParams {
sort: string;
order: string;
order: 'ASC' | 'DESC';
page: number;
perPage: number;
filter: any;
Expand Down Expand Up @@ -419,6 +419,6 @@ const emptyObject = {};
const defaultSort = {
field: 'id',
order: SORT_ASC,
};
} as const;

const defaultParams = {};
4 changes: 2 additions & 2 deletions packages/ra-core/src/controller/useSortState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const sortReducer = (state: SortPayload, action: Action): SortPayload => {
}
};

export const defaultSort = { field: '', order: 'ASC' };
export const defaultSort = { field: '', order: 'ASC' } as const;

/**
* Set the sort { field, order }
Expand Down Expand Up @@ -123,7 +123,7 @@ const useSortState = (initialSort: SortPayload = defaultSort): SortProps => {
[dispatch]
),
setSortOrder: useCallback(
(order: string) =>
(order: 'ASC' | 'DESC') =>
dispatch({ type: 'SET_SORT_ORDER', payload: order }),
[dispatch]
),
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface RaRecord<IdentifierType extends Identifier = Identifier>

export interface SortPayload {
field: string;
order: string;
order: 'ASC' | 'DESC';
}
export interface FilterPayload {
[k: string]: any;
Expand Down
6 changes: 3 additions & 3 deletions packages/ra-data-simple-rest/src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ describe('Data Simple REST Client', () => {
},
sort: {
field: 'title',
order: 'desc',
order: 'DESC',
},
});

expect(httpClient).toHaveBeenCalledWith(
'http://localhost:3000/posts?filter=%7B%7D&range=%5B0%2C9%5D&sort=%5B%22title%22%2C%22desc%22%5D',
'http://localhost:3000/posts?filter=%7B%7D&range=%5B0%2C9%5D&sort=%5B%22title%22%2C%22DESC%22%5D',
{
headers: {
map: {
Expand Down Expand Up @@ -61,7 +61,7 @@ describe('Data Simple REST Client', () => {
},
sort: {
field: 'title',
order: 'desc',
order: 'DESC',
},
});

Expand Down
2 changes: 1 addition & 1 deletion packages/ra-ui-materialui/src/button/ExportButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ ExportButton.propTypes = {
resource: PropTypes.string,
sort: PropTypes.exact({
field: PropTypes.string,
order: PropTypes.string,
order: PropTypes.oneOf(['ASC', 'DESC'] as const),
}),
icon: PropTypes.element,
meta: PropTypes.any,
Expand Down
6 changes: 3 additions & 3 deletions packages/ra-ui-materialui/src/field/ReferenceManyField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ ReferenceManyField.propTypes = {
source: PropTypes.string,
sort: PropTypes.exact({
field: PropTypes.string,
order: PropTypes.string,
order: PropTypes.oneOf(['ASC', 'DESC'] as const),
}),
target: PropTypes.string.isRequired,
};
Expand Down Expand Up @@ -166,7 +166,7 @@ ReferenceManyFieldView.propTypes = {
className: PropTypes.string,
sort: PropTypes.exact({
field: PropTypes.string,
order: PropTypes.string,
order: PropTypes.oneOf(['ASC', 'DESC'] as const),
}),
data: PropTypes.any,
isLoading: PropTypes.bool,
Expand All @@ -176,4 +176,4 @@ ReferenceManyFieldView.propTypes = {
};

const defaultFilter = {};
const defaultSort = { field: 'id', order: 'DESC' };
const defaultSort = { field: 'id', order: 'DESC' as const };
2 changes: 1 addition & 1 deletion packages/ra-ui-materialui/src/list/InfiniteList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ InfiniteList.propTypes = {
//@ts-ignore-line
sort: PropTypes.shape({
field: PropTypes.string,
order: PropTypes.string,
order: PropTypes.oneOf(['ASC', 'DESC'] as const),
}),
sx: PropTypes.any,
title: TitlePropType,
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-ui-materialui/src/list/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ List.propTypes = {
//@ts-ignore-line
sort: PropTypes.shape({
field: PropTypes.string,
order: PropTypes.string,
order: PropTypes.oneOf(['ASC', 'DESC'] as const),
}),
sx: PropTypes.any,
title: TitlePropType,
Expand Down
5 changes: 4 additions & 1 deletion packages/ra-ui-materialui/src/list/ListActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ export const ListActions = (props: ListActionsProps) => {

ListActions.propTypes = {
className: PropTypes.string,
sort: PropTypes.any,
sort: PropTypes.shape({
field: PropTypes.string,
order: PropTypes.oneOf(['ASC', 'DESC'] as const),
}),
displayedFilters: PropTypes.object,
exporter: PropTypes.oneOfType([PropTypes.func, PropTypes.bool]),
filters: PropTypes.element,
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-ui-materialui/src/list/datagrid/Datagrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ Datagrid.propTypes = {
className: PropTypes.string,
sort: PropTypes.exact({
field: PropTypes.string,
order: PropTypes.string,
order: PropTypes.oneOf(['ASC', 'DESC'] as const),
}),
data: PropTypes.arrayOf(PropTypes.any),
empty: PropTypes.element,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ DatagridHeader.propTypes = {
className: PropTypes.string,
sort: PropTypes.exact({
field: PropTypes.string,
order: PropTypes.string,
order: PropTypes.oneOf(['ASC', 'DESC'] as const),
}),
data: PropTypes.arrayOf(PropTypes.any),
hasExpand: PropTypes.bool,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ DatagridHeaderCell.propTypes = {
field: PropTypes.element,
sort: PropTypes.shape({
field: PropTypes.string,
order: PropTypes.string,
order: PropTypes.oneOf(['ASC', 'DESC'] as const),
}).isRequired,
isSorting: PropTypes.bool,
resource: PropTypes.string,
Expand Down