refactor, fix: move address id resolution logic to upobject
This commit is contained in:
parent
1628a39550
commit
c70376e484
2 changed files with 25 additions and 20 deletions
|
@ -77,34 +77,20 @@
|
||||||
const labelsQuery = await api.query(
|
const labelsQuery = await api.query(
|
||||||
`(matches (in ${typeAddressesIn}) "${ATTR_LABEL}" ?)`
|
`(matches (in ${typeAddressesIn}) "${ATTR_LABEL}" ?)`
|
||||||
);
|
);
|
||||||
await Promise.all(
|
|
||||||
typeAddresses.map(async (address) => {
|
typeAddresses.forEach((address) => {
|
||||||
let labels = labelsQuery.getObject(address).identify();
|
let labels = labelsQuery.getObject(address).identify();
|
||||||
|
|
||||||
let typeLabel: string | undefined;
|
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) {
|
if (typeLabel) {
|
||||||
labels.unshift(typeLabel);
|
labels.unshift(typeLabel);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!labels.length) {
|
|
||||||
labels.push(address);
|
|
||||||
}
|
|
||||||
|
|
||||||
allTypes[address] = {
|
allTypes[address] = {
|
||||||
labels,
|
labels,
|
||||||
attributes: [],
|
attributes: [],
|
||||||
};
|
};
|
||||||
})
|
});
|
||||||
);
|
|
||||||
|
|
||||||
const attributes = await api.query(
|
const attributes = await api.query(
|
||||||
`(matches ? "${ATTR_OF}" (in ${typeAddressesIn}))`
|
`(matches ? "${ATTR_OF}" (in ${typeAddressesIn}))`
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
import { vaultInfo } from "../../util/info";
|
import { vaultInfo } from "../../util/info";
|
||||||
import type { BrowseContext } from "../../util/browse";
|
import type { BrowseContext } from "../../util/browse";
|
||||||
import type { UpObject } from "upend";
|
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 { useEntity } from "../../lib/entity";
|
||||||
import api from "../../lib/api";
|
import api from "../../lib/api";
|
||||||
const dispatch = createEventDispatcher();
|
const dispatch = createEventDispatcher();
|
||||||
|
@ -31,11 +31,30 @@
|
||||||
// Identification
|
// Identification
|
||||||
let inferredIds: string[] = [];
|
let inferredIds: string[] = [];
|
||||||
$: inferredIds = $entity?.identify() || [];
|
$: inferredIds = $entity?.identify() || [];
|
||||||
|
let addressIds: string[] = [];
|
||||||
$: resolving = inferredIds.concat(labels || []).length == 0 && !$entity;
|
$: 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;
|
let displayLabel = address;
|
||||||
$: {
|
$: {
|
||||||
const allLabels = [].concat(inferredIds).concat(labels || []);
|
const allLabels = []
|
||||||
|
.concat(inferredIds)
|
||||||
|
.concat(addressIds)
|
||||||
|
.concat(labels || []);
|
||||||
displayLabel = Array.from(new Set(allLabels)).join(" | ");
|
displayLabel = Array.from(new Set(allLabels)).join(" | ");
|
||||||
|
|
||||||
if (!displayLabel && $entityInfo?.t === "Attribute") {
|
if (!displayLabel && $entityInfo?.t === "Attribute") {
|
||||||
|
@ -98,7 +117,7 @@
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="address"
|
class="address"
|
||||||
class:identified={inferredIds.length || labels?.length}
|
class:identified={inferredIds.length || addressIds.length || labels?.length}
|
||||||
class:banner
|
class:banner
|
||||||
>
|
>
|
||||||
<HashBadge {address} />
|
<HashBadge {address} />
|
||||||
|
|
Loading…
Reference in a new issue