From de488dbc28f4b85ea378a772a527c16136707025 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ml=C3=A1dek?= Date: Wed, 3 May 2023 23:22:18 +0200 Subject: [PATCH] feat: only suggest type's attributes in attributeview editing --- webui/src/components/AttributeView.svelte | 1 + webui/src/components/utils/Selector.svelte | 12 +++++++++--- webui/src/components/widgets/EntryList.svelte | 8 +++++++- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/webui/src/components/AttributeView.svelte b/webui/src/components/AttributeView.svelte index c1da49f..0a05d3c 100644 --- a/webui/src/components/AttributeView.svelte +++ b/webui/src/components/AttributeView.svelte @@ -106,6 +106,7 @@ : component.props) || {}} {entries} {editable} + {type} on:change /> {/each} diff --git a/webui/src/components/utils/Selector.svelte b/webui/src/components/utils/Selector.svelte index 1423160..a11f0a5 100644 --- a/webui/src/components/utils/Selector.svelte +++ b/webui/src/components/utils/Selector.svelte @@ -18,12 +18,14 @@ const MAX_OPTIONS = 25; export let type: "attribute" | "value"; - export let attribute: string | undefined = undefined; - export let value: IValue | undefined = undefined; + export let attributeOptions: string[] | undefined = undefined; export let valueTypes: VALUE_TYPE[] | undefined = undefined; export let placeholder = ""; export let disabled = false; + export let attribute: string | undefined = undefined; + export let value: IValue | undefined = undefined; + if (type == "attribute") { value = { c: attribute, @@ -64,7 +66,10 @@ switch (type) { case "attribute": { const allAttributes = await fetchAllAttributes(); - options = allAttributes + const attributes = attributeOptions + ? allAttributes.filter((attr) => attributeOptions.includes(attr.name)) + : allAttributes; + options = attributes .filter( (attr) => attr.name.toLowerCase().includes(query.toLowerCase()) || @@ -82,6 +87,7 @@ .toUpperCase() .replaceAll(/[^A-Z0-9]/g, "_"); if ( + !attributeOptions && !allAttributes.map((attr) => attr.name).includes(attributeToCreate) ) { options.push({ diff --git a/webui/src/components/widgets/EntryList.svelte b/webui/src/components/widgets/EntryList.svelte index b435b4f..a5233b2 100644 --- a/webui/src/components/widgets/EntryList.svelte +++ b/webui/src/components/widgets/EntryList.svelte @@ -17,6 +17,7 @@ import { formatDuration } from "../../util/fragments/time"; import { i18n } from "../../i18n"; import UpLink from "../display/UpLink.svelte"; + import type { UpType } from "src/lib/types"; const dispatch = createEventDispatcher(); export let columns: string | undefined = undefined; @@ -26,6 +27,7 @@ export let columnWidths: string[] = []; export let entries: UpEntry[]; + export let type: UpType | undefined = undefined; export let editable = false; // Display @@ -295,7 +297,11 @@ {#if displayColumns.includes(ATTR_COL)} - + {/if} {#if displayColumns.includes(VALUE_COL)}