@balena/ui-shared-components 14.0.1-build-bump-typescript-to-5-9-2-31dbec9f4f68887ab6fc1fbeae9778554f2c46e2-1 → 14.0.1-build-sdk23-orderby-e357d5b8ffc1975aa61a5978370ee31a3b72fcc7-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,5 +7,5 @@ interface FilterMutation extends JSONSchema {
7
7
  $or?: any[];
8
8
  }
9
9
  export declare const convertToPineClientFilter: (parentKeys: string[], filter: FilterMutation | FilterMutation[]) => PineFilterObject | undefined;
10
- export declare const orderbyBuilder: <T>(sortInfo: TableSortOptions<T> | null, customSort: RJSTContext<T>["customSort"]) => string[] | null;
10
+ export declare const orderbyBuilder: <T>(sortInfo: TableSortOptions<T> | null, customSort: RJSTContext<T>["customSort"]) => {}[] | null;
11
11
  export {};
@@ -176,6 +176,43 @@ export const convertToPineClientFilter = (parentKeys, filter) => {
176
176
  }
177
177
  return handlePrimitiveFilter(parentKeys, filter);
178
178
  };
179
+ const keyToOrderByStructure = (path, direction) => {
180
+ console.log('*** path', path);
181
+ // Step 1: Normalize the path.
182
+ // Replace bracket notation like [0] with dot notation like .0
183
+ // This makes splitting the path into consistent parts easier.
184
+ const parts = path.replace(/\[(\d+)\]/g, '/$1').split('/');
185
+ const result = {};
186
+ // Step 2: Define the recursive helper function.
187
+ // This function will traverse the parts and build the object.
188
+ const build = (currentObject, currentParts) => {
189
+ var _a;
190
+ const key = currentParts.shift();
191
+ // If key is undefined (e.g. empty string), we stop.
192
+ if (!key) {
193
+ return;
194
+ }
195
+ // Base Case: If there are no more parts left, we've reached
196
+ // the end of the path. Assign the value to the current key.
197
+ if (currentParts.length === 0) {
198
+ currentObject[key] = direction;
199
+ return;
200
+ }
201
+ // Recursive Step: If there are more parts, we need to go deeper.
202
+ // We peek at the *next* part to decide if we need to create
203
+ // an Array or an Object for the current key.
204
+ const nextKey = currentParts[0];
205
+ const needsArray = /^\d+$/.test(nextKey);
206
+ // If the path doesn't exist yet, create it.
207
+ // Create an array if the next part is a number, otherwise an object.
208
+ (_a = currentObject[key]) !== null && _a !== void 0 ? _a : (currentObject[key] = needsArray ? [] : {});
209
+ // Make the recursive call on the next level down.
210
+ build(currentObject[key], currentParts);
211
+ };
212
+ // Step 3: Kick off the recursion.
213
+ build(result, parts);
214
+ return result;
215
+ };
179
216
  export const orderbyBuilder = (sortInfo, customSort) => {
180
217
  var _a, _b;
181
218
  if (!sortInfo) {
@@ -190,7 +227,10 @@ export const orderbyBuilder = (sortInfo, customSort) => {
190
227
  // The refScheme will reference the property path, e.g., owns_items[0].uuid.
191
228
  const customOrderByKey = (_b = (_a = customSort === null || customSort === void 0 ? void 0 : customSort[`${field}_${refScheme}`]) !== null && _a !== void 0 ? _a : customSort === null || customSort === void 0 ? void 0 : customSort[field]) !== null && _b !== void 0 ? _b : (typeof sortInfo.sortable === 'string' ? sortInfo.sortable : undefined);
192
229
  if (typeof customOrderByKey === 'string') {
193
- return [`${customOrderByKey} ${direction}`, `id ${direction}`];
230
+ return [
231
+ keyToOrderByStructure(customOrderByKey, direction),
232
+ { id: direction },
233
+ ];
194
234
  }
195
235
  if (Array.isArray(customOrderByKey)) {
196
236
  if (customOrderByKey.length === 0 ||
@@ -198,8 +238,8 @@ export const orderbyBuilder = (sortInfo, customSort) => {
198
238
  throw new Error(`Field ${field} error: custom sort for this field must be of type string or a non empty string array, ${customOrderByKey.join(',')} is not accepted.`);
199
239
  }
200
240
  return [
201
- ...customOrderByKey.map((k) => `${k} ${direction}`),
202
- `id ${direction}`,
241
+ ...customOrderByKey.map((k) => keyToOrderByStructure(k, direction)),
242
+ { id: direction },
203
243
  ];
204
244
  }
205
245
  if (customOrderByKey != null && typeof customOrderByKey !== 'string') {
@@ -209,5 +249,5 @@ export const orderbyBuilder = (sortInfo, customSort) => {
209
249
  if (refScheme) {
210
250
  fieldPath += `/${refScheme.replace(/\[(.*?)\]/g, '').replace(/\./g, '/')}`;
211
251
  }
212
- return [`${fieldPath} ${direction}`, `id ${direction}`];
252
+ return [keyToOrderByStructure(fieldPath, direction), { id: direction }];
213
253
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@balena/ui-shared-components",
3
- "version": "14.0.1-build-bump-typescript-to-5-9-2-31dbec9f4f68887ab6fc1fbeae9778554f2c46e2-1",
3
+ "version": "14.0.1-build-sdk23-orderby-e357d5b8ffc1975aa61a5978370ee31a3b72fcc7-1",
4
4
  "main": "./dist/index.js",
5
5
  "sideEffects": false,
6
6
  "files": [
@@ -49,7 +49,7 @@
49
49
  "remark-gfm": "^4.0.0",
50
50
  "rimraf": "^6.0.0",
51
51
  "ts-jest": "^29.2.5",
52
- "typescript": "^5.9.2",
52
+ "typescript": "^5.8.2",
53
53
  "virtua": "^0.37.3",
54
54
  "zxcvbn": "^4.4.2"
55
55
  },
@@ -132,7 +132,7 @@
132
132
  },
133
133
  "homepage": "https://github.com/balena-io/ui-shared-components#readme",
134
134
  "versionist": {
135
- "publishedAt": "2025-08-01T09:00:14.477Z"
135
+ "publishedAt": "2025-09-03T12:11:52.365Z"
136
136
  },
137
137
  "overrides": {
138
138
  "storybook": "$storybook"