From 765d02facf41699e34002259c7c399f8c08b7721 Mon Sep 17 00:00:00 2001 From: Abhishek P Anil Date: Wed, 27 Nov 2024 15:43:47 +0530 Subject: [PATCH 1/3] fix: optimised code and added support for image type object closes #https://github.com/culturecreates/tech-support-tickets/issues/104 --- .../CalendarAccordion/CalendarAccordion.jsx | 57 +++++++------------ 1 file changed, 22 insertions(+), 35 deletions(-) diff --git a/src/components/Accordion/CalendarAccordion/CalendarAccordion.jsx b/src/components/Accordion/CalendarAccordion/CalendarAccordion.jsx index a796242c..8ba6ec1e 100644 --- a/src/components/Accordion/CalendarAccordion/CalendarAccordion.jsx +++ b/src/components/Accordion/CalendarAccordion/CalendarAccordion.jsx @@ -84,6 +84,22 @@ function CalendarAccordion(props) { const calendarContentLanguage = currentCalendarData?.contentLanguage; + const processEntities = (entities) => { + if (!entities) return []; + return entities.map((v) => ({ + ...v, + image: Array.isArray(v?.image) + ? v?.image.find((image) => image?.isMain) || null + : typeof v?.image === 'object' && v?.image !== null + ? v?.image + : null, + })); + }; + + const updateList = (entities, setter) => { + setter(treeEntitiesOption(processEntities(entities), user, calendarContentLanguage, sourceOptions.CMS)); + }; + const organizationPersonSearch = (value, type) => { const queryMap = { organizers: query, @@ -95,25 +111,10 @@ function CalendarAccordion(props) { getEntities({ searchKey: value, classes: decodeURIComponent(currentQuery.toString()), calendarId }) .unwrap() .then((response) => { - if (type == 'organizers') { - setOrganizersList( - treeEntitiesOption( - response?.map((v) => ({ ...v, image: v?.image?.find((image) => image?.isMain) })), - user, - calendarContentLanguage, - sourceOptions.CMS, - ), - ); - } - if (type == 'people') { - setPeopleList( - treeEntitiesOption( - response?.map((v) => ({ ...v, image: v?.image?.find((image) => image?.isMain) })), - user, - calendarContentLanguage, - sourceOptions.CMS, - ), - ); + if (type === 'organizers') { + updateList(response, setOrganizersList); + } else if (type === 'people') { + updateList(response, setPeopleList); } }) .catch((error) => console.log(error)); @@ -131,27 +132,13 @@ function CalendarAccordion(props) { useEffect(() => { if (initialEntities && currentCalendarData) { - setOrganizersList( - treeEntitiesOption( - initialEntities?.map((v) => ({ ...v, image: v?.image?.find((image) => image?.isMain) })), - user, - calendarContentLanguage, - sourceOptions.CMS, - ), - ); + updateList(initialEntities, setOrganizersList); } }, [initialEntityLoading, currentCalendarData]); useEffect(() => { if (initialPersonEntities && currentCalendarData) { - setPeopleList( - treeEntitiesOption( - initialPersonEntities?.map((v) => ({ ...v, image: v?.image?.find((image) => image?.isMain) })), - user, - calendarContentLanguage, - sourceOptions.CMS, - ), - ); + updateList(initialPersonEntities, setPeopleList); } }, [initialPersonEntityLoading, currentCalendarData]); From f2daafcd81f050d695fa005e27aa59f6b5ce2de9 Mon Sep 17 00:00:00 2001 From: syam babu Date: Thu, 28 Nov 2024 15:26:45 +0530 Subject: [PATCH 2/3] 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 3/3] 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);