Skip to content

Commit

Permalink
chore: adds additional error message to XAction and use it in service…
Browse files Browse the repository at this point in the history
…/policy listings (#2411)

chore: adds additional error message to XAction and use it

Signed-off-by: John Cowen <[email protected]>
  • Loading branch information
johncowen committed Apr 12, 2024
1 parent d30ed91 commit e865b09
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/app/policies/views/PolicyListView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
@change="route.update"
>
<template #name="{ row }">
<RouterLink
<XAction
:to="{
name: 'policy-summary-view',
params: {
Expand All @@ -119,7 +119,7 @@
}"
>
{{ row.name }}
</RouterLink>
</XAction>
</template>
<template #namespace="{ row: item }">
{{ item.namespace.length > 0 ? item.namespace : t('common.detail.none') }}
Expand Down Expand Up @@ -157,7 +157,7 @@
</template>
<template #details="{ row }">
<RouterLink
<XAction
class="details-link"
data-testid="details-link"
:to="{
Expand All @@ -175,7 +175,7 @@
decorative
:size="KUI_ICON_SIZE_30"
/>
</RouterLink>
</XAction>
</template>
</AppCollection>
<RouterView
Expand Down
8 changes: 4 additions & 4 deletions src/app/services/views/ServiceListView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
>
<template #name="{ row: item }">
<TextWithCopyButton :text="item.name">
<RouterLink
<XAction
:to="{
name: 'service-detail-view',
params: {
Expand All @@ -61,7 +61,7 @@
}"
>
{{ item.name }}
</RouterLink>
</XAction>
</TextWithCopyButton>
</template>
Expand Down Expand Up @@ -94,7 +94,7 @@
</template>
<template #details="{ row }">
<RouterLink
<XAction
class="details-link"
data-testid="details-link"
:to="{
Expand All @@ -111,7 +111,7 @@
decorative
:size="KUI_ICON_SIZE_30"
/>
</RouterLink>
</XAction>
</template>
</AppCollection>
</KCard>
Expand Down
18 changes: 17 additions & 1 deletion src/app/x/components/x-action/XAction.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,15 @@
</template>
<script lang="ts" setup>
import { computed, watch } from 'vue'
import { RouterLink } from 'vue-router'
import { RouterLink, useRouter } from 'vue-router'
import type { RouteLocationNamedRaw } from 'vue-router'
type BooleanLocationQueryValue = string | number | undefined | boolean
type BooleanLocationQueryRaw = Record<string | number, BooleanLocationQueryValue | BooleanLocationQueryValue[]>
type RouteLocationRawWithBooleanQuery = Omit<RouteLocationNamedRaw, 'query'> & {
query?: BooleanLocationQueryRaw
}
const router = useRouter()
const props = withDefaults(defineProps<{
href?: string
Expand Down Expand Up @@ -74,6 +75,7 @@ const query = computed(() => {
return prev
}, {})
})
watch(() => props.mount, (val) => {
if (typeof val === 'function') {
val({
Expand All @@ -82,4 +84,18 @@ watch(() => props.mount, (val) => {
})
}
}, { immediate: true })
watch(() => props.to, (val) => {
try {
router.resolve({
...val,
query: query.value,
})
} catch (e) {
if (e instanceof Error) {
e.message = `${e.toString()}: ${JSON.stringify(val)}`
}
console.error(e)
}
}, { immediate: true })
</script>

0 comments on commit e865b09

Please sign in to comment.