fix: only sxhow menu section when there are items
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
import { computed, watch } from 'vue';
|
||||
import { useLayoutStore, type MenuMode } from '@KTXC/stores/layoutStore';
|
||||
import { useIntegrationStore } from '@KTXC/stores/integrationStore';
|
||||
import type { IntegrationPointType } from '@KTXC/types/integrationTypes';
|
||||
import { useL10n } from '@KTXC/composables/useL10n';
|
||||
import Logo from '@KTXC/layouts/logo/LogoDark.vue';
|
||||
import SystemMenuGroupStatic from './LayoutSystemMenuGroupStatic.vue';
|
||||
@@ -12,25 +13,33 @@ const layoutStore = useLayoutStore();
|
||||
const integrationStore = useIntegrationStore();
|
||||
const { t } = useL10n('core');
|
||||
|
||||
const menuPointByMode: Record<MenuMode, IntegrationPointType> = {
|
||||
apps: 'app_menu',
|
||||
'user-settings': 'user_settings_menu',
|
||||
'admin-settings': 'admin_settings_menu',
|
||||
};
|
||||
|
||||
// Get all entries based on current menu mode
|
||||
const menuEntries = computed(() => {
|
||||
switch (layoutStore.menuMode) {
|
||||
case 'user-settings':
|
||||
return integrationStore.getPoint('user_settings_menu');
|
||||
case 'admin-settings':
|
||||
return integrationStore.getPoint('admin_settings_menu');
|
||||
case 'apps':
|
||||
default:
|
||||
return integrationStore.getPoint('app_menu');
|
||||
}
|
||||
const menuEntries = computed(() => integrationStore.getPoint(menuPointByMode[layoutStore.menuMode]));
|
||||
|
||||
// Only show menu modes that currently have visible items.
|
||||
const menuModes = computed((): Array<{ value: MenuMode; icon: string; label: string }> => {
|
||||
const modes: Array<{ value: MenuMode; icon: string; label: string }> = [
|
||||
{ value: 'apps', icon: 'mdi-view-dashboard', label: t('systemMenu.apps', 'Applications') },
|
||||
{ value: 'user-settings', icon: 'mdi-account-cog', label: t('systemMenu.personalSettings', 'Settings') },
|
||||
{ value: 'admin-settings', icon: 'mdi-shield-crown', label: t('systemMenu.adminSettings', 'System') },
|
||||
];
|
||||
|
||||
return modes.filter(mode => integrationStore.getPoint(menuPointByMode[mode.value]).length > 0);
|
||||
});
|
||||
|
||||
// Static list of menu modes shown as icon buttons
|
||||
const menuModes = computed((): Array<{ value: MenuMode; icon: string; label: string }> => [
|
||||
{ value: 'apps', icon: 'mdi-view-dashboard', label: t('systemMenu.apps', 'Applications') },
|
||||
{ value: 'user-settings', icon: 'mdi-account-cog', label: t('systemMenu.personalSettings', 'Settings') },
|
||||
{ value: 'admin-settings', icon: 'mdi-shield-crown', label: t('systemMenu.adminSettings', 'System') },
|
||||
]);
|
||||
// If the active menu becomes empty (for example, after a module is disabled),
|
||||
// move to the first menu that still has content.
|
||||
watch(menuModes, (availableModes) => {
|
||||
if (availableModes.length > 0 && !availableModes.some(mode => mode.value === layoutStore.menuMode)) {
|
||||
layoutStore.setMenuMode(availableModes[0].value);
|
||||
}
|
||||
}, { immediate: true });
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
@@ -84,28 +93,30 @@ export default {
|
||||
|
||||
<!-- Menu Mode Switcher -->
|
||||
<template v-slot:append>
|
||||
<v-divider />
|
||||
<div class="menu-mode-switcher d-flex justify-space-around align-center py-2">
|
||||
<v-tooltip
|
||||
v-for="mode in menuModes"
|
||||
:key="mode.value"
|
||||
location="right"
|
||||
>
|
||||
<template v-slot:activator="{ props }">
|
||||
<v-btn
|
||||
v-bind="props"
|
||||
icon
|
||||
variant="text"
|
||||
density="comfortable"
|
||||
:color="layoutStore.menuMode === mode.value ? 'primary' : undefined"
|
||||
:class="['menu-mode-btn', { 'menu-mode-btn--active': layoutStore.menuMode === mode.value }]"
|
||||
@click="layoutStore.setMenuMode(mode.value)"
|
||||
>
|
||||
<v-icon>{{ mode.icon }}</v-icon>
|
||||
</v-btn>
|
||||
</template>
|
||||
<span>{{ mode.label }}</span>
|
||||
</v-tooltip>
|
||||
<div v-if="menuModes.length">
|
||||
<v-divider />
|
||||
<div class="menu-mode-switcher d-flex justify-space-around align-center py-2">
|
||||
<v-tooltip
|
||||
v-for="mode in menuModes"
|
||||
:key="mode.value"
|
||||
location="right"
|
||||
>
|
||||
<template v-slot:activator="{ props }">
|
||||
<v-btn
|
||||
v-bind="props"
|
||||
icon
|
||||
variant="text"
|
||||
density="comfortable"
|
||||
:color="layoutStore.menuMode === mode.value ? 'primary' : undefined"
|
||||
:class="['menu-mode-btn', { 'menu-mode-btn--active': layoutStore.menuMode === mode.value }]"
|
||||
@click="layoutStore.setMenuMode(mode.value)"
|
||||
>
|
||||
<v-icon>{{ mode.icon }}</v-icon>
|
||||
</v-btn>
|
||||
</template>
|
||||
<span>{{ mode.label }}</span>
|
||||
</v-tooltip>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</v-navigation-drawer>
|
||||
|
||||
@@ -156,6 +156,10 @@ export const useIntegrationStore = defineStore('integrationStore', {
|
||||
|
||||
return Array.from(point.items.values())
|
||||
.filter(entry => entry.visible !== false)
|
||||
.map(entry => 'items' in entry
|
||||
? { ...entry, items: entry.items.filter(item => item.visible !== false) }
|
||||
: entry)
|
||||
.filter(entry => !('items' in entry) || entry.items.length > 0)
|
||||
.sort((a, b) => (a.priority ?? 100) - (b.priority ?? 100));
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user