Compare commits

...

1 Commits

Author SHA1 Message Date
Tomáš Mládek 772fff2088 wip: also pass `group` to all widgets, basic unused attr display
ci/woodpecker/push/woodpecker Pipeline failed Details
2023-08-28 18:14:06 +02:00
5 changed files with 66 additions and 16 deletions

View File

@ -7,7 +7,10 @@
export interface Widget { export interface Widget {
name: string; name: string;
icon?: string; icon?: string;
components: (entries: UpEntry[]) => Array<WidgetComponent>; components: (input: {
entries: UpEntry[];
group?: string;
}) => Array<WidgetComponent>;
} }
</script> </script>
@ -66,7 +69,7 @@
$: { $: {
components = availableWidgets components = availableWidgets
.find((w) => w.name === currentWidget) .find((w) => w.name === currentWidget)
.components(entries); .components({ entries, group });
} }
</script> </script>

View File

@ -234,7 +234,7 @@
{ {
name: "List", name: "List",
icon: "list-check", icon: "list-check",
components: (entries) => [ components: ({ entries }) => [
{ {
component: EntryList, component: EntryList,
props: { props: {
@ -250,12 +250,13 @@
{ {
name: "List", name: "List",
icon: "list-check", icon: "list-check",
components: (entries) => [ components: ({ entries, group }) => [
{ {
component: EntryList, component: EntryList,
props: { props: {
entries, entries,
columns: "attribute, value", columns: "attribute, value",
attributes: $allTypes[group]?.attributes || [],
}, },
}, },
], ],
@ -263,7 +264,7 @@
{ {
name: "Gallery", name: "Gallery",
icon: "image", icon: "image",
components: (entries) => [ components: ({ entries }) => [
{ {
component: Gallery, component: Gallery,
props: { props: {
@ -281,7 +282,7 @@
{ {
name: "List", name: "List",
icon: "list-check", icon: "list-check",
components: (entries) => [ components: ({ entries }) => [
{ {
component: Gallery, component: Gallery,
props: { props: {
@ -294,7 +295,7 @@
{ {
name: "Gallery", name: "Gallery",
icon: "image", icon: "image",
components: (entries) => [ components: ({ entries }) => [
{ {
component: Gallery, component: Gallery,
props: { props: {

View File

@ -18,6 +18,9 @@
import { i18n } from "../../i18n"; import { i18n } from "../../i18n";
import UpLink from "../display/UpLink.svelte"; import UpLink from "../display/UpLink.svelte";
import { ATTR_ADDED, ATTR_LABEL } from "upend/constants"; import { ATTR_ADDED, ATTR_LABEL } from "upend/constants";
import api from "../../lib/api";
import { AddressComponents } from "upend/api";
import Icon from "../utils/Icon.svelte";
const dispatch = createEventDispatcher(); const dispatch = createEventDispatcher();
export let columns: string | undefined = undefined; export let columns: string | undefined = undefined;
@ -27,6 +30,7 @@
export let columnWidths: string[] | undefined = undefined; export let columnWidths: string[] | undefined = undefined;
export let entries: UpEntry[]; export let entries: UpEntry[];
export let attributes: string[] = [];
export let editable = false; export let editable = false;
export let attributeOptions: string[] | undefined = undefined; export let attributeOptions: string[] | undefined = undefined;
@ -209,6 +213,20 @@
return String(value); return String(value);
} }
} }
// Unused attributes
let unusedAttributes = [];
$: (async () => {
unusedAttributes = await Promise.all(
attributes
.filter((attr) => !entries.some((entry) => entry.attribute === attr))
.map(async (attribute) => {
const components = new AddressComponents("Attribute", attribute);
return await api.componentsToAddress(components);
}),
);
})();
</script> </script>
<div class="container"> <div class="container">
@ -337,7 +355,30 @@
</tr> </tr>
{/each} {/each}
{#if editable} {#each unusedAttributes as attributeAddress}
<tr>
{#if editable}
<td class="attr-action"><Icon name="right-arrow" /> </td>
{/if}
{#each displayColumns as column}
{#if column == ATTR_COL}
<td>
<UpObject link address={attributeAddress} />
</td>
{:else if column == VALUE_COL}
{#if editable}
<!-- <Selector type="value" bind:value={newEntryValue} /> -->
{:else}
<td class="unset">{$i18n.t("(unset)")}</td>
{/if}
{:else}
<td></td>
{/if}
{/each}
</tr>
{/each}
{#if editable && !attributes.length}
<tr class="add-row"> <tr class="add-row">
<td class="attr-action"> <td class="attr-action">
<IconButton name="plus-circle" on:click={addEntry} /> <IconButton name="plus-circle" on:click={addEntry} />
@ -402,5 +443,10 @@
.attribute-col { .attribute-col {
width: 33%; width: 33%;
} }
.unset {
opacity: 0.66;
pointer-events: none;
}
} }
</style> </style>

View File

@ -92,7 +92,7 @@
{ {
name: "List", name: "List",
icon: "list-ul", icon: "list-ul",
components: (entries) => [ components: ({ entries }) => [
{ {
component: EntryList, component: EntryList,
props: { props: {
@ -108,7 +108,7 @@
{ {
name: "Gallery", name: "Gallery",
icon: "image", icon: "image",
components: (entries) => [ components: ({ entries }) => [
{ {
component: Gallery, component: Gallery,
props: { props: {
@ -124,7 +124,7 @@
{ {
name: "List", name: "List",
icon: "list-ul", icon: "list-ul",
components: (entries) => [ components: ({ entries }) => [
{ {
component: EntryList, component: EntryList,
props: { props: {
@ -140,7 +140,7 @@
{ {
name: "Gallery", name: "Gallery",
icon: "image", icon: "image",
components: (entries) => [ components: ({ entries }) => [
{ {
component: Gallery, component: Gallery,
props: { props: {

View File

@ -37,7 +37,7 @@
} }
$: objects = ($result?.entries || []).filter( $: objects = ($result?.entries || []).filter(
(e) => e.attribute === ATTR_LABEL (e) => e.attribute === ATTR_LABEL,
); );
$: sortedObjects = matchSorter(objects, debouncedQuery, { $: sortedObjects = matchSorter(objects, debouncedQuery, {
keys: ["value.c"], keys: ["value.c"],
@ -51,7 +51,7 @@
.then((labelListing) => { .then((labelListing) => {
exactHits = labelListing.entries exactHits = labelListing.entries
.filter( .filter(
(e) => String(e.value.c).toLowerCase() === query.toLowerCase() (e) => String(e.value.c).toLowerCase() === query.toLowerCase(),
) )
.map((e) => e.entity); .map((e) => e.entity);
}); });
@ -68,7 +68,7 @@
{ {
name: "List", name: "List",
icon: "list-ul", icon: "list-ul",
components: (entries) => [ components: ({ entries }) => [
{ {
component: Gallery, component: Gallery,
props: { props: {
@ -82,7 +82,7 @@
{ {
name: "Gallery", name: "Gallery",
icon: "image", icon: "image",
components: (entries) => [ components: ({ entries }) => [
{ {
component: Gallery, component: Gallery,
props: { props: {