Skip to content
Open
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
23 changes: 22 additions & 1 deletion adminforth/spa/src/components/Sidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
Default user <strong>"adminforth"</strong> detected. Delete it and create your own account.
</div>

<ul class="af-sidebar-container space-y-2 font-medium" >
<ul class="af-sidebar-container space-y-2 font-medium" @click.capture="handleURLClick">
<template v-if="!iconOnlySidebarEnabled || !isSidebarIconOnly" v-for="(item, i) in coreStore.menu" :key="`menu-${i}`">
<div v-if="item.type === 'divider'" class="border-t border-lightSidebarDevider dark:border-darkSidebarDevider"></div>
<div v-else-if="item.type === 'gap'" class="flex items-center justify-center h-8"></div>
Expand Down Expand Up @@ -306,6 +306,9 @@ import { Tooltip } from '@/afcl';
import type { AnnouncementBadgeResponse } from '@/types/Common';
import { useAdminforth } from '@/adminforth';
import { IconExclamationCircleOutline} from '@iconify-prerendered/vue-flowbite';
import { useRouter } from 'vue-router';

const router = useRouter();

const isLocalhost = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1' || window.location.hostname === '::1';

Expand Down Expand Up @@ -386,6 +389,24 @@ function clickOnMenuItem(label: string | number) {
}
}

const handleURLClick = (event: MouseEvent) => {
const target = (event.target as HTMLElement).closest('.af-sidebar-menu-link');
if (!target) return;

const label = target.textContent?.trim();
const item = coreStore.menu.find(m => m.label === label) || coreStore.menu.flatMap(m => m.children || []).find(c => c.label === label);

if (item?.url) {
event.preventDefault();
event.stopPropagation();

const { pathname, search, hash } = new URL(item.url as string, window.location.origin);
router.push(pathname + search + hash);

emit('hideSidebar');
}
};

watch(()=>coreStore.menu, () => {
coreStore.menu.forEach((item, i) => {
if (item.open) {
Expand Down
2 changes: 2 additions & 0 deletions adminforth/types/Common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1122,6 +1122,8 @@ export interface AdminForthConfigMenuItem {
* Item id will be automatically generated from hashed resourceId+Path+label
*/
itemId?: string, // todo move to runtime type

url?: string
}


Expand Down