From ecbcb42cbb38237cf70e783504ab0d83fb93b17f Mon Sep 17 00:00:00 2001 From: Denis Bykhov Date: Wed, 15 Mar 2023 22:45:15 +0600 Subject: [PATCH] Nested filter fix (#2739) Signed-off-by: Denis Bykhov --- .../src/components/filter/FilterBar.svelte | 1 + .../components/filter/FilterSection.svelte | 23 +++++++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/plugins/view-resources/src/components/filter/FilterBar.svelte b/plugins/view-resources/src/components/filter/FilterBar.svelte index 7af7dc12e6..c4cdd20ad6 100644 --- a/plugins/view-resources/src/components/filter/FilterBar.svelte +++ b/plugins/view-resources/src/components/filter/FilterBar.svelte @@ -41,6 +41,7 @@ if (index === -1) { $filterStore.push(e) } else { + $filterStore[index].onRemove?.() $filterStore[index] = e } $filterStore = $filterStore diff --git a/plugins/view-resources/src/components/filter/FilterSection.svelte b/plugins/view-resources/src/components/filter/FilterSection.svelte index d2ee342444..ed6c40c2bf 100644 --- a/plugins/view-resources/src/components/filter/FilterSection.svelte +++ b/plugins/view-resources/src/components/filter/FilterSection.svelte @@ -32,7 +32,7 @@ function getTargetClass (): Ref> | undefined { try { - return (hierarchy.getAttribute(filter.key._class, filter.key.key).type as RefTo).to + return (hierarchy.getAttribute(currentFilter.key._class, currentFilter.key.key).type as RefTo).to } catch (err: any) { console.error(err) } @@ -52,7 +52,7 @@ let countLabel: string = '' async function getLabel (): Promise { - const count = isState ? await getCountStates(filter.value) : filter.value.length + const count = isState ? await getCountStates(currentFilter.value) : currentFilter.value.length countLabel = await translate(view.string.FilterStatesCount, { value: count }) } $: if (filter) getLabel() @@ -72,11 +72,11 @@ return await client.findOne(view.class.FilterMode, { _id: mode }) } - function onChange (e: Filter | undefined) { + function onChange (e: Filter) { if (filter.nested !== undefined) { - filter.nested = filter + filter.nested = e } else { - filter = filter + filter = e } dispatch('change') } @@ -87,6 +87,7 @@ }) $: modeValuePromise = getMode(filter.mode) + $: nestedModeValuePromise = filter.nested ? getMode(filter.nested.mode) : undefined
@@ -125,11 +126,13 @@ toggle(true) }} > - {#await modeValuePromise then mode} - {#if mode?.label} - - {/if} - {/await} + {#if nestedModeValuePromise} + {#await nestedModeValuePromise then mode} + {#if mode?.label} + + {/if} + {/await} + {/if} {/if} {#await modeValuePromise then mode}