From 47c401145ded1f1d7fdb69cc7776ef809635100c Mon Sep 17 00:00:00 2001 From: Meier Lukas Date: Thu, 8 Aug 2024 20:59:55 +0200 Subject: [PATCH] fix: removing a category hides items from the wrapper below (#2103) * fix: removing a category hides items from the wrapper below * refactor: improve variable names --- .../Wrappers/Category/useCategoryActions.tsx | 34 ++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/src/components/Dashboard/Wrappers/Category/useCategoryActions.tsx b/src/components/Dashboard/Wrappers/Category/useCategoryActions.tsx index c666349d1..83f6ecf12 100644 --- a/src/components/Dashboard/Wrappers/Category/useCategoryActions.tsx +++ b/src/components/Dashboard/Wrappers/Category/useCategoryActions.tsx @@ -185,10 +185,20 @@ 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 => { @@ -196,7 +206,7 @@ export const useCategoryActions = (configName: string | undefined, category: Cat return false; } - if (app.area.type !== 'category') { + if (app.area.type === 'sidebar') { return false; } @@ -204,7 +214,10 @@ export const useCategoryActions = (configName: string | undefined, category: Cat 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): boolean => { @@ -212,7 +225,7 @@ export const useCategoryActions = (configName: string | undefined, category: Cat return false; } - if (widget.area.type !== 'category') { + if (widget.area.type === 'sidebar') { return false; } @@ -220,7 +233,10 @@ export const useCategoryActions = (configName: string | undefined, category: Cat return false; } - return widget.area.properties.id === currentItem.id; + return ( + widget.area.properties.id === currentItem.id || + widget.area.properties.id === currentWrapper.id + ); }; return { @@ -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 ), }; },