From c7ce8c5755e0982a31f1229c41df687241bd5641 Mon Sep 17 00:00:00 2001 From: Mukul Tayal Date: Wed, 17 Jan 2024 19:21:12 +0530 Subject: [PATCH 1/6] hide and show lock keys functionality --- src/Common/Helper.tsx | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/Common/Helper.tsx b/src/Common/Helper.tsx index b3be2937d..4aaf56225 100644 --- a/src/Common/Helper.tsx +++ b/src/Common/Helper.tsx @@ -499,18 +499,20 @@ export const getFilteredChartVersions = (charts, selectedChartType) => { chartRefId: item.chartRefId, })) } -function removeEmptyObjectKeysAndNullValues(obj) { - // It recursively removes empty object keys and array values that are null + +function removeEmptyObjectKeysAndNullValues(obj, originaljsonCopy) { + // It recursively removes empty object keys and empty array keys for (let key in obj) { if (Array.isArray(obj[key])) { - if (obj[key].length === 0) continue - obj[key] = obj[key].filter((item) => item !== null) // Check if the array is empty - if (obj[key].length === 0) { - delete obj[key] // Delete the key if the array is empty + if (obj[key].length === 0 && originaljsonCopy[key].length !== 0) { + delete obj[key] } } else if (obj[key] && typeof obj[key] === 'object') { - if (removeEmptyObjectKeysAndNullValues(obj[key])) { + if ( + removeEmptyObjectKeysAndNullValues(obj[key], originaljsonCopy[key]) && + Object.keys(originaljsonCopy[key]).length !== 0 + ) { delete obj[key] } } else if (obj[key] === undefined) { @@ -520,20 +522,23 @@ function removeEmptyObjectKeysAndNullValues(obj) { return Object.keys(obj).length === 0 } -export function getUnlockedJSON(json, jsonPathArray) { +export function getUnlockedJSON(json, jsonPathArray, removeParentKeysAndEmptyArrays = false) { const jsonCopy = JSON.parse(JSON.stringify(json)) + const originaljsonCopy = JSON.parse(JSON.stringify(json)) + let removedPatches = [] let patches = jsonPathArray.flatMap((jsonPath) => { const pathsToRemove = JSONPath({ path: jsonPath, json: jsonCopy, resultType: 'all' }) - return pathsToRemove.map((result) => - Array.isArray(result.parent) - ? { op: 'replace', path: result.pointer, value: null } - : { op: 'remove', path: result.pointer }, - ) + //reversing patches to handle correct array index deletion + pathsToRemove.reverse() + return pathsToRemove.map((result) => { + //storing removed patches to have functionality of undo + removedPatches.push({ op: 'add', path: result.pointer, value: result.value }) + return { op: 'remove', path: result.pointer } + }) }) let newDocument = jsonpatch.applyPatch(jsonCopy, patches).newDocument - - removeEmptyObjectKeysAndNullValues(newDocument) - return newDocument + if (removeParentKeysAndEmptyArrays) removeEmptyObjectKeysAndNullValues(newDocument, originaljsonCopy) + return { newDocument, removedPatches: removedPatches.reverse() } } export function getLockedJSON(json, jsonPathArray: string[]) { From ac267f780889d5d125dfa444f688af4a034713c4 Mon Sep 17 00:00:00 2001 From: Mukul Tayal Date: Fri, 19 Jan 2024 14:38:02 +0530 Subject: [PATCH 2/6] beta release --- package-lock.json | 4 ++-- package.json | 2 +- src/Common/Helper.tsx | 2 ++ 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index a75816ad6..fa173172b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@devtron-labs/devtron-fe-common-lib", - "version": "0.0.51", + "version": "0.0.55-beta-2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@devtron-labs/devtron-fe-common-lib", - "version": "0.0.51", + "version": "0.0.55-beta-2", "license": "ISC", "dependencies": { "fast-json-patch": "^3.1.1", diff --git a/package.json b/package.json index 6f6e006ef..10d61af50 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@devtron-labs/devtron-fe-common-lib", - "version": "0.0.51", + "version": "0.0.55-beta-2", "description": "Supporting common component library", "main": "dist/index.js", "scripts": { diff --git a/src/Common/Helper.tsx b/src/Common/Helper.tsx index 4aaf56225..ae5c105f8 100644 --- a/src/Common/Helper.tsx +++ b/src/Common/Helper.tsx @@ -523,6 +523,8 @@ function removeEmptyObjectKeysAndNullValues(obj, originaljsonCopy) { } export function getUnlockedJSON(json, jsonPathArray, removeParentKeysAndEmptyArrays = false) { + if (!jsonPathArray.length) return { newDocument: json, removedPatches: [] } + const jsonCopy = JSON.parse(JSON.stringify(json)) const originaljsonCopy = JSON.parse(JSON.stringify(json)) let removedPatches = [] From 23e656f0d13d832853dfbf58803bc4dd2e9f4114 Mon Sep 17 00:00:00 2001 From: Mukul Tayal Date: Mon, 22 Jan 2024 13:00:11 +0530 Subject: [PATCH 3/6] newer beta release --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 6927c53fc..9d4d0bc6c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@devtron-labs/devtron-fe-common-lib", - "version": "0.0.55", + "version": "0.0.55-beta-6", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@devtron-labs/devtron-fe-common-lib", - "version": "0.0.55", + "version": "0.0.55-beta-6", "license": "ISC", "dependencies": { "fast-json-patch": "^3.1.1", diff --git a/package.json b/package.json index 6407d69b0..65cb262a1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@devtron-labs/devtron-fe-common-lib", - "version": "0.0.55", + "version": "0.0.55-beta-6", "description": "Supporting common component library", "main": "dist/index.js", "scripts": { From aaf0c7a124d7940a9043a519aed022a3e5fa9e31 Mon Sep 17 00:00:00 2001 From: Mukul Tayal Date: Tue, 23 Jan 2024 17:43:08 +0530 Subject: [PATCH 4/6] array nesting case handling --- package-lock.json | 4 ++-- package.json | 2 +- src/Common/Helper.tsx | 9 ++++++++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index 9d4d0bc6c..685d08ca0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@devtron-labs/devtron-fe-common-lib", - "version": "0.0.55-beta-6", + "version": "0.0.58-beta-3", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@devtron-labs/devtron-fe-common-lib", - "version": "0.0.55-beta-6", + "version": "0.0.58-beta-3", "license": "ISC", "dependencies": { "fast-json-patch": "^3.1.1", diff --git a/package.json b/package.json index 65cb262a1..4d947a1db 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@devtron-labs/devtron-fe-common-lib", - "version": "0.0.55-beta-6", + "version": "0.0.58-beta-3", "description": "Supporting common component library", "main": "dist/index.js", "scripts": { diff --git a/src/Common/Helper.tsx b/src/Common/Helper.tsx index 71bc10082..44d87fb45 100644 --- a/src/Common/Helper.tsx +++ b/src/Common/Helper.tsx @@ -505,8 +505,15 @@ function removeEmptyObjectKeysAndNullValues(obj, originaljsonCopy) { for (let key in obj) { if (Array.isArray(obj[key])) { // Check if the array is empty + if (obj[key].length !== 0) { + obj[key].forEach((element, index) => { + if (element === null || (typeof element === 'object' && Object.keys(element).length === 0)) + obj[key].splice(index, 1) + else removeEmptyObjectKeysAndNullValues(element, originaljsonCopy[key][index]) + }) + } if (obj[key].length === 0 && originaljsonCopy[key].length !== 0) { - delete obj[key] + delete obj[key] } } else if (obj[key] && typeof obj[key] === 'object') { if ( From b6bd6c8d1f7228ab55dde33dc568588ab75d89fc Mon Sep 17 00:00:00 2001 From: Mukul Tayal Date: Wed, 31 Jan 2024 14:56:07 +0530 Subject: [PATCH 5/6] newer beta release --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 685d08ca0..0e6b99599 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@devtron-labs/devtron-fe-common-lib", - "version": "0.0.58-beta-3", + "version": "0.0.58-beta-25", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@devtron-labs/devtron-fe-common-lib", - "version": "0.0.58-beta-3", + "version": "0.0.58-beta-25", "license": "ISC", "dependencies": { "fast-json-patch": "^3.1.1", diff --git a/package.json b/package.json index 4d947a1db..993519274 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@devtron-labs/devtron-fe-common-lib", - "version": "0.0.58-beta-3", + "version": "0.0.58-beta-25", "description": "Supporting common component library", "main": "dist/index.js", "scripts": { From ec264e3e1dde0d97c0e429b9747912ff0534c2cc Mon Sep 17 00:00:00 2001 From: Mukul Tayal Date: Mon, 5 Feb 2024 14:41:47 +0530 Subject: [PATCH 6/6] chore: release newer version for common-lib --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index a4aac8c6c..5654b5860 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@devtron-labs/devtron-fe-common-lib", - "version": "0.0.59", + "version": "0.0.60", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@devtron-labs/devtron-fe-common-lib", - "version": "0.0.59", + "version": "0.0.60", "license": "ISC", "dependencies": { "fast-json-patch": "^3.1.1", diff --git a/package.json b/package.json index bc12e87a9..80a0959bf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@devtron-labs/devtron-fe-common-lib", - "version": "0.0.59-beta-13", + "version": "0.0.60", "description": "Supporting common component library", "main": "dist/index.js", "scripts": {