Skip to content

Commit 4d0c059

Browse files
committed
feat: update help buttons to dynamically generate documentation links
- Refactored the help buttons component to replace the static documentation link with a computed property that generates the link based on the current route. - Added utility functions to construct the route pattern and collapse dynamic segments for improved documentation navigation. - Enhanced user experience by ensuring the documentation link reflects the current context within the application.
1 parent 8a7e60a commit 4d0c059

File tree

1 file changed

+57
-1
lines changed

1 file changed

+57
-1
lines changed

apps/web/src/components/core/help-buttons.vue

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44
q-tooltip.text-body2(anchor="top middle" self="bottom middle") Mode sombre/clair
55
q-btn.q-px-sm(flat stretch icon="mdi-frequently-asked-questions" :href="getQAndALink" target="_blank" :size="size")
66
q-tooltip.text-body2 Poser une question ou signaler un problème
7-
q-btn.q-px-sm(flat stretch icon="mdi-help" href="https://libertech-fr.github.io/sesame-doc/" target="_blank" :size="size")
7+
q-btn.q-px-sm(flat stretch icon="mdi-help" :href="getDocumentationLink" target="_blank" :size="size")
88
q-tooltip.text-body2 Aide et Documentation
99
</template>
1010

1111
<script lang="ts">
12+
import { computed } from 'vue'
13+
import { useRoute } from 'vue-router'
14+
1215
export default defineNuxtComponent({
1316
name: 'HelpButtonsComponent',
1417
props: {
@@ -46,9 +49,62 @@ export default defineNuxtComponent({
4649
updateAvailable?: boolean
4750
}>('daemonVersion', {})
4851
52+
const route = useRoute()
53+
54+
const docsBaseUrl = 'https://libertech-fr.github.io/sesame-doc'
55+
56+
const getRoutePatternPath = () => {
57+
const matched = route.matched ?? []
58+
if (matched.length === 0) return route.path
59+
60+
// Vue Router stocke des segments dynamiques sous la forme `:param`.
61+
// On reconstruit un chemin complet avec ces placeholders pour pointer vers la doc.
62+
let pattern = ''
63+
for (const record of matched) {
64+
const p = record.path
65+
if (!p) continue
66+
67+
if (p === '/') {
68+
pattern = '/'
69+
continue
70+
}
71+
72+
if (p.startsWith('/')) {
73+
pattern = p
74+
} else {
75+
pattern = `${pattern.endsWith('/') ? pattern.slice(0, -1) : pattern}/${p}`
76+
}
77+
}
78+
79+
pattern = pattern.replace(/\/+/g, '/')
80+
pattern = pattern.replace(/:([A-Za-z0-9_]+)\([^/]*\)/g, ':$1')
81+
return pattern === '' ? '/' : pattern.startsWith('/') ? pattern : `/${pattern}`
82+
}
83+
84+
const collapseDynamicSegments = (path: string) => {
85+
if (path === '/') return '/'
86+
const segments = path.split('/').filter(Boolean)
87+
88+
const kept: string[] = []
89+
for (const seg of segments) {
90+
if (seg.startsWith(':')) break
91+
kept.push(seg)
92+
}
93+
94+
return `/${kept.join('/')}`
95+
}
96+
97+
const getDocumentationLink = computed(() => {
98+
const pattern = getRoutePatternPath()
99+
const docRoute = collapseDynamicSegments(pattern)
100+
const docPath = docRoute === '/' ? '/pages/index.html' : `/pages${docRoute}.html`
101+
return `${docsBaseUrl}${docPath}`
102+
})
103+
49104
return {
50105
orchestratorVersion,
51106
daemonVersion,
107+
getDocumentationLink,
52108
}
53109
},
54110
methods: {

0 commit comments

Comments
 (0)