Skip to content

Commit

Permalink
Merge pull request #1472 from culturecreates/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
sahalali authored Nov 28, 2024
2 parents d3e746a + c359e84 commit e49c3aa
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 39 deletions.
57 changes: 22 additions & 35 deletions src/components/Accordion/CalendarAccordion/CalendarAccordion.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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));
Expand All @@ -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]);

Expand Down
25 changes: 21 additions & 4 deletions src/utils/removeUneditedFallbackValues.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,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;
};

0 comments on commit e49c3aa

Please sign in to comment.