@gen3/core 0.11.42 → 0.11.44

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/dist/cjs/index.js CHANGED
@@ -2411,6 +2411,59 @@ const explorerTags = guppyApi.enhanceEndpoints({
2411
2411
  variables
2412
2412
  };
2413
2413
  },
2414
+ // return . seperated fields as proper values
2415
+ transformResponse: (response, _meta, args)=>{
2416
+ const containsDots = args?.fields?.filter((f)=>f.includes('.'));
2417
+ // check if dot seperated in arry and not object
2418
+ if (containsDots && containsDots.length > 0 && response.data) {
2419
+ const containsDotsUniqueBase = containsDots.reduce((acc, field)=>{
2420
+ const partsArr = field.split('.');
2421
+ if (partsArr.length < 2) {
2422
+ throw new Error('Explorer does not support field with more than one \'.\' separator\'t');
2423
+ }
2424
+ const basePart = partsArr[0];
2425
+ if (!acc.includes(basePart)) {
2426
+ acc.push(basePart);
2427
+ }
2428
+ return acc;
2429
+ }, []);
2430
+ // checks if api is returning an array of objects for the base part
2431
+ // if so, it restructures the object to group the sub parts into arrays
2432
+ // e.g. {a: [{b: 1, c:2}, {b:3, c:4}]} becomes {a: {b: [1,3], c:[2,4]}}
2433
+ // this is to make it easier to work with in the table component
2434
+ // currently only supports one level of nesting
2435
+ // also puts original into subRows for dropdown viewing
2436
+ const tempResponse = response.data[args.type].map((item)=>{
2437
+ const tempItem = item;
2438
+ for(let i = 0; i < containsDotsUniqueBase.length; i++){
2439
+ const basePart = containsDotsUniqueBase[i];
2440
+ if (item[basePart] && Array.isArray(item[basePart])) {
2441
+ // move original to subRows
2442
+ tempItem.subRows = tempItem[basePart];
2443
+ tempItem[basePart] = tempItem[basePart].reduce((acc, obj)=>{
2444
+ for(const key in obj){
2445
+ if (Object.hasOwn(obj, key)) {
2446
+ if (!acc[key]) {
2447
+ acc[key] = [];
2448
+ }
2449
+ acc[key].push(obj[key]);
2450
+ }
2451
+ }
2452
+ return acc;
2453
+ }, {});
2454
+ }
2455
+ }
2456
+ return tempItem;
2457
+ });
2458
+ return {
2459
+ data: {
2460
+ _aggregation: response.data._aggregation,
2461
+ [args.type]: tempResponse
2462
+ }
2463
+ };
2464
+ }
2465
+ return response;
2466
+ },
2414
2467
  providesTags: [
2415
2468
  'RAW_DATA',
2416
2469
  'TABLE_DATA'