Skip to content
This repository has been archived by the owner on Jan 16, 2025. It is now read-only.

Commit

Permalink
Make OData sorting predictable and unique
Browse files Browse the repository at this point in the history
Change-type: patch
  • Loading branch information
Andrea Rosci authored and Andrea Rosci committed Mar 5, 2024
1 parent 2e768cb commit 9d1faf3
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/oData/jsonToOData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ export const orderbyBuilder = <T>(
const direction = !reverse ? 'asc' : 'desc';
const customOrderByKey = customSort?.[field];
if (typeof customOrderByKey === 'string') {
return `${customOrderByKey} ${direction}`;
return [`${customOrderByKey} ${direction}`, `id ${direction}`];
} else if (customOrderByKey != null && typeof customOrderByKey !== 'string') {
throw new Error(
`Field ${field} error: custom sort for this field must be of type string, ${typeof customOrderByKey} is not accepted.`,
Expand All @@ -241,7 +241,5 @@ export const orderbyBuilder = <T>(
if (refScheme) {
fieldPath += `/${refScheme.replace(/\[(.*?)\]/g, '').replace(/\./g, '/')}`;
}
return {
[fieldPath]: direction,
};
return [`${fieldPath} ${direction}`, `id ${direction}`];
};

0 comments on commit 9d1faf3

Please sign in to comment.