*actually* fix buggy impl of generic ids
parent
09bf9371d7
commit
ce60bf5198
|
@ -63,13 +63,10 @@ export default defineComponent({
|
|||
});
|
||||
|
||||
// Identification
|
||||
const { attributes } = useEntity(props.address);
|
||||
const inferredEntries = identify(attributes);
|
||||
const inferredIds: ComputedRef<string[]> = computed(() => {
|
||||
if (visible.value) {
|
||||
const { attributes } = useEntity(props.address);
|
||||
return identify(attributes).value.map((eid) => eid.value);
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
return inferredEntries.value.map((eid) => eid.value);
|
||||
});
|
||||
|
||||
return {
|
||||
|
|
|
@ -49,37 +49,38 @@ interface EntityIdentification {
|
|||
|
||||
export function identify(attributes: ComputedRef<[string, IEntry][]>): ComputedRef<EntityIdentification[]> {
|
||||
// Get all identities of the object
|
||||
const isEntries = attributes.value
|
||||
.filter(
|
||||
([_, entry]) => entry.attribute === "IS"
|
||||
).map(([_, entry]) => entry.value.c);
|
||||
const isEntries = computed(() => {
|
||||
return attributes.value
|
||||
.filter(([_, entry]) => entry.attribute === "IS")
|
||||
.map(([_, entry]) => entry.value.c);
|
||||
})
|
||||
|
||||
// Out of those, retrieve their TYPE_ID entries
|
||||
const idAttributes: [string, Ref<ListingResult | undefined>][] = isEntries.map((type) => {
|
||||
const { data: listing } = useSWRV<ListingResult, unknown>(() => {
|
||||
return `/api/obj?query=(matches "${type}" "TYPE_ID" ?)`;
|
||||
}, fetcher);
|
||||
return [type, listing];
|
||||
const { data: typeIdListing } = useSWRV<ListingResult, unknown>(() => {
|
||||
return isEntries.value && `/api/obj?query=(matches (in ${isEntries.value.map((e) => `"${e}"`).join(" ")}) "TYPE_ID" ?)`;
|
||||
}, fetcher);
|
||||
|
||||
const typeIdAttributes: ComputedRef<[string, string][]> = computed(() => {
|
||||
return Object.values(typeIdListing.value || {}).map((entry) => {
|
||||
return [entry.entity, entry.value.c];
|
||||
});
|
||||
});
|
||||
|
||||
// Finally, filter own object's attributes according to TYPE_IDs
|
||||
return computed(() => {
|
||||
// For each identity
|
||||
return idAttributes
|
||||
.filter(([_, listing]) => Boolean(listing.value))
|
||||
.map(([type, listing]) => {
|
||||
// For each identity/TYPE_ID pair
|
||||
return typeIdAttributes.value
|
||||
.map(([type, attrName]) => {
|
||||
// And each associated TYPE_ID attribute...
|
||||
return Object.values(listing.value || {}).map((idEntry) => {
|
||||
// return own matchin attributes
|
||||
return attributes.value
|
||||
.filter(([_, e]) => e.attribute === idEntry.value.c)
|
||||
// return own matchin attributes
|
||||
return attributes.value
|
||||
.filter(([_, e]) => e.attribute === attrName)
|
||||
.map(([_, attr]) => {
|
||||
return {
|
||||
type,
|
||||
value: attr.value.c
|
||||
}
|
||||
})
|
||||
}).flat();
|
||||
}).flat();
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue