Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: adds XAction component #2273

Merged
merged 1 commit into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/app/data-planes/views/DataPlaneDetailView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -203,20 +203,20 @@
}
"
>
<RouterLink
<XAction
data-action
:to="{
name: ((name) => name.includes('bound') ? name.replace('-outbound-', '-inbound-') : 'connection-inbound-summary-overview-view')(String(_route.name)),
params: {
connection: item.name,
},
query: {
inactive: route.params.inactive ? null : undefined,
inactive: route.params.inactive,
},
}"
>
{{ item.name.replace('localhost', '').replace('_', ':') }}
</RouterLink>
</XAction>
</ConnectionCard>
</template>
</template>
Expand Down
1 change: 1 addition & 0 deletions src/app/x/components/x-action/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# x-action
75 changes: 75 additions & 0 deletions src/app/x/components/x-action/XAction.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<template>
<template
v-if="Object.keys(props.to).length > 0"
>
<RouterLink
:to="{
...props.to,
query,
}"
>
<slot name="default" />
</RouterLink>
</template>
<template
v-else-if="props.href.length > 0"
>
<a
:href="props.href"
target="_blank"
rel="noopener noreferrer"
>
<slot name="default" />
</a>
</template>
<template
v-else-if="props.for.length > 0"
>
<label :for="props.for">
<slot name="default" />
</label>
</template>
<template
v-else
>
<button type="button">
<slot name="default" />
</button>
</template>
</template>
<script lang="ts" setup>
import { computed } from 'vue'
import { RouterLink } 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 props = withDefaults(defineProps<{
href?: string
to?: RouteLocationRawWithBooleanQuery
for?: string
}>(), {
href: '',
to: () => ({}),
for: '',
})
const query = computed(() => {
return Object.entries(props.to.query ?? {}).reduce<Record<string, string | number | null | undefined>>((prev, [key, value]) => {
switch (true) {
case value === true:
prev[key] = null
break
case value === false:
prev[key] = undefined
break
default:
prev[key] = value as string | number | undefined
}
return prev
}, {})
})
</script>
1 change: 1 addition & 0 deletions src/app/x/components/x-teleport/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# x-teleport
10 changes: 10 additions & 0 deletions src/app/x/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
import XAction from './components/x-action/XAction.vue'
import XTeleportSlot from './components/x-teleport/XTeleportSlot.vue'
import XTeleportTemplate from './components/x-teleport/XTeleportTemplate.vue'
import type { ServiceDefinition } from '@/services/utils'
import { token } from '@/services/utils'

type Token = ReturnType<typeof token>

declare module '@vue/runtime-core' {
export interface GlobalComponents {
XAction: typeof XAction
XTeleportTemplate: typeof XTeleportTemplate
XTeleportSlot: typeof XTeleportSlot
}
}

export const services = (app: Record<string, Token>): ServiceDefinition[] => {
return [
[token('x.vue.components'),
{
service: () => {
return [
['XAction', XAction],
['XTeleportTemplate', XTeleportTemplate],
['XTeleportSlot', XTeleportSlot],
]
Expand Down