From 4a8562c6b414b2179b7e2eb4519ef134e43e4e13 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 | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/utils.ts b/src/utils.ts index 6db0c83..ef83a04 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -67,7 +67,14 @@ 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', + } }); };