From f2daafcd81f050d695fa005e27aa59f6b5ce2de9 Mon Sep 17 00:00:00 2001 From: syam babu Date: Thu, 28 Nov 2024 15:26:45 +0530 Subject: [PATCH 1/2] hotfix: empty virtual location being send to backend. closes #1469 --- src/utils/removeUneditedFallbackValues.js | 29 +++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/utils/removeUneditedFallbackValues.js b/src/utils/removeUneditedFallbackValues.js index 6291ede4..242bc352 100644 --- a/src/utils/removeUneditedFallbackValues.js +++ b/src/utils/removeUneditedFallbackValues.js @@ -36,6 +36,10 @@ export const filterUneditedFallbackValues = ({ if (fieldName === fieldNameFlag) requiredFallbackKeyForCurrentField = key; }); + if (fieldName == 'virtualLocation') { + console.log(emptyValueFilter(additionalFilters, values)); + } + // If no matching fallback key is found, return the original values if (!requiredFallbackKeyForCurrentField) return emptyValueFilter(additionalFilters, values); @@ -60,15 +64,32 @@ export const filterUneditedFallbackValues = ({ }; const emptyValueFilter = (additionalFilters, modifiedValues) => { - if (additionalFilters && Object.values(additionalFilters).some((value) => value === true)) { + if ( + typeof additionalFilters !== 'object' || + typeof modifiedValues !== 'object' || + !additionalFilters || + !modifiedValues + ) { + return undefined; + } + + const modifiedValuesCopy = { ...modifiedValues }; + + if (Object.values(additionalFilters).some((value) => value === true)) { Object.keys(additionalFilters).forEach((key) => { - if (Object.prototype.hasOwnProperty.call(modifiedValues, key)) { + if (Object.prototype.hasOwnProperty.call(modifiedValuesCopy, key)) { if (additionalFilters[key] === false) { - delete modifiedValues[key]; + delete modifiedValuesCopy[key]; } } }); } - return modifiedValues; + Object.keys(modifiedValuesCopy).forEach((key) => { + if (typeof modifiedValuesCopy[key] === 'string' && modifiedValuesCopy[key].trim() === '') { + delete modifiedValuesCopy[key]; + } + }); + + return Object.keys(modifiedValuesCopy).length ? modifiedValuesCopy : undefined; }; From a20190c5329e83c5d820ca2775367f3d773fddca Mon Sep 17 00:00:00 2001 From: syam babu Date: Thu, 28 Nov 2024 15:34:48 +0530 Subject: [PATCH 2/2] removed console.log --- src/utils/removeUneditedFallbackValues.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/utils/removeUneditedFallbackValues.js b/src/utils/removeUneditedFallbackValues.js index 242bc352..5480e93c 100644 --- a/src/utils/removeUneditedFallbackValues.js +++ b/src/utils/removeUneditedFallbackValues.js @@ -36,10 +36,6 @@ export const filterUneditedFallbackValues = ({ if (fieldName === fieldNameFlag) requiredFallbackKeyForCurrentField = key; }); - if (fieldName == 'virtualLocation') { - console.log(emptyValueFilter(additionalFilters, values)); - } - // If no matching fallback key is found, return the original values if (!requiredFallbackKeyForCurrentField) return emptyValueFilter(additionalFilters, values);