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) || {}} : component.props) || {}}
{entries} {entries}
{editable} {editable}
{type}
on:change on:change
/> />
{/each} {/each}

View file

@ -18,12 +18,14 @@
const MAX_OPTIONS = 25; const MAX_OPTIONS = 25;
export let type: "attribute" | "value"; export let type: "attribute" | "value";
export let attribute: string | undefined = undefined; export let attributeOptions: string[] | undefined = undefined;
export let value: IValue | undefined = undefined;
export let valueTypes: VALUE_TYPE[] | undefined = undefined; export let valueTypes: VALUE_TYPE[] | undefined = undefined;
export let placeholder = ""; export let placeholder = "";
export let disabled = false; export let disabled = false;
export let attribute: string | undefined = undefined;
export let value: IValue | undefined = undefined;
if (type == "attribute") { if (type == "attribute") {
value = { value = {
c: attribute, c: attribute,
@ -64,7 +66,10 @@
switch (type) { switch (type) {
case "attribute": { case "attribute": {
const allAttributes = await fetchAllAttributes(); const allAttributes = await fetchAllAttributes();
options = allAttributes const attributes = attributeOptions
? allAttributes.filter((attr) => attributeOptions.includes(attr.name))
: allAttributes;
options = attributes
.filter( .filter(
(attr) => (attr) =>
attr.name.toLowerCase().includes(query.toLowerCase()) || attr.name.toLowerCase().includes(query.toLowerCase()) ||
@ -82,6 +87,7 @@
.toUpperCase() .toUpperCase()
.replaceAll(/[^A-Z0-9]/g, "_"); .replaceAll(/[^A-Z0-9]/g, "_");
if ( if (
!attributeOptions &&
!allAttributes.map((attr) => attr.name).includes(attributeToCreate) !allAttributes.map((attr) => attr.name).includes(attributeToCreate)
) { ) {
options.push({ options.push({

View file

@ -17,6 +17,7 @@
import { formatDuration } from "../../util/fragments/time"; import { formatDuration } from "../../util/fragments/time";
import { i18n } from "../../i18n"; import { i18n } from "../../i18n";
import UpLink from "../display/UpLink.svelte"; import UpLink from "../display/UpLink.svelte";
import type { UpType } from "src/lib/types";
const dispatch = createEventDispatcher(); const dispatch = createEventDispatcher();
export let columns: string | undefined = undefined; export let columns: string | undefined = undefined;
@ -26,6 +27,7 @@
export let columnWidths: string[] = []; export let columnWidths: string[] = [];
export let entries: UpEntry[]; export let entries: UpEntry[];
export let type: UpType | undefined = undefined;
export let editable = false; export let editable = false;
// Display // Display
@ -295,7 +297,11 @@
</td> </td>
{#if displayColumns.includes(ATTR_COL)} {#if displayColumns.includes(ATTR_COL)}
<td> <td>
<Selector type="attribute" bind:attribute={newEntryAttribute} /> <Selector
type="attribute"
bind:attribute={newEntryAttribute}
attributeOptions={type?.attributes}
/>
</td> </td>
{/if} {/if}
{#if displayColumns.includes(VALUE_COL)} {#if displayColumns.includes(VALUE_COL)}