Skip to content

Commit

Permalink
fix: removing a category hides items from the wrapper below (#2103)
Browse files Browse the repository at this point in the history
* fix: removing a category hides items from the wrapper below

* refactor: improve variable names
  • Loading branch information
Meierschlumpf authored Aug 8, 2024
1 parent 76d46ec commit 47c4011
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions src/components/Dashboard/Wrappers/Category/useCategoryActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,42 +185,58 @@ export const useCategoryActions = (configName: string | undefined, category: Cat
updateConfig(
configName,
(previous) => {
const currentItem = previous.categories.find((category) => category.id === category.id);
const currentItem = previous.categories.find(
(previousCategory) => previousCategory.id === category.id
);
if (!currentItem) return previous;

const currentWrapper = previous.wrappers.find(
(previousWrapper) => previousWrapper.position === currentItem?.position
);
if (!currentWrapper) return previous;

// Find the main wrapper
const mainWrapper = previous.wrappers.find((wrapper) => wrapper.position === 0);
const mainWrapper = previous.wrappers.find(
(previousWrapper) => previousWrapper.position === 0
);
const mainWrapperId = mainWrapper?.id ?? 'default';

const isAppAffectedFilter = (app: AppType): boolean => {
if (!app.area) {
return false;
}

if (app.area.type !== 'category') {
if (app.area.type === 'sidebar') {
return false;
}

if (app.area.properties.id === mainWrapperId) {
return false;
}

return app.area.properties.id === currentItem.id;
return (
app.area.properties.id === currentItem.id ||
app.area.properties.id === currentWrapper.id
);
};

const isWidgetAffectedFilter = (widget: IWidget<string, any>): boolean => {
if (!widget.area) {
return false;
}

if (widget.area.type !== 'category') {
if (widget.area.type === 'sidebar') {
return false;
}

if (widget.area.properties.id === mainWrapperId) {
return false;
}

return widget.area.properties.id === currentItem.id;
return (
widget.area.properties.id === currentItem.id ||
widget.area.properties.id === currentWrapper.id
);
};

return {
Expand Down Expand Up @@ -261,9 +277,11 @@ export const useCategoryActions = (configName: string | undefined, category: Cat
})
),
],
categories: previous.categories.filter((category) => category.id !== category.id),
categories: previous.categories.filter(
(previousCategory) => previousCategory.id !== category.id
),
wrappers: previous.wrappers.filter(
(wrapper) => wrapper.position !== currentItem.position
(previousWrapper) => previousWrapper.position !== currentItem.position
),
};
},
Expand Down

0 comments on commit 47c4011

Please sign in to comment.