Skip to content

Commit

Permalink
refactor: better breadcrumbs #258
Browse files Browse the repository at this point in the history
  • Loading branch information
0xJacky committed Jul 24, 2024
1 parent b9c7d1d commit 532d6e8
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 16 deletions.
36 changes: 24 additions & 12 deletions app/src/components/Breadcrumb/Breadcrumb.vue
Original file line number Diff line number Diff line change
@@ -1,30 +1,41 @@
<script setup lang="ts">
import { useRoute } from 'vue-router'
interface bread {
name: () => string
name: string
translatedName: () => string
path: string
hasChildren?: boolean
}
const name = ref()
const route = useRoute()
const router = useRouter()
const breadList = computed(() => {
const _breadList: bread[] = []
const result: bread[] = []
name.value = route.meta.name
route.matched.forEach(item => {
// item.name !== 'index' && this.breadList.push(item)
_breadList.push({
name: item.meta.name as never as () => string,
if (item.meta?.lastRouteName) {
const lastRoute = router.resolve({ name: item.meta.lastRouteName })
result.push({
name: lastRoute.name as string,
translatedName: lastRoute.meta.name as never as () => string,
path: lastRoute.path,
})
}
result.push({
name: item.name as string,
translatedName: item.meta.name as never as () => string,
path: item.path,
hasChildren: item.children?.length > 0,
})
})
return _breadList
return result
})
</script>

<template>
Expand All @@ -34,12 +45,13 @@ const breadList = computed(() => {
:key="item.name"
>
<RouterLink
v-if="item.name !== name && index !== 1"
v-if="index === 0 || !item.hasChildren && index !== breadList.length - 1"
:to="{ path: item.path === '' ? '/' : item.path }"
>
{{ item.name() }}
{{ item.translatedName() }}
</RouterLink>
<span v-else>{{ item.name() }}</span>
<span v-else-if="item.hasChildren">{{ item.translatedName() }}</span>
<span v-else>{{ item.translatedName() }}</span>
</ABreadcrumbItem>
</ABreadcrumb>
</template>
Expand Down
4 changes: 2 additions & 2 deletions app/src/components/NodeSelector/NodeSelector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { Environment } from '@/api/environment'
import environment from '@/api/environment'
const props = defineProps<{
target: number[]
target?: number[]
map?: Record<number, string>
hiddenLocal?: boolean
}>()
Expand Down Expand Up @@ -37,7 +37,7 @@ const value = computed({
},
set(v) {
if (typeof props.map === 'object') {
v.forEach(id => {
v?.forEach(id => {
if (id !== 0)
emit('update:map', { ...props.map, [id]: data_map.value[id].name })
})
Expand Down
3 changes: 1 addition & 2 deletions app/src/components/PageHeader/PageHeader.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<script setup lang="ts">
import { useRoute } from 'vue-router'
import Breadcrumb from '@/components/Breadcrumb/Breadcrumb.vue'
const route = useRoute()
Expand All @@ -9,7 +8,7 @@ const display = computed(() => {
})
const name = computed(() => {
return (route.meta.name as never as () => string)()
return (route.meta.name as () => string)()
})
</script>

Expand Down
5 changes: 5 additions & 0 deletions app/src/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export const routes: RouteRecordRaw[] = [
component: () => import('@/views/domain/DomainAdd.vue'),
meta: {
name: () => $gettext('Add Site'),
lastRouteName: 'Sites List',
},
}, {
path: ':name',
Expand All @@ -70,6 +71,7 @@ export const routes: RouteRecordRaw[] = [
meta: {
name: () => $gettext('Edit Site'),
hiddenInSidebar: true,
lastRouteName: 'Sites List',
},
}],
},
Expand All @@ -89,6 +91,7 @@ export const routes: RouteRecordRaw[] = [
meta: {
name: () => $gettext('Edit Stream'),
hiddenInSidebar: true,
lastRouteName: 'Manage Streams',
},
},
{
Expand Down Expand Up @@ -143,6 +146,7 @@ export const routes: RouteRecordRaw[] = [
meta: {
name: () => $gettext('Modify Certificate'),
hiddenInSidebar: true,
lastRouteName: 'Certificates List',
},
},
{
Expand All @@ -152,6 +156,7 @@ export const routes: RouteRecordRaw[] = [
meta: {
name: () => $gettext('Import Certificate'),
hiddenInSidebar: true,
lastRouteName: 'Certificates List',
},
},
{
Expand Down
1 change: 1 addition & 0 deletions app/src/routes/type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ declare module 'vue-router' {
noAuth?: boolean
status_code?: number
error?: () => string
lastRouteName?: string
}
}
1 change: 1 addition & 0 deletions app/src/views/stream/StreamList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ function handleAddStream() {
<AModal
v-model:open="showAddStream"
:title="$gettext('Add Stream')"
:mask="false"
@ok="handleAddStream"
>
<AForm layout="vertical">
Expand Down
1 change: 1 addition & 0 deletions app/src/views/user/userColumns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const columns: Column[] = [{
},
},
hiddenInTable: true,
hiddenInDetail: true,
}, {
title: () => $gettext('2FA'),
dataIndex: 'enabled_2fa',
Expand Down

0 comments on commit 532d6e8

Please # to comment.