feat: only suggest type's attributes in attributeview editing

This commit is contained in:
Tomáš Mládek 2023-05-03 23:22:18 +02:00
parent 98f19da5f4
commit de488dbc28
3 changed files with 17 additions and 4 deletions

View file

@ -106,6 +106,7 @@
: component.props) || {}}
{entries}
{editable}
{type}
on:change
/>
{/each}

View file

@ -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({

View file

@ -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 @@
</td>
{#if displayColumns.includes(ATTR_COL)}
<td>
<Selector type="attribute" bind:attribute={newEntryAttribute} />
<Selector
type="attribute"
bind:attribute={newEntryAttribute}
attributeOptions={type?.attributes}
/>
</td>
{/if}
{#if displayColumns.includes(VALUE_COL)}