Skip to content

Commit

Permalink
fix: add sortBy to getRecords
Browse files Browse the repository at this point in the history
  • Loading branch information
dziraf committed Apr 22, 2022
1 parent 99c430c commit dae1803
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,17 @@ export const getFileFromRequest = (request: ActionRequest): File => {
export const getRecords = async (
context: ActionContext
): Promise<BaseRecord[]> => {
const idProperty = context.resource
.properties()
.find(p => p.isId())
?.name?.();
const titleProperty = context.resource.decorate().titleProperty()?.name?.();

return context.resource.find(new Filter({}, context.resource), {
limit: Number.MAX_SAFE_INTEGER,
sort: {
sortBy: idProperty ?? titleProperty,
direction: 'asc',
},
});
};

0 comments on commit dae1803

Please sign in to comment.