diff --git a/ui/src/components/AttributeView.svelte b/ui/src/components/AttributeView.svelte index c311dcf..68261ee 100644 --- a/ui/src/components/AttributeView.svelte +++ b/ui/src/components/AttributeView.svelte @@ -5,7 +5,8 @@ import type { Component, UpType, Widget } from "../lib/types"; import Table from "./widgets/Table.svelte"; import TableComponent from "./widgets/Table.svelte"; // silence false svelte(reactive-component) warnings - const dispatcher = createEventDispatcher(); + import type { AttributeChange } from "../types/base"; + const dispatch = createEventDispatcher(); export let attributes: [string, IEntry][]; export let type: UpType | undefined = undefined; @@ -43,8 +44,30 @@ )!.components; } - function processChange() { - // noop + async function onChange(change: AttributeChange) { + switch (change.type) { + case "create": + await fetch(`/api/obj`, { + method: "PUT", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ + entity: address, + attribute: change.attribute, + value: { + t: "Value", + c: change.value, + }, + }), + }); + break; + case "delete": + await fetch(`/api/obj/${change.addr}`, { method: "DELETE" }); + break; + default: + console.error("Unimplemented AttributeChange", change); + return; + } + dispatch("changed"); } @@ -82,7 +105,7 @@ {...component.props || {}} {attributes} {editable} - on:edit={processChange} + on:change={(ev) => onChange(ev.detail)} /> {/each} {:else} diff --git a/ui/src/components/Inspect.svelte b/ui/src/components/Inspect.svelte index 8dc67ba..c6d732b 100644 --- a/ui/src/components/Inspect.svelte +++ b/ui/src/components/Inspect.svelte @@ -93,7 +93,7 @@ {address} type={allTypes[typeAddr]} {attributes} - on:edit={revalidate} + on:changed={revalidate} /> {/each} {#if filteredUntypedAttributes.length > 0 || editable} @@ -102,7 +102,7 @@ {editable} {address} attributes={untypedAttributes} - on:change={revalidate} + on:changed={revalidate} /> {/if} {#if $backlinks.length > 0} @@ -111,6 +111,7 @@ {address} attributes={$backlinks} reverse + on:changed={revalidate} /> {/if} diff --git a/ui/src/components/widgets/Table.svelte b/ui/src/components/widgets/Table.svelte index c527782..17e31c2 100644 --- a/ui/src/components/widgets/Table.svelte +++ b/ui/src/components/widgets/Table.svelte @@ -1,10 +1,13 @@