refactor, fix: move address id resolution logic to upobject
parent
1628a39550
commit
c70376e484
|
@ -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}))`
|
||||
|
|
|
@ -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 @@
|
|||
>
|
||||
<div
|
||||
class="address"
|
||||
class:identified={inferredIds.length || labels?.length}
|
||||
class:identified={inferredIds.length || addressIds.length || labels?.length}
|
||||
class:banner
|
||||
>
|
||||
<HashBadge {address} />
|
||||
|
|
Loading…
Reference in New Issue