feat(common): in app console UI enhancements (#5120)

Co-authored-by: nivedin <nivedinp@gmail.com>
This commit is contained in:
James George 2025-06-06 23:38:11 +05:30 committed by GitHub
parent 26cb342969
commit 5e33595c12
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 51 additions and 38 deletions

View file

@ -3,10 +3,10 @@
class="flex items-start px-4 py-2 text-tiny text-secondaryDark rounded-md" class="flex items-start px-4 py-2 text-tiny text-secondaryDark rounded-md"
:class="color" :class="color"
> >
<component :is="icon" class="mr-2 shrink-0" /> <component :is="icon" class="mr-2 shrink-0 svg-icons" />
<div class="flex flex-col space-y-1 overflow-x-auto text-xs"> <div class="flex flex-col space-y-2 overflow-x-auto text-xs flex-1">
<div class="text-secondaryLight">{{ formattedTimestamp }}</div> <div class="text-secondary">{{ formattedTimestamp }}</div>
<div class="flex flex-col space-y-1"> <div class="flex flex-col space-y-1">
<ConsoleValue <ConsoleValue

View file

@ -1,20 +1,22 @@
<template> <template>
<div class="whitespace-pre-wrap font-mono text-sm"> <div class="whitespace-pre-wrap font-mono text-[12px]">
<VueJsonPretty <VueJsonPretty
v-if="isObjectOrArray" v-if="isObjectOrArray"
:data="parsedValue" :data="parsedValue"
:theme="treeViewTheme"
:show-line="false"
:show-line-numbers="true"
:deep="2" :deep="2"
:class="snippetColors" class="p-4 bg-primary text-secondaryDark border !border-dividerLight !text-[12px] rounded !font-mono"
/> />
<pre <pre
v-else-if="isStringifiedObject" v-else-if="parsedJSON"
class="overflow-auto max-h-96 p-4" class="overflow-auto max-h-96 p-4 bg-primary text-secondaryDark border !border-dividerLight rounded"
:class="snippetColors" >{{ formattedJSONString }}
>{{ prettyStringified }}
</pre> </pre>
<pre v-else <pre v-else class="truncate"
>{{ formattedPrimitive }} >{{ formattedPrimitive }}
</pre> </pre>
</div> </div>
@ -25,52 +27,51 @@ import { computed } from "vue"
import VueJsonPretty from "vue-json-pretty" import VueJsonPretty from "vue-json-pretty"
import "vue-json-pretty/lib/styles.css" import "vue-json-pretty/lib/styles.css"
import { useColorMode } from "~/composables/theming"
const props = defineProps<{ value: unknown }>() const props = defineProps<{ value: unknown }>()
const snippetColors = ` const theme = useColorMode()
border rounded-md bg-gray-50 text-black !border-gray-200
dark:bg-gray-900 dark:text-gray-100 dark:!border-gray-700
`
const isObjectOrArray = computed(() => { const isObjectOrArray = computed(
return typeof props.value === "object" && props.value !== null () => typeof props.value === "object" && props.value !== null
}) )
const parsedJSON = computed(() => {
if (typeof props.value !== "string") {
return null
}
const isStringifiedObject = computed(() => {
if (typeof props.value !== "string") return false
try { try {
const parsed = JSON.parse(props.value) const parsed = JSON.parse(props.value)
return typeof parsed === "object" && parsed !== null return typeof parsed === "object" && parsed !== null ? parsed : null
} catch { } catch {
return false return null
} }
}) })
const parsedValue = computed(() => { const parsedValue = computed(() =>
if (isObjectOrArray.value) return props.value isObjectOrArray.value ? props.value : parsedJSON.value
)
if (isStringifiedObject.value && typeof props.value === "string") { const formattedJSONString = computed(() => {
try { if (typeof props.value !== "string") {
return JSON.parse(props.value) return ""
} catch {
return null
}
} }
return null if (parsedJSON.value) {
}) // Return the original string if it looks already formatted
const hasNewlines = props.value.includes("\n")
const hasIndentation = props.value.match(/^\s{2,}["[{]/m) !== null
const prettyStringified = computed(() => { if (hasNewlines || hasIndentation) {
if (typeof props.value === "string") {
try {
const parsed = JSON.parse(props.value)
return JSON.stringify(parsed, null, 2)
} catch {
return props.value return props.value
} }
return JSON.stringify(parsedJSON.value, null, 2)
} }
return ""
return props.value
}) })
const formattedPrimitive = computed(() => { const formattedPrimitive = computed(() => {
@ -98,4 +99,16 @@ const formattedPrimitive = computed(() => {
return "[Unserializable]" return "[Unserializable]"
} }
}) })
const isDarkTheme = computed(() => ["dark", "black"].includes(theme.value))
const treeViewTheme = computed(() => (isDarkTheme.value ? "dark" : "light"))
</script> </script>
<style>
.vjs-tree-node.is-highlight,
.vjs-tree-node:hover {
background-color: var(--primary-light-color) !important;
color: var(--secondary-dark-color) !important;
}
</style>