From c70376e4847ab7cb5bfe0c70ff28bcc09543389a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ml=C3=A1dek?= Date: Sun, 30 Jul 2023 17:02:33 +0200 Subject: [PATCH] refactor, fix: move address id resolution logic to upobject --- webui/src/components/Inspect.svelte | 20 +++------------- webui/src/components/display/UpObject.svelte | 25 +++++++++++++++++--- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/webui/src/components/Inspect.svelte b/webui/src/components/Inspect.svelte index 33d994c..f426d3a 100644 --- a/webui/src/components/Inspect.svelte +++ b/webui/src/components/Inspect.svelte @@ -77,34 +77,20 @@ const labelsQuery = await api.query( `(matches (in ${typeAddressesIn}) "${ATTR_LABEL}" ?)` ); - await Promise.all( - typeAddresses.map(async (address) => { + + typeAddresses.forEach((address) => { let labels = labelsQuery.getObject(address).identify(); let typeLabel: string | undefined; - await Promise.all( - (["Hash", "Uuid", "Attribute", "Url"] as ADDRESS_TYPE[]).map( - async (t) => { - if ((await api.getAddress(t)) == address) { - labels.push(`[${t}]`); - } - } - ) - ); if (typeLabel) { labels.unshift(typeLabel); } - if (!labels.length) { - labels.push(address); - } - allTypes[address] = { labels, attributes: [], }; - }) - ); + }); const attributes = await api.query( `(matches ? "${ATTR_OF}" (in ${typeAddressesIn}))` diff --git a/webui/src/components/display/UpObject.svelte b/webui/src/components/display/UpObject.svelte index 829f3b0..e7c9c01 100644 --- a/webui/src/components/display/UpObject.svelte +++ b/webui/src/components/display/UpObject.svelte @@ -10,7 +10,7 @@ import { vaultInfo } from "../../util/info"; import type { BrowseContext } from "../../util/browse"; import type { UpObject } from "upend"; - import type { EntityInfo } from "upend/types"; + import type { ADDRESS_TYPE, EntityInfo } from "upend/types"; import { useEntity } from "../../lib/entity"; import api from "../../lib/api"; const dispatch = createEventDispatcher(); @@ -31,11 +31,30 @@ // Identification let inferredIds: string[] = []; $: inferredIds = $entity?.identify() || []; + let addressIds: string[] = []; $: resolving = inferredIds.concat(labels || []).length == 0 && !$entity; + $: fetchAddressLabels(address); + async function fetchAddressLabels(address: string) { + addressIds = []; + await Promise.all( + (["Hash", "Uuid", "Attribute", "Url"] as ADDRESS_TYPE[]).map( + async (t) => { + if ((await api.getAddress(t)) == address) { + addressIds.push(`∈ ${t}`); + } + } + ) + ); + addressIds = addressIds; + } + let displayLabel = address; $: { - const allLabels = [].concat(inferredIds).concat(labels || []); + const allLabels = [] + .concat(inferredIds) + .concat(addressIds) + .concat(labels || []); displayLabel = Array.from(new Set(allLabels)).join(" | "); if (!displayLabel && $entityInfo?.t === "Attribute") { @@ -98,7 +117,7 @@ >