From ad8032e7a2a1c76c1bcff932d1806f395be1da14 Mon Sep 17 00:00:00 2001 From: Meier Lukas Date: Thu, 8 Aug 2024 20:41:50 +0200 Subject: [PATCH 1/2] fix: removing a category hides items from the wrapper below --- .../Wrappers/Category/useCategoryActions.tsx | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/components/Dashboard/Wrappers/Category/useCategoryActions.tsx b/src/components/Dashboard/Wrappers/Category/useCategoryActions.tsx index e2362eb38aa..46867c9331d 100644 --- a/src/components/Dashboard/Wrappers/Category/useCategoryActions.tsx +++ b/src/components/Dashboard/Wrappers/Category/useCategoryActions.tsx @@ -187,6 +187,10 @@ export const useCategoryActions = (configName: string | undefined, category: Cat (previous) => { const currentItem = previous.categories.find((x) => x.id === category.id); if (!currentItem) return previous; + + const currentWrapper = previous.wrappers.find((x) => x.position === currentItem?.position); + if (!currentWrapper) return previous; + // Find the main wrapper const mainWrapper = previous.wrappers.find((x) => x.position === 0); const mainWrapperId = mainWrapper?.id ?? 'default'; @@ -196,7 +200,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 +208,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 +219,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 +227,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 { From 25e5eb5229fd3c7e84280bb358c607a2e759d823 Mon Sep 17 00:00:00 2001 From: Meier Lukas Date: Thu, 8 Aug 2024 20:55:29 +0200 Subject: [PATCH 2/2] refactor: improve variable names --- .../Wrappers/Category/useCategoryActions.tsx | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/components/Dashboard/Wrappers/Category/useCategoryActions.tsx b/src/components/Dashboard/Wrappers/Category/useCategoryActions.tsx index 46867c9331d..83f6ecf1203 100644 --- a/src/components/Dashboard/Wrappers/Category/useCategoryActions.tsx +++ b/src/components/Dashboard/Wrappers/Category/useCategoryActions.tsx @@ -185,14 +185,20 @@ export const useCategoryActions = (configName: string | undefined, category: Cat updateConfig( configName, (previous) => { - const currentItem = previous.categories.find((x) => x.id === category.id); + const currentItem = previous.categories.find( + (previousCategory) => previousCategory.id === category.id + ); if (!currentItem) return previous; - const currentWrapper = previous.wrappers.find((x) => x.position === currentItem?.position); + const currentWrapper = previous.wrappers.find( + (previousWrapper) => previousWrapper.position === currentItem?.position + ); if (!currentWrapper) return previous; // Find the main wrapper - const mainWrapper = previous.wrappers.find((x) => x.position === 0); + const mainWrapper = previous.wrappers.find( + (previousWrapper) => previousWrapper.position === 0 + ); const mainWrapperId = mainWrapper?.id ?? 'default'; const isAppAffectedFilter = (app: AppType): boolean => { @@ -271,8 +277,12 @@ export const useCategoryActions = (configName: string | undefined, category: Cat }) ), ], - categories: previous.categories.filter((x) => x.id !== category.id), - wrappers: previous.wrappers.filter((x) => x.position !== currentItem.position), + categories: previous.categories.filter( + (previousCategory) => previousCategory.id !== category.id + ), + wrappers: previous.wrappers.filter( + (previousWrapper) => previousWrapper.position !== currentItem.position + ), }; }, true