From d528f03905cf06551a0769af0f96046c8b6177d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ml=C3=A1dek?= Date: Sun, 12 Nov 2023 11:26:46 +0100 Subject: [PATCH] feat(webui): distinguish between correctly & incorrectly typed members in Inspect --- webui/src/components/Inspect.svelte | 84 +++++++++++++++++++++++++---- 1 file changed, 75 insertions(+), 9 deletions(-) diff --git a/webui/src/components/Inspect.svelte b/webui/src/components/Inspect.svelte index b03966c..88550b2 100644 --- a/webui/src/components/Inspect.svelte +++ b/webui/src/components/Inspect.svelte @@ -4,11 +4,11 @@ import UpObject from "./display/UpObject.svelte"; import { createEventDispatcher } from "svelte"; import { derived, type Readable } from "svelte/store"; - import type { UpEntry } from "@upnd/upend"; + import { Query, type UpEntry } from "@upnd/upend"; import Spinner from "./utils/Spinner.svelte"; import NotesEditor from "./utils/NotesEditor.svelte"; import type { WidgetChange } from "../types/base"; - import type { EntityInfo } from "@upnd/upend/types"; + import type { Address, EntityInfo } from "@upnd/upend/types"; import IconButton from "./utils/IconButton.svelte"; import { Link } from "svelte-navigator"; import BlobViewer from "./display/BlobViewer.svelte"; @@ -26,6 +26,7 @@ import InspectTypeEditor from "./InspectTypeEditor.svelte"; import LabelBorder from "./utils/LabelBorder.svelte"; import { debug } from "debug"; + import { Any } from "@upnd/upend/query"; const dbg = debug("kestrel:Inspect"); const dispatch = createEventDispatcher(); @@ -181,6 +182,46 @@ } } + let correctlyTagged: Address[] | undefined; + let incorrectlyTagged: Address[] | undefined; + $: { + if ($entity?.attr[`~${ATTR_OF}`]) { + fetchCorrectlyTagged(); + } + } + + async function fetchCorrectlyTagged() { + const attributes = ( + await Promise.all( + $entity?.attr[`~${ATTR_OF}`].map((e) => + api.addressToComponents(e.entity), + ), + ) + ) + .filter((ac) => ac.t == "Attribute") + .map((ac) => ac.c); + + const attributeQuery = await api.query( + Query.matches( + tagged.map((t) => `@${t.entity}`), + attributes, + Any, + ), + ); + + correctlyTagged = []; + incorrectlyTagged = []; + + for (const element of tagged) { + const entity = attributeQuery.getObject(element.entity); + if (attributes.every((attr) => entity.attr[attr])) { + correctlyTagged = [...correctlyTagged, element.entity]; + } else { + incorrectlyTagged = [...incorrectlyTagged, element.entity]; + } + } + } + async function onChange(ev: CustomEvent) { dbg("onChange", ev.detail); const change = ev.detail; @@ -416,13 +457,38 @@ /> {/if} - + {#if !correctlyTagged || !incorrectlyTagged} + + {:else} + + correctlyTagged.includes(e.entity), + )} + on:change={onChange} + {address} + /> + + incorrectlyTagged.includes(e.entity), + )} + on:change={onChange} + {address} + /> + {/if} {#if currentBacklinks.length > 0}