@gisce/react-ooui 1.2.0-rc.49 → 1.2.0-rc.50
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.
package/package.json
CHANGED
package/src/hooks/useExport.ts
CHANGED
|
@@ -338,22 +338,23 @@ const getKeysWithoutChildsInFields = ({
|
|
|
338
338
|
fields: any;
|
|
339
339
|
keys: string[];
|
|
340
340
|
}) => {
|
|
341
|
-
return [
|
|
341
|
+
return splitAndSortKeys([
|
|
342
342
|
...new Set(
|
|
343
343
|
keys
|
|
344
344
|
.filter((key) => {
|
|
345
345
|
if (key.indexOf("/") === -1) {
|
|
346
|
-
return !fields["/"][key];
|
|
346
|
+
return !fields["/"]?.[key];
|
|
347
347
|
} else {
|
|
348
|
-
|
|
348
|
+
const parentKey = getParentKey(key);
|
|
349
|
+
console.log({ key, parentKey, fields });
|
|
350
|
+
const exists = fields?.[getParentKey(key)]?.[key];
|
|
351
|
+
console.log({ exists });
|
|
352
|
+
return !fields?.[getParentKey(key)]?.[key];
|
|
349
353
|
}
|
|
350
354
|
})
|
|
351
355
|
.map((key) => getParentKey(key))
|
|
352
|
-
.sort((a, b) => {
|
|
353
|
-
return a.split("/").length - b.split("/").length;
|
|
354
|
-
})
|
|
355
356
|
),
|
|
356
|
-
];
|
|
357
|
+
]);
|
|
357
358
|
};
|
|
358
359
|
|
|
359
360
|
const retrieveKeyFieldsForPredefinedExports = async ({
|
|
@@ -398,3 +399,40 @@ const addIdToRelationFields = ({
|
|
|
398
399
|
const relationField = isRelationField(optsForField);
|
|
399
400
|
return relationField ? `${key}/id` : key;
|
|
400
401
|
});
|
|
402
|
+
|
|
403
|
+
const splitAndSortKeys = (keys: string[]): string[] => {
|
|
404
|
+
// We must split the keys that have more than one level (character / ocurrences in the string > 1)
|
|
405
|
+
// Into an array of keys with only one level
|
|
406
|
+
// For example: "partner_id/country_id/name" => ["partner_id", "partner_id/country_id", "partner_id/country_id/name"]
|
|
407
|
+
// We must do this because we must load the fields info for each key if not loaded yet in fields
|
|
408
|
+
// And we must load the fields info for the parent key first
|
|
409
|
+
//
|
|
410
|
+
// We must also sort the keys by the number of levels they have
|
|
411
|
+
// For example: ["partner_id", "partner_id/country_id", "partner_id/country_id/name"]
|
|
412
|
+
|
|
413
|
+
const keysMap: Map<string, boolean> = new Map();
|
|
414
|
+
const result: string[] = [];
|
|
415
|
+
|
|
416
|
+
// Split keys with more than one level
|
|
417
|
+
for (const key of keys) {
|
|
418
|
+
const subKeys = key.split("/");
|
|
419
|
+
let parentKey = "";
|
|
420
|
+
for (const subKey of subKeys) {
|
|
421
|
+
const currentKey = parentKey ? `${parentKey}/${subKey}` : subKey;
|
|
422
|
+
if (!keysMap.has(currentKey)) {
|
|
423
|
+
result.push(currentKey);
|
|
424
|
+
keysMap.set(currentKey, true);
|
|
425
|
+
}
|
|
426
|
+
parentKey = currentKey;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
// Sort keys by number of levels
|
|
431
|
+
result.sort((a, b) => {
|
|
432
|
+
const aLevels = a.split("/").length;
|
|
433
|
+
const bLevels = b.split("/").length;
|
|
434
|
+
return aLevels - bLevels;
|
|
435
|
+
});
|
|
436
|
+
|
|
437
|
+
return result;
|
|
438
|
+
};
|