Skip to content

Commit

Permalink
feat(policy-summary): add spec to structured view (#3579)
Browse files Browse the repository at this point in the history
This is the first part and in a follow-up I'll add more view types for
the config. Here I added the spec in a code block to the structured
view, so the user can still get all information in this view and doesn't
need to switch to YAML.

---

I added a prop to hide the `Copy as K8s` button from the code block. I
think the spec is agnostic to universal and k8s.

---


![image](https://github.com/user-attachments/assets/d7449a69-911f-405f-9be5-2c3e844a1fd0)

Part of #3489

---------

Signed-off-by: schogges <moritz.fleck@konghq.com>
  • Loading branch information
schogges authored Feb 24, 2025
1 parent 3981a1c commit e614095
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@
</template>
</DefinitionCard>
</div>

<ResourceCodeBlock
v-if="policy.spec"
:resource="{ spec: policy.spec }"
:show-k8s-copy-button="false"
/>
</template>
<template v-else>
<div>
Expand All @@ -83,6 +89,7 @@
import type { Policy } from '../data'
import { useI18n, useCan } from '@/app/application'
import DefinitionCard from '@/app/common/DefinitionCard.vue'
import ResourceCodeBlock from '@/app/x/components/x-code-block/ResourceCodeBlock.vue'
const { t } = useI18n()
const can = useCan()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ policies:
navigation:
policy-detail-view: Overview
policy-detail-config-view: YAML
spec: Spec
items:
empty: "This policy type does not exist."
types:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,50 +1,49 @@
<template>
<div>
<XCodeBlock
language="yaml"
:code="yamlUniversal"
:is-searchable="props.isSearchable"
:code-max-height="props.codeMaxHeight"
:query="props.query"
:is-filter-mode="props.isFilterMode"
:is-reg-exp-mode="props.isRegExpMode"
@query-change="emit('query-change', $event)"
@filter-mode-change="emit('filter-mode-change', $event)"
@reg-exp-mode-change="emit('reg-exp-mode-change', $event)"
>
<template #secondary-actions>
<XDisclosure
v-slot="{ expanded, toggle }"
<XCodeBlock
language="yaml"
:code="yamlUniversal"
:is-searchable="props.isSearchable"
:code-max-height="props.codeMaxHeight"
:query="props.query"
:is-filter-mode="props.isFilterMode"
:is-reg-exp-mode="props.isRegExpMode"
@query-change="emit('query-change', $event)"
@filter-mode-change="emit('filter-mode-change', $event)"
@reg-exp-mode-change="emit('reg-exp-mode-change', $event)"
>
<template #secondary-actions>
<XDisclosure
v-slot="{ expanded, toggle }"
>
<KCodeBlockIconButton
v-if="props.showK8sCopyButton"
:copy-tooltip="t('common.copyKubernetesText')"
theme="dark"
@click="() => {
if (!expanded) {
toggle()
}
}"
>
<KCodeBlockIconButton
:copy-tooltip="t('common.copyKubernetesText')"
theme="dark"
@click="() => {
if (!expanded) {
<XIcon name="copy" />{{ t('common.copyKubernetesShortText') }}
</KCodeBlockIconButton>
<XCopyButton
format="hidden"
v-slot="{ copy }"
>
<slot
:copy="(cb: CopyCallback) => {
if (expanded) {
toggle()
}
cb((text: object) => copy(toYamlRepresentation(text)), onCopyReject)
}"
>
<XIcon name="copy" />{{ t('common.copyKubernetesShortText') }}
</KCodeBlockIconButton>
<XCopyButton
format="hidden"
v-slot="{ copy }"
>
<slot
:copy="(cb: CopyCallback) => {
if (expanded) {
toggle()
}
cb((text: object) => copy(toYamlRepresentation(text)), onCopyReject)
}"
:copying="expanded"
/>
</XCopyButton>
</XDisclosure>
</template>
</XCodeBlock>
</div>
:copying="expanded"
/>
</XCopyButton>
</XDisclosure>
</template>
</XCodeBlock>
</template>

<script lang="ts" setup>
Expand All @@ -64,12 +63,14 @@ const props = withDefaults(defineProps<{
query?: string
isFilterMode?: boolean
isRegExpMode?: boolean
showK8sCopyButton?: boolean
}>(), {
codeMaxHeight: undefined,
isSearchable: false,
query: '',
isFilterMode: false,
isRegExpMode: false,
showK8sCopyButton: true,
})
const emit = defineEmits<{
Expand Down

0 comments on commit e614095

Please sign in to comment.