@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.
- package/dist/Common/Helper.d.ts +4 -1
- package/dist/Common/Types.d.ts +0 -1
- package/dist/index.js +20 -14
- package/package.json +1 -1
- package/src/Common/Helper.tsx +23 -16
- package/src/Common/Types.ts +0 -1
package/dist/Common/Helper.d.ts
CHANGED
|
@@ -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):
|
|
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
|
package/dist/Common/Types.d.ts
CHANGED
|
@@ -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
|
|
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];
|
|
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
|
-
|
|
11819
|
-
|
|
11820
|
-
|
|
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
|
-
|
|
11825
|
-
|
|
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
package/src/Common/Helper.tsx
CHANGED
|
@@ -499,18 +499,20 @@ export const getFilteredChartVersions = (charts, selectedChartType) => {
|
|
|
499
499
|
chartRefId: item.chartRefId,
|
|
500
500
|
}))
|
|
501
501
|
}
|
|
502
|
-
|
|
503
|
-
|
|
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]
|
|
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 (
|
|
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
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
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
|
-
|
|
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[]) {
|
package/src/Common/Types.ts
CHANGED
|
@@ -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[]
|