Skip to content

Commit

Permalink
feat: ✨ dataset sidebar router
Browse files Browse the repository at this point in the history
  • Loading branch information
Aydawka committed Nov 13, 2023
1 parent 3dab10a commit 2d2a6f0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/components/sidebar/DatasetSidebar.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { Icon } from "@iconify/vue";
import type { MenuOption } from "naive-ui";
import type { MenuInst, MenuOption } from "naive-ui";
import { NLayoutSider, NMenu, NSpace } from "naive-ui";
import { computed, h, ref } from "vue";
import { useRoute, useRouter } from "vue-router";
Expand Down Expand Up @@ -197,6 +197,20 @@ const showSidebar = computed(() => {
return false;
});
const selectedKeyRef = ref("1");
const menuInstRef = ref<MenuInst | null>(null);
const selectAndExpand = (key: string) => {
selectedKeyRef.value = key;
menuInstRef.value?.showOption(key);
};
router.beforeEach((to, from) => {
if (typeof to.name !== "string") return;
const name: string = to.meta && to.meta.menuItem ? (to.meta.menuItem as string) : to.name;
selectAndExpand(name);
});
</script>

<template>
Expand All @@ -213,6 +227,8 @@ const showSidebar = computed(() => {
>
<n-space vertical justify="space-between" class="h-full">
<n-menu
ref="menuInstRef"
v-model:value="selectedKeyRef"
:collapsed-width="64"
:collapsed-icon-size="22"
:default-expanded-keys="['dataset:metadata']"
Expand Down
7 changes: 7 additions & 0 deletions src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ const router = createRouter({
name: "dataset:publish:versions:new",
path: "new",
component: NewVersion,
meta: { menuItem: "dataset:publish:versions" },
},
{
path: ":versionId",
Expand All @@ -294,31 +295,37 @@ const router = createRouter({
name: "dataset:publish:version:participants",
path: "participants",
component: PublishSelectParticipants,
meta: { menuItem: "dataset:publish:versions" },
},
{
name: "dataset:publish:version:study-metadata",
path: "study-metadata",
component: PublishStudyMetadata,
meta: { menuItem: "dataset:publish:versions" },
},
{
name: "dataset:publish:version:dataset-metadata",
path: "dataset-metadata",
component: PublishDatasetMetadata,
meta: { menuItem: "dataset:publish:versions" },
},
{
name: "dataset:publish:version:changelog",
path: "changelog",
component: PublishChangelog,
meta: { menuItem: "dataset:publish:versions" },
},
{
name: "dataset:publish:version:readme",
path: "additional-readme",
component: PublishReadme,
meta: { menuItem: "dataset:publish:versions" },
},
{
name: "dataset:publish:version:summary",
path: "summary",
component: PublishSummary,
meta: { menuItem: "dataset:publish:versions" },
},
],
},
Expand Down

0 comments on commit 2d2a6f0

Please sign in to comment.