From fc6212855afcacb891dfeacdf3f8392db9c69c19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ml=C3=A1dek?= Date: Thu, 27 Jan 2022 21:28:42 +0100 Subject: [PATCH] [ui] objects searchable/selectable from edit box --- webui/src/components/utils/Selector.svelte | 31 +++++++++++++++++++++- webui/src/util/search.ts | 6 ++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/webui/src/components/utils/Selector.svelte b/webui/src/components/utils/Selector.svelte index 149cd47..46f121d 100644 --- a/webui/src/components/utils/Selector.svelte +++ b/webui/src/components/utils/Selector.svelte @@ -2,6 +2,7 @@ import { debounce } from "lodash"; import type { IValue } from "upend/types"; + import { baseSearch, baseSearchOnce, getObjects } from "../../util/search"; import UpObject from "../display/UpObject.svelte"; import IconButton from "./IconButton.svelte"; import Input from "./Input.svelte"; @@ -17,6 +18,11 @@ let options: SelectorOption[] = []; const updateOptions = debounce(async (query: string) => { + if (query.length == 0) { + options = []; + return; + } + switch (type) { case "attribute": const req = await fetch("/api/all/attributes"); @@ -30,6 +36,25 @@ }); break; case "value": + const result = await baseSearchOnce(query); + const objects = await getObjects(result.entries); + + options = [ + { + value: { + t: "Value", + c: query, + }, + }, + ...objects.slice(0, 25).map(([address, label]) => { + return { + value: { + t: "Address", + c: address, + }, + } as SelectorOption; + }), + ]; break; } }, 200); @@ -98,7 +123,11 @@ {#if option.attribute} {option.attribute} {:else if option.value} - RESOLVING LOGIC + {#if option.value.t == "Address"} + + {:else} + {option.value.c} + {/if} {/if} {/each} diff --git a/webui/src/util/search.ts b/webui/src/util/search.ts index 7b0c6b9..1ff69d0 100644 --- a/webui/src/util/search.ts +++ b/webui/src/util/search.ts @@ -1,11 +1,15 @@ import type { UpEntry } from "upend"; import type { ListingResult } from "upend/types"; -import { fetchEntry, query as queryFn } from "../lib/entity"; +import { fetchEntry, query as queryFn, queryOnce } from "../lib/entity"; export function baseSearch(query: string) { return queryFn(() => `(matches ? ? (contains "${query}"))`); } +export function baseSearchOnce(query: string) { + return queryOnce(`(matches ? ? (contains "${query}"))`); +} + export async function getObjects( entries: UpEntry[] ): Promise<[string, string][]> {