From 8e46e8f34f8e8e610e6492d27fd2177c8ee62843 Mon Sep 17 00:00:00 2001 From: Alexandre Rousseau Date: Sat, 9 Nov 2024 14:55:24 +0100 Subject: [PATCH] feat(ui): add an option `hideRoot` for `CoreJsonViewer` - WF-104 Add an option to not show the type of the root node when it's an Object or an Array. --- .../src/components/core/content/CoreJsonViewer.vue | 12 ++++++++++++ .../shared/SharedJsonViewer/SharedJsonViewer.vue | 6 +++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/ui/src/components/core/content/CoreJsonViewer.vue b/src/ui/src/components/core/content/CoreJsonViewer.vue index 37aa60768..7cee5b185 100644 --- a/src/ui/src/components/core/content/CoreJsonViewer.vue +++ b/src/ui/src/components/core/content/CoreJsonViewer.vue @@ -4,6 +4,7 @@ :data="data ?? {}" :initial-depth="initialDepth" :enable-copy-to-json="fields.copy.value === 'yes'" + :hide-root="fields.hideRoot.value === 'yes'" /> @@ -54,6 +55,17 @@ const definition: WriterComponentDefinition = { type: FieldType.Number, init: "0", }, + hideRoot: { + name: "Hide root", + desc: "Don't show the type of the root node when it's an Object or an Array.", + type: FieldType.Text, + options: { + yes: "yes", + no: "no", + }, + default: "no", + category: FieldCategory.Style, + }, copy: { name: "Copy", desc: "If active, adds a control bar with copy JSON button.", diff --git a/src/ui/src/components/shared/SharedJsonViewer/SharedJsonViewer.vue b/src/ui/src/components/shared/SharedJsonViewer/SharedJsonViewer.vue index 8c3587018..c01186271 100644 --- a/src/ui/src/components/shared/SharedJsonViewer/SharedJsonViewer.vue +++ b/src/ui/src/components/shared/SharedJsonViewer/SharedJsonViewer.vue @@ -65,6 +65,10 @@ const props = defineProps({ type: Array as PropType, default: () => [], }, + hideRoot: { + type: Boolean, + required: false, + }, initialDepth: { type: Number, default: 0 }, enableCopyToJson: { type: Boolean, required: false }, }); @@ -73,7 +77,7 @@ defineEmits({ toggle: jsonViewerToggleEmitDefinition, }); -const isRoot = computed(() => props.path.length === 0); +const isRoot = computed(() => props.path.length === 0 && !props.hideRoot); const isRootOpen = computed( () => props.initialDepth === -1 || props.initialDepth > 0, );