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

refactor: remove dynamic nav items #10307

Merged
merged 1 commit into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion packages/web-runtime/src/layouts/Application.vue
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export default defineComponent({
}
},
computed: {
...mapGetters(['apps', 'activeMessages', 'configuration', 'getExtensionsWithNavItems']),
...mapGetters(['apps', 'activeMessages', 'configuration']),
isIE11() {
return !!(window as any).MSInputMethodContext && !!(document as any).documentMode
},
Expand Down
43 changes: 1 addition & 42 deletions packages/web-runtime/src/store/navigation.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
const state = {
// static nav items are set during extension loading and will not be modified later on
staticNavItems: {},
// dynamic nav items are initially empty and can be created e.g. from loaded data
dynamicNavItems: {},
closed: false
}

Expand All @@ -21,32 +19,6 @@ const mutations = {
staticNavItems[extension] = navItems
state.staticNavItems = staticNavItems
},
/**
* Use this mutation to dynamically add nav items after initialization phase, e.g. from loaded
* data. If there already is a nav item with the same name, that one will be replaced.
*
* @param state
* @param extension
* @param navItem
* @constructor
*/
ADD_NAV_ITEM(state, { extension, navItem }) {
const dynamicNavItems = { ...state.dynamicNavItems }
dynamicNavItems[extension] = dynamicNavItems[extension] || []
const index = dynamicNavItems[extension].findIndex(
(item) => item.route.path === navItem.route.path
)
if (index >= 0) {
dynamicNavItems[extension][index] = navItem
} else {
dynamicNavItems[extension].push(navItem)
}
state.dynamicNavItems = dynamicNavItems
},
/* Sets dynamic nav items */
SET_DYNAMIC_NAV_ITEMS(state, navItems) {
state.dynamicNavItems = navItems
},
SET_CLOSED(state, closed) {
state.closed = closed
}
Expand All @@ -62,8 +34,7 @@ const getters = {
*/
getNavItemsByExtension: (state, getters) => (extension) => {
const staticNavItems = state.staticNavItems[extension] || []
const dynamicNavItems = state.dynamicNavItems[extension] || []
return [...staticNavItems, ...dynamicNavItems].filter((navItem) => {
return staticNavItems.filter((navItem) => {
if (!navItem.enabled) {
// when `enabled` callback not provided: count as enabled.
return true
Expand All @@ -75,15 +46,6 @@ const getters = {
return false
}
})
},
getExtensionsWithNavItems: (state, getters) => {
// get a unique list of extension ids by collecting the ids in a set and then spreading them into an array.
const extensions = [
...new Set([...Object.keys(state.staticNavItems), ...Object.keys(state.dynamicNavItems)])
]
// return only those extension ids that really have at least one nav item.
// Context: NavItems can be removed, so the map key could still exist with an empty array of nav items.
return extensions.filter((extension) => getters.getNavItemsByExtension(extension).length > 0)
}
}

Expand All @@ -93,9 +55,6 @@ const actions = {
},
closeNavigation({ commit }) {
commit('SET_CLOSED', true)
},
clearDynamicNavItems({ commit }) {
commit('SET_DYNAMIC_NAV_ITEMS', {})
}
}
export default {
Expand Down