Skip to content

Commit

Permalink
chore: add automatic routeName
Browse files Browse the repository at this point in the history
Signed-off-by: John Cowen <[email protected]>
  • Loading branch information
johncowen committed Dec 5, 2024
1 parent 92eb707 commit 0b81993
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
21 changes: 21 additions & 0 deletions packages/kuma-gui/src/app/application/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,26 @@ const addPath = (item: RouteRecordRaw, parent?: RouteRecordRaw) => {
item.meta.path = `${path}${path.length > 0 ? '.' : ''}${String(item.name)}`
}
}
const addRouteName = (item: RouteRecordRaw) => {
if (typeof item.name !== 'undefined') {
const props = ((props) => {
switch (true) {
case typeof props === 'function':
return props
case typeof props === 'undefined':
return () => ({})
default:
return () => props
}
})(item.props)
item.props = (...args) => {
return {
...props(...args),
routeName: item.name,
}
}
}
}
export const services = (app: Record<string, Token>): ServiceDefinition[] => {
return [

Expand Down Expand Up @@ -140,6 +160,7 @@ export const services = (app: Record<string, Token>): ServiceDefinition[] => {
return [
addModule,
addPath,
addRouteName,
]
},
labels: [
Expand Down
9 changes: 0 additions & 9 deletions packages/kuma-gui/src/app/data-planes/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,26 +63,17 @@ export const routes = () => {
{
path: ':dataPlane',
name: `${fullPrefix}data-plane-summary-view`,
props: () => ({
routeName: `${fullPrefix}data-plane-summary-view`,
}),
redirect: { name: `${fullPrefix}data-plane-summary-overview-view` },
component: () => import('@/app/data-planes/views/DataPlaneSummaryView.vue'),
children: [
{
path: 'summary-overview',
name: `${fullPrefix}data-plane-summary-overview-view`,
props: () => ({
routeName: `${fullPrefix}data-plane-summary-overview-view`,
}),
component: () => import('@/app/data-planes/views/DataPlaneSummaryOverviewView.vue'),
},
{
path: 'summary-config',
name: `${fullPrefix}data-plane-summary-config-view`,
props: () => ({
routeName: `${fullPrefix}data-plane-summary-config-view`,
}),
component: () => import('@/app/data-planes/views/DataPlaneSummaryConfigView.vue'),
},
],
Expand Down
9 changes: 0 additions & 9 deletions packages/kuma-gui/src/app/subscriptions/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,16 @@ export const routes = (prefix: string): RouteRecordRaw[] => {
path: 'subscription/:subscription',
name: `${prefix}-subscription-summary-view`,
redirect: { name: `${prefix}-subscription-summary-overview-view` },
props: () => ({
routeName: `${prefix}-subscription-summary-view`,
}),
component: () => import('@/app/subscriptions/views/SubscriptionSummaryView.vue'),
children: [
{
path: 'overview',
name: `${prefix}-subscription-summary-overview-view`,
props: () => ({
routeName: `${prefix}-subscription-summary-overview-view`,
}),
component: () => import('@/app/subscriptions/views/SubscriptionSummaryOverviewView.vue'),
},
{
path: 'config',
name: `${prefix}-subscription-summary-config-view`,
props: () => ({
routeName: `${prefix}-subscription-summary-config-view`,
}),
component: () => import('@/app/subscriptions/views/SubscriptionSummaryConfigView.vue'),
},
],
Expand Down

0 comments on commit 0b81993

Please sign in to comment.