Tomáš Mládek
b2a25520e4
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
44 lines
1.1 KiB
Svelte
44 lines
1.1 KiB
Svelte
<script lang="ts">
|
|
import api from "../lib/api";
|
|
import { ATTR_IN } from "@upnd/upend/constants";
|
|
import { createEventDispatcher } from "svelte";
|
|
import type { UpObject } from "@upnd/upend";
|
|
import type { Readable } from "svelte/store";
|
|
import EntitySetEditor from "./EntitySetEditor.svelte";
|
|
import { i18n } from "../i18n";
|
|
const dispatch = createEventDispatcher();
|
|
|
|
export let entity: Readable<UpObject>;
|
|
|
|
$: groups = Object.fromEntries(
|
|
($entity?.attr[ATTR_IN] || []).map((e) => [e.value.c as string, e.address]),
|
|
);
|
|
|
|
async function addGroup(address: string) {
|
|
await api.putEntry([
|
|
{
|
|
entity: $entity.address,
|
|
attribute: ATTR_IN,
|
|
value: {
|
|
t: "Address",
|
|
c: address,
|
|
},
|
|
},
|
|
]);
|
|
dispatch("change");
|
|
}
|
|
|
|
async function removeGroup(address: string) {
|
|
await api.deleteEntry(groups[address]);
|
|
dispatch("change");
|
|
}
|
|
</script>
|
|
|
|
<EntitySetEditor
|
|
entities={Object.keys(groups)}
|
|
header={$i18n.t("Groups")}
|
|
hide={Object.keys(groups).length === 0}
|
|
on:add={(e) => addGroup(e.detail)}
|
|
on:remove={(e) => removeGroup(e.detail)}
|
|
on:highlighted
|
|
/>
|