From 97bdaa0a7720aecb58460924bd2500219d81651e Mon Sep 17 00:00:00 2001 From: Laura Whitaker Date: Thu, 28 Sep 2023 09:17:11 -0600 Subject: [PATCH] Add "Not equal to" option to Text filter search (#1652) * Add Not equal to option for text filter * Update and refactor getFocusedElementId --- .../filter-search/conditional-menu.svelte | 23 ++++++++++++----- .../filter-search/datetime-filter.svelte | 2 ++ .../workflow/filter-search/index.svelte | 17 +------------ .../filter-search/number-filter.svelte | 2 +- .../search-attribute-menu.svelte | 25 +++---------------- .../workflow/filter-search/text-filter.svelte | 9 +++++++ src/lib/i18n/locales/en/common.ts | 2 ++ src/lib/utilities/query/filter-search.ts | 17 +++++++++++++ 8 files changed, 53 insertions(+), 44 deletions(-) diff --git a/src/lib/components/workflow/filter-search/conditional-menu.svelte b/src/lib/components/workflow/filter-search/conditional-menu.svelte index 5e5561ca4..1c52f7b67 100644 --- a/src/lib/components/workflow/filter-search/conditional-menu.svelte +++ b/src/lib/components/workflow/filter-search/conditional-menu.svelte @@ -24,25 +24,36 @@ defaultConditionOptions; export let disabled = false; export let inputId: string; + export let noBorderLeft = false; + export let noBorderRight = false; - $: options, ($filter.conditional = options[0].value); - - $: selectedOption = - options.find((o) => o.value === $filter.conditional) ?? options[0]; + $: filterConditionalOption = options.find( + (o) => o.value === $filter.conditional, + ); + $: options, updateFilterConditional(); + $: selectedOption = filterConditionalOption ?? options[0]; $: selectedLabel = selectedOption?.label ?? selectedOption?.value; + + function updateFilterConditional() { + if (!filterConditionalOption) { + $filter.conditional = options[0].value; + } + } {selectedLabel} - + {#each options as { value, label }} { diff --git a/src/lib/components/workflow/filter-search/datetime-filter.svelte b/src/lib/components/workflow/filter-search/datetime-filter.svelte index 6593dea08..605e8085f 100644 --- a/src/lib/components/workflow/filter-search/datetime-filter.svelte +++ b/src/lib/components/workflow/filter-search/datetime-filter.svelte @@ -126,6 +126,8 @@ { value: 'BETWEEN', label: translate('between') }, { value: '>=', label: translate('after') }, ]} + noBorderLeft + noBorderRight />
- + (FILTER_CONTEXT); - function getFocusedElementId(attribute: string) { - if (isStatusFilter(attribute)) return 'status-filter'; - - if (isTextFilter(attribute)) return 'text-filter-search'; - - if (isListFilter(attribute)) return 'list-filter-search'; - - if (isNumberFilter(attribute) || isDateTimeFilter(attribute)) - return 'conditional-menu-button'; - - if (isBooleanFilter(attribute)) return 'boolean-filter'; - - return ''; - } - function isOptionDisabled(value: string, filters: WorkflowFilter[]) { return filters.some( - (filter) => filter.conditional === '=' && filter.attribute === value, + (filter) => + (filter.conditional === '=' || filter.conditional === '!=') && + filter.attribute === value, ); } diff --git a/src/lib/components/workflow/filter-search/text-filter.svelte b/src/lib/components/workflow/filter-search/text-filter.svelte index 1b914dc08..a83e1f9af 100644 --- a/src/lib/components/workflow/filter-search/text-filter.svelte +++ b/src/lib/components/workflow/filter-search/text-filter.svelte @@ -4,6 +4,7 @@ import Input from '$lib/holocene/input/input.svelte'; import { translate } from '$lib/i18n/translate'; + import ConditionalMenu from './conditional-menu.svelte'; import { FILTER_CONTEXT, type FilterContext } from './index.svelte'; const { filter, handleSubmit } = getContext(FILTER_CONTEXT); @@ -19,6 +20,14 @@ } +