Files
archie/ui/src/mappings/PayloadTree.vue
T
sam 461d3dc1f7
deploy / gate (push) Successful in 4m54s
Quality / check (push) Successful in 6m36s
deploy / archied-image (push) Successful in 3m23s
deploy / agent-image (push) Successful in 11s
deploy / dist-zip (push) Skipped
fix(ui): phone-width overflows in the audit's flagged rows, with an e2e check (#1757)
Grants rows and toggle groups wrap with a smaller phone label; the token
form wraps and its input flexes; the sources name column caps at full
width and its action buttons wrap; the rule-editor condition row wraps
with a full-width phone select; the payload tree indents less and breaks
long JSON leaves; the topbar instance badge truncates; org agent rows
keep Assign inline and move Rename/Suspend/Retire into a MoreMenu. New
e2e check phone-overflow.cjs visits these views at 390x844 with seeded
data and asserts no horizontal scroll.
2026-11-06 23:23:16 +11:00

88 lines
2.6 KiB
Vue

<script setup lang="ts">
import { computed } from "vue";
import {
fieldTypeFromValue,
pathAppendIndex,
pathAppendKey,
type FieldPick,
} from "./mapping-fields";
/**
* One level of a captured payload, with every key and every leaf clickable, so
* a field is bound by clicking through the real payload rather than by typing a
* JSON path -- "click through its payload, bind JSON paths" per
* docs/prds/payload-field-mapping.md. Recurses into itself for child objects
* and arrays, so depth costs nothing to support.
*
* A key is clickable in its own right: binding `data` whole is a legitimate
* choice, and the type is inferred from whatever that node happens to hold.
*/
const props = withDefaults(
defineProps<{ value: unknown; path?: string; name?: string }>(),
{ path: "", name: "" },
);
const emit = defineEmits<{ pick: [pick: FieldPick] }>();
const isBranch = computed(
() => props.value !== null && typeof props.value === "object",
);
/** This level's children, each with the path that addresses it. */
const entries = computed<Array<{ key: string; value: unknown; path: string }>>(
() => {
if (!isBranch.value) return [];
if (Array.isArray(props.value)) {
return props.value.map((child, index) => ({
key: String(index),
value: child,
path: pathAppendIndex(props.path, index),
}));
}
return Object.entries(props.value as Record<string, unknown>).map(
([key, child]) => ({
key,
value: child,
path: pathAppendKey(props.path, key),
}),
);
},
);
function pick(path: string, key: string, value: unknown): void {
emit("pick", { path, type: fieldTypeFromValue(value), name: key });
}
</script>
<template>
<ul
v-if="isBranch"
class="flex list-none flex-col gap-0.5 pl-4 font-mono text-caption max-sm:pl-2"
>
<li v-for="entry in entries" :key="entry.path" class="min-w-0">
<button
type="button"
class="focus-visible:ring-ring break-all rounded-sm px-1 text-left outline-none hover:bg-muted focus-visible:ring-2"
@click="pick(entry.path, entry.key, entry.value)"
>
{{ entry.key }}
</button>
<PayloadTree
:value="entry.value"
:path="entry.path"
:name="entry.key"
@pick="emit('pick', $event)"
/>
</li>
</ul>
<button
v-else
type="button"
class="focus-visible:ring-ring ml-1 break-all rounded-sm px-1 text-left text-fg-subtle outline-none hover:bg-muted focus-visible:ring-2"
@click="pick(path, name, value)"
>
{{ JSON.stringify(value) }}
</button>
</template>