Skip to content

Commit

Permalink
LeftNav in btpLayout: make 'expanded' the default state for nav item …
Browse files Browse the repository at this point in the history
…groups (#3938)

* 3911-leftnav-in-btp - make 'expanded' the default state for grouped categories

* Apply prettier

* Apply prettier

* Add unit tests

* Prettier

---------

Co-authored-by: Anna Milewska <[email protected]>
Co-authored-by: Waldemar Mazurek <[email protected]>
Co-authored-by: Johannes Doberer <[email protected]>
  • Loading branch information
4 people authored Sep 27, 2024
1 parent d039ff2 commit f6cfb82
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 1 deletion.
3 changes: 3 additions & 0 deletions core/src/navigation/LeftNav.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,9 @@
entries: [isGroup ? ['undefined', entry[1]] : entry]
};
converted.push(categoryById[catId]);
if (!NavigationHelpers.isCollapsedSuperCategory(catId) && isGroup) {
setExpandedState(entry[1], true);
}
}
}
});
Expand Down
3 changes: 3 additions & 0 deletions core/src/navigation/LeftNavGroup.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
function toggleExpanded() {
expanded = !expanded;
NavigationHelpers.storeExpandedState(navGroup.uid, expanded);
if (!navGroup.isSingleEntry) {
NavigationHelpers.storeCollapsedSuperCategoriesState(navGroup.uid, expanded)
}
}
</script>

Expand Down
20 changes: 20 additions & 0 deletions core/src/utilities/helpers/navigation-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class NavigationHelpersClass {
constructor() {
this.EXP_CAT_KEY = 'luigi.preferences.navigation.expandedCategories';
this.COL_NAV_KEY = 'luigi.preferences.navigation.collapsedNavigation';
this.COLLAPSED_SUPER_CATEGORIES_KEY = 'luigi.preferences.navigation.collapsedSuperCategories';
this.virtualGroupPrefix = '___';
}

Expand Down Expand Up @@ -322,6 +323,25 @@ class NavigationHelpersClass {
return expandedList;
}

storeCollapsedSuperCategoriesState(key, value) {
let collapsedList = JSON.parse(localStorage.getItem(this.COLLAPSED_SUPER_CATEGORIES_KEY)) || [];

if (value) {
collapsedList = collapsedList.filter(item => item !== key);
} else {
if (!collapsedList.includes(key)) {
collapsedList.push(key);
}
}

localStorage.setItem(this.COLLAPSED_SUPER_CATEGORIES_KEY, JSON.stringify(collapsedList));
}

isCollapsedSuperCategory(key) {
const collapsedList = JSON.parse(localStorage.getItem(this.COLLAPSED_SUPER_CATEGORIES_KEY)) || [];
return collapsedList.includes(key);
}

storeExpandedState(key, value, replace = false) {
let expandedList = this.loadExpandedCategories();

Expand Down
Loading

0 comments on commit f6cfb82

Please sign in to comment.