Skip to content

Commit c005eb3

Browse files
Update search-attribute-filter components
1 parent 08db9ff commit c005eb3

4 files changed

Lines changed: 30 additions & 26 deletions

File tree

src/lib/components/search-attribute-filter/duration-filter.svelte

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@
1010
1111
const { filter, handleSubmit } = getContext<FilterContext>(FILTER_CONTEXT);
1212
13-
$: ({ value } = $filter);
14-
$: _value = value;
15-
16-
let isValid = true;
13+
let _value = $derived($filter.value);
14+
let isValid = $state(true);
1715
1816
const handleKeydown = (e: KeyboardEvent) => {
1917
const newValue = _value.trim();
@@ -24,12 +22,12 @@
2422
}
2523
};
2624
27-
const validateDuration = (event: Event & { target: HTMLInputElement }) => {
28-
if (isValidDurationQuery(event.target.value.trim())) {
29-
isValid = true;
30-
} else {
31-
isValid = false;
25+
const validateDuration = (event: Event) => {
26+
if (!(event.currentTarget instanceof HTMLInputElement)) {
27+
return;
3228
}
29+
30+
isValid = isValidDurationQuery(event.currentTarget.value.trim());
3331
};
3432
</script>
3533

src/lib/components/search-attribute-filter/number-filter.svelte

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
getContext<FilterContext>(FILTER_CONTEXT);
1212
const min = 0;
1313
14-
$: ({ value } = $filter);
15-
$: _value = value ? Number(value) : null;
14+
let _value = $derived($filter.value ? Number($filter.value) : null);
1615
1716
const handleKeydown = (e: KeyboardEvent) => {
1817
$focusedElementId = '';

src/lib/components/search-attribute-filter/search-attribute-menu.svelte

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script lang="ts">
22
import { getContext } from 'svelte';
33
4-
import { page } from '$app/stores';
4+
import { page } from '$app/state';
55
66
import Icon from '$lib/holocene/icon/icon.svelte';
77
import Input from '$lib/holocene/input/input.svelte';
@@ -24,8 +24,12 @@
2424
2525
import { FILTER_CONTEXT, type FilterContext } from './index.svelte';
2626
27-
export let filters: SearchAttributeFilter[];
28-
export let options: SearchAttributeOption[];
27+
interface Props {
28+
filters: SearchAttributeFilter[];
29+
options: SearchAttributeOption[];
30+
}
31+
32+
let { filters, options }: Props = $props();
2933
3034
const { filter, activeQueryIndex, focusedElementId } =
3135
getContext<FilterContext>(FILTER_CONTEXT);
@@ -45,22 +49,26 @@
4549
$focusedElementId = getFocusedElementId($filter);
4650
}
4751
48-
let searchAttributeValue = '';
52+
let searchAttributeValue = $state('');
4953
50-
$: filteredOptions = !searchAttributeValue
51-
? options
52-
: options.filter((option) =>
53-
option.value.toLowerCase().includes(searchAttributeValue.toLowerCase()),
54-
);
54+
const filteredOptions = $derived(
55+
!searchAttributeValue
56+
? options
57+
: options.filter((option) =>
58+
option.value
59+
.toLowerCase()
60+
.includes(searchAttributeValue.toLowerCase()),
61+
),
62+
);
5563
56-
$: query = $page.url.searchParams.get('query');
64+
const query = $derived(page.url.searchParams.get('query') ?? '');
5765
</script>
5866

5967
<MenuContainer>
6068
<MenuButton
6169
id="search-attribute-filter-button"
6270
controls="search-attribute-menu"
63-
disabled={$activeQueryIndex !== null || query?.length >= MAX_QUERY_LENGTH}
71+
disabled={$activeQueryIndex !== null || query.length >= MAX_QUERY_LENGTH}
6472
onclick={() => (searchAttributeValue = '')}
6573
class="text-nowrap"
6674
>

src/lib/components/search-attribute-filter/text-filter.svelte

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
1212
const { filter, handleSubmit } = getContext<FilterContext>(FILTER_CONTEXT);
1313
14-
$: ({ value } = $filter);
15-
$: _value = value;
14+
let _value = $derived($filter.value);
1615
1716
function handleKeydown(e: KeyboardEvent) {
1817
if (e.key === 'Enter' && _value !== '') {
@@ -22,13 +21,13 @@
2221
}
2322
}
2423
25-
$: options = [
24+
const options = $derived([
2625
{ value: '=', label: translate('common.equal-to') },
2726
{ value: '!=', label: translate('common.not-equal-to') },
2827
...($prefixSearchEnabled && $filter.type === SEARCH_ATTRIBUTE_TYPE.KEYWORD
2928
? [{ value: 'STARTS_WITH', label: translate('common.starts-with') }]
3029
: []),
31-
];
30+
]);
3231
</script>
3332

3433
<ConditionalMenu {options} inputId="text-filter" noBorderLeft>

0 commit comments

Comments
 (0)