From c69c1a2d9fd04bd74b4773a9161b17221534d08d Mon Sep 17 00:00:00 2001 From: Rafal Dziegielewski Date: Fri, 22 Apr 2022 08:25:45 +0200 Subject: [PATCH] fix: add sortBy to getRecords --- src/utils.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/utils.ts b/src/utils.ts index 6db0c83..d9efc20 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -67,7 +67,17 @@ export const getFileFromRequest = (request: ActionRequest): File => { export const getRecords = async ( context: ActionContext ): Promise => { + 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', + }, }); };