@devtron-labs/devtron-fe-common-lib 0.0.55-beta-4 → 0.0.55-beta-6

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.
@@ -55,7 +55,10 @@ export declare const customStyles: {
55
55
  dropdownIndicator: (base: any, state: any) => any;
56
56
  };
57
57
  export declare const getFilteredChartVersions: (charts: any, selectedChartType: any) => any;
58
- export declare function getUnlockedJSON(json: any, jsonPathArray: any): any;
58
+ export declare function getUnlockedJSON(json: any, jsonPathArray: any, removeParentKeysAndEmptyArrays?: boolean): {
59
+ newDocument: any;
60
+ removedPatches: any[];
61
+ };
59
62
  export declare function getLockedJSON(json: any, jsonPathArray: string[]): any;
60
63
  /**
61
64
  * Returns a debounced variant of the function
@@ -339,7 +339,6 @@ export interface CommonNodeAttr {
339
339
  };
340
340
  appReleaseTagNames?: string[];
341
341
  tagsEditable?: boolean;
342
- isGitOpsRepoNotConfigured?: boolean;
343
342
  deploymentAppCreated?: boolean;
344
343
  isLast?: boolean;
345
344
  downstreamEnvironments?: DownstreamNodesEnvironmentsType[];
package/dist/index.js CHANGED
@@ -11787,20 +11787,18 @@ var getFilteredChartVersions = function (charts, selectedChartType) {
11787
11787
  chartRefId: item.chartRefId,
11788
11788
  }); });
11789
11789
  };
11790
- function removeEmptyObjectKeysAndNullValues(obj) {
11791
- // It recursively removes empty object keys and array values that are null
11790
+ function removeEmptyObjectKeysAndNullValues(obj, originaljsonCopy) {
11791
+ // It recursively removes empty object keys and empty array keys
11792
11792
  for (var key in obj) {
11793
11793
  if (Array.isArray(obj[key])) {
11794
- if (obj[key].length === 0)
11795
- continue;
11796
- obj[key] = obj[key].filter(function (item) { return item !== null; });
11797
11794
  // Check if the array is empty
11798
- if (obj[key].length === 0) {
11799
- delete obj[key]; // Delete the key if the array is empty
11795
+ if (obj[key].length === 0 && originaljsonCopy[key].length !== 0) {
11796
+ delete obj[key];
11800
11797
  }
11801
11798
  }
11802
11799
  else if (obj[key] && typeof obj[key] === 'object') {
11803
- if (removeEmptyObjectKeysAndNullValues(obj[key])) {
11800
+ if (removeEmptyObjectKeysAndNullValues(obj[key], originaljsonCopy[key]) &&
11801
+ Object.keys(originaljsonCopy[key]).length !== 0) {
11804
11802
  delete obj[key];
11805
11803
  }
11806
11804
  }
@@ -11810,19 +11808,27 @@ function removeEmptyObjectKeysAndNullValues(obj) {
11810
11808
  }
11811
11809
  return Object.keys(obj).length === 0;
11812
11810
  }
11813
- function getUnlockedJSON(json, jsonPathArray) {
11811
+ function getUnlockedJSON(json, jsonPathArray, removeParentKeysAndEmptyArrays) {
11812
+ if (removeParentKeysAndEmptyArrays === void 0) { removeParentKeysAndEmptyArrays = false; }
11813
+ if (!jsonPathArray.length)
11814
+ return { newDocument: json, removedPatches: [] };
11814
11815
  var jsonCopy = JSON.parse(JSON.stringify(json));
11816
+ var originaljsonCopy = JSON.parse(JSON.stringify(json));
11817
+ var removedPatches = [];
11815
11818
  var patches = jsonPathArray.flatMap(function (jsonPath) {
11816
11819
  var pathsToRemove = JSONPath({ path: jsonPath, json: jsonCopy, resultType: 'all' });
11820
+ //reversing patches to handle correct array index deletion
11821
+ pathsToRemove.reverse();
11817
11822
  return pathsToRemove.map(function (result) {
11818
- return Array.isArray(result.parent)
11819
- ? { op: 'replace', path: result.pointer, value: null }
11820
- : { op: 'remove', path: result.pointer };
11823
+ //storing removed patches to have functionality of undo
11824
+ removedPatches.push({ op: 'add', path: result.pointer, value: result.value });
11825
+ return { op: 'remove', path: result.pointer };
11821
11826
  });
11822
11827
  });
11823
11828
  var newDocument = applyPatch(jsonCopy, patches).newDocument;
11824
- removeEmptyObjectKeysAndNullValues(newDocument);
11825
- return newDocument;
11829
+ if (removeParentKeysAndEmptyArrays)
11830
+ removeEmptyObjectKeysAndNullValues(newDocument, originaljsonCopy);
11831
+ return { newDocument: newDocument, removedPatches: removedPatches.reverse() };
11826
11832
  }
11827
11833
  function getLockedJSON(json, jsonPathArray) {
11828
11834
  var jsonCopy = JSON.parse(JSON.stringify(json));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devtron-labs/devtron-fe-common-lib",
3
- "version": "0.0.55-beta-4",
3
+ "version": "0.0.55-beta-6",
4
4
  "description": "Supporting common component library",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -499,18 +499,20 @@ export const getFilteredChartVersions = (charts, selectedChartType) => {
499
499
  chartRefId: item.chartRefId,
500
500
  }))
501
501
  }
502
- function removeEmptyObjectKeysAndNullValues(obj) {
503
- // It recursively removes empty object keys and array values that are null
502
+
503
+ function removeEmptyObjectKeysAndNullValues(obj, originaljsonCopy) {
504
+ // It recursively removes empty object keys and empty array keys
504
505
  for (let key in obj) {
505
506
  if (Array.isArray(obj[key])) {
506
- if (obj[key].length === 0) continue
507
- obj[key] = obj[key].filter((item) => item !== null)
508
507
  // Check if the array is empty
509
- if (obj[key].length === 0) {
510
- delete obj[key] // Delete the key if the array is empty
508
+ if (obj[key].length === 0 && originaljsonCopy[key].length !== 0) {
509
+ delete obj[key]
511
510
  }
512
511
  } else if (obj[key] && typeof obj[key] === 'object') {
513
- if (removeEmptyObjectKeysAndNullValues(obj[key])) {
512
+ if (
513
+ removeEmptyObjectKeysAndNullValues(obj[key], originaljsonCopy[key]) &&
514
+ Object.keys(originaljsonCopy[key]).length !== 0
515
+ ) {
514
516
  delete obj[key]
515
517
  }
516
518
  } else if (obj[key] === undefined) {
@@ -520,20 +522,25 @@ function removeEmptyObjectKeysAndNullValues(obj) {
520
522
  return Object.keys(obj).length === 0
521
523
  }
522
524
 
523
- export function getUnlockedJSON(json, jsonPathArray) {
525
+ export function getUnlockedJSON(json, jsonPathArray, removeParentKeysAndEmptyArrays = false) {
526
+ if (!jsonPathArray.length) return { newDocument: json, removedPatches: [] }
527
+
524
528
  const jsonCopy = JSON.parse(JSON.stringify(json))
529
+ const originaljsonCopy = JSON.parse(JSON.stringify(json))
530
+ let removedPatches = []
525
531
  let patches = jsonPathArray.flatMap((jsonPath) => {
526
532
  const pathsToRemove = JSONPath({ path: jsonPath, json: jsonCopy, resultType: 'all' })
527
- return pathsToRemove.map((result) =>
528
- Array.isArray(result.parent)
529
- ? { op: 'replace', path: result.pointer, value: null }
530
- : { op: 'remove', path: result.pointer },
531
- )
533
+ //reversing patches to handle correct array index deletion
534
+ pathsToRemove.reverse()
535
+ return pathsToRemove.map((result) => {
536
+ //storing removed patches to have functionality of undo
537
+ removedPatches.push({ op: 'add', path: result.pointer, value: result.value })
538
+ return { op: 'remove', path: result.pointer }
539
+ })
532
540
  })
533
541
  let newDocument = jsonpatch.applyPatch(jsonCopy, patches).newDocument
534
-
535
- removeEmptyObjectKeysAndNullValues(newDocument)
536
- return newDocument
542
+ if (removeParentKeysAndEmptyArrays) removeEmptyObjectKeysAndNullValues(newDocument, originaljsonCopy)
543
+ return { newDocument, removedPatches: removedPatches.reverse() }
537
544
  }
538
545
 
539
546
  export function getLockedJSON(json, jsonPathArray: string[]) {
@@ -372,7 +372,6 @@ export interface CommonNodeAttr {
372
372
  }
373
373
  appReleaseTagNames?: string[]
374
374
  tagsEditable?: boolean
375
- isGitOpsRepoNotConfigured?: boolean
376
375
  deploymentAppCreated?: boolean
377
376
  isLast?: boolean
378
377
  downstreamEnvironments?: DownstreamNodesEnvironmentsType[]