Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: removing a category hides items from the wrapper below #2103

Merged
merged 3 commits into from
Aug 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading