diff --git a/src/lib/components/bottom-nav-namespaces.svelte b/src/lib/components/bottom-nav-namespaces.svelte index e0a04ee5fc..7f44d0b3e3 100644 --- a/src/lib/components/bottom-nav-namespaces.svelte +++ b/src/lib/components/bottom-nav-namespaces.svelte @@ -4,16 +4,22 @@ import type { NamespaceListItem } from '$lib/types/global'; import { sortAlphabetically } from '$lib/utilities/sort-alphabetically'; - export let open = false; - export let namespaceList: NamespaceListItem[] = []; + interface Props { + open?: boolean; + namespaceList?: NamespaceListItem[]; + } + + let { open = false, namespaceList = [] }: Props = $props(); - let search = ''; + let search = $state(''); - $: namespaces = sortAlphabetically( - search - ? namespaceList.filter(({ namespace }) => namespace.includes(search)) - : namespaceList, - (ns) => ns.namespace, + const namespaces = $derived( + sortAlphabetically( + search + ? namespaceList.filter(({ namespace }) => namespace.includes(search)) + : namespaceList, + (ns) => ns.namespace, + ), ); @@ -35,7 +41,11 @@ diff --git a/src/lib/components/lines-and-dots/event-type-filter.svelte b/src/lib/components/lines-and-dots/event-type-filter.svelte index 9de9f2e660..54c570299b 100644 --- a/src/lib/components/lines-and-dots/event-type-filter.svelte +++ b/src/lib/components/lines-and-dots/event-type-filter.svelte @@ -2,7 +2,7 @@ import { writable } from 'svelte/store'; import { goto } from '$app/navigation'; - import { page } from '$app/stores'; + import { page } from '$app/state'; import Checkbox from '$lib/holocene/checkbox.svelte'; import Icon from '$lib/holocene/icon/icon.svelte'; @@ -26,43 +26,46 @@ import { CategoryIcon } from './constants'; - export let compact = false; + interface Props { + compact?: boolean; + } - let open = writable(false); + let { compact = false }: Props = $props(); - $: defaultOptions = compact - ? compactEventTypeOptions.map((o) => o.value) - : allEventTypeOptions.map((o) => o.value); + const open = writable(false); - $: options = [ - ...(compact ? compactEventTypeOptions : allEventTypeOptions).map((o) => ({ - ...o, - label: translate(o.label), - icon: CategoryIcon[o.value], - description: translate(o.description), - })), - ]; + const defaultOptions = $derived( + compact + ? compactEventTypeOptions.map((o) => o.value) + : allEventTypeOptions.map((o) => o.value), + ); - $: { + const options = $derived.by(() => { + let list = (compact ? compactEventTypeOptions : allEventTypeOptions).map( + (o) => ({ + ...o, + label: translate(o.label), + icon: CategoryIcon[o.value], + description: o.description ? translate(o.description) : '', + }), + ); if (isVersionNewer('1.21.0', $temporalVersion)) { - options = options.filter(({ value }) => value !== 'update'); + list = list.filter(({ value }) => value !== 'update'); } - } - - $: { - if (!nexusEnabled($page.data.systemInfo?.capabilities)) { - options = options.filter(({ value }) => value !== 'nexus'); + if (!nexusEnabled(page.data.systemInfo?.capabilities)) { + list = list.filter(({ value }) => value !== 'nexus'); } - } + return list; + }); - const onOptionClick = ({ value }) => { + const onOptionClick = ({ value }: (typeof options)[number]) => { clearActiveGroups(); const newCategories = $eventTypeFilter.some((type) => type === value) ? $eventTypeFilter.filter((type) => type !== value) : [...$eventTypeFilter, value]; $eventTypeFilter = newCategories; updateEventFilterParams( - $page.url, + page.url, { categories: newCategories.length === defaultOptions.length ? null : newCategories, @@ -75,7 +78,7 @@ $eventTypeFilter = defaultOptions; $eventStatusFilter = false; updateEventFilterParams( - $page.url, + page.url, { categories: null, statusFilter: false }, goto, ); @@ -85,7 +88,7 @@ $eventTypeFilter = defaultOptions; $eventStatusFilter = !$eventStatusFilter; updateEventFilterParams( - $page.url, + page.url, { categories: null, statusFilter: !$eventStatusFilter }, goto, ); @@ -95,13 +98,15 @@ $eventTypeFilter = []; $eventStatusFilter = false; updateEventFilterParams( - $page.url, + page.url, { categories: [], statusFilter: false }, goto, ); }; - $: filterActive = $eventTypeFilter.length < defaultOptions.length; + const filterActive = $derived( + $eventTypeFilter.length < defaultOptions.length, + ); @@ -111,7 +116,10 @@ class="flex h-6 w-6 flex-col items-center justify-center rounded-full transition-colors duration-200" class:bg-interactive={filterActive} > - + {/snippet} @@ -167,7 +175,7 @@ {translate('common.none')} - {#each options as option} + {#each options as option (option.value)} - import { getContext } from 'svelte'; + import { getContext, type Snippet } from 'svelte'; import { Menu, @@ -12,8 +12,6 @@ import { FILTER_CONTEXT, type FilterContext } from './index.svelte'; - const { filter, focusedElementId, handleSubmit } = - getContext(FILTER_CONTEXT); const defaultConditionOptions = [ { value: '>' }, { value: '>=' }, @@ -23,40 +21,55 @@ { value: '<' }, ]; - export let options: { value: string; label?: string }[] = - defaultConditionOptions; - export let disabled = false; - export let inputId: string; - export let noBorderLeft = false; - export let noBorderRight = false; + interface Props { + options?: { value: string; label?: string }[]; + disabled?: boolean; + inputId: string; + noBorderLeft?: boolean; + noBorderRight?: boolean; + children?: Snippet; + } + + let { + options = defaultConditionOptions, + disabled = false, + inputId, + noBorderLeft = false, + noBorderRight = false, + children, + }: Props = $props(); - let conditionalOptions = [ + const { filter, focusedElementId, handleSubmit } = + getContext(FILTER_CONTEXT); + + const conditionalOptions = $derived([ ...options, { value: 'is', label: translate('common.is-null') }, { value: 'is not', label: translate('common.is-not-null') }, - ]; + ]); - $: filterConditionalOption = conditionalOptions.find( - (o) => o.value === $filter.conditional, + const filterConditionalOption = $derived( + conditionalOptions.find((o) => o.value === $filter.conditional), ); - $: { - filterConditionalOption; - updateFilterConditional(); - } - $: isNullFilter = isNullConditional($filter.conditional); - $: selectedOption = filterConditionalOption ?? conditionalOptions[0]; - $: selectedLabel = selectedOption?.label ?? selectedOption?.value; + const isNullFilter = $derived(isNullConditional($filter.conditional)); + const selectedOption = $derived( + filterConditionalOption ?? conditionalOptions[0], + ); + const selectedLabel = $derived( + selectedOption?.label ?? selectedOption?.value, + ); + + $effect(() => { + if (!filterConditionalOption) { + $filter.conditional = conditionalOptions[0].value; + } + }); function handleNullFilter() { $filter.value = null; $filter.customDate = false; handleSubmit(); } - - function updateFilterConditional() { - if (!filterConditionalOption) - $filter.conditional = conditionalOptions[0].value; - } @@ -85,5 +98,5 @@ {#if !isNullFilter} - + {@render children?.()} {/if} diff --git a/src/lib/components/search-attribute-filter/list-filter.svelte b/src/lib/components/search-attribute-filter/list-filter.svelte index d0f547b0cb..78e1284c56 100644 --- a/src/lib/components/search-attribute-filter/list-filter.svelte +++ b/src/lib/components/search-attribute-filter/list-filter.svelte @@ -1,5 +1,5 @@ -
+ { + e.preventDefault(); + onSubmit(); + }} +> {#if isInConditional(conditional)} {translate('common.search')} - + {@render children?.()} {:else} - + {@render children?.()} {/if}
diff --git a/src/lib/components/timezone-select.svelte b/src/lib/components/timezone-select.svelte index ad11912112..38da2b385e 100644 --- a/src/lib/components/timezone-select.svelte +++ b/src/lib/components/timezone-select.svelte @@ -1,7 +1,8 @@ { if (!value) updateDatetime();