Skip to content

Commit 4a13ff3

Browse files
committed
fix: added derive.by
1 parent 9f8249d commit 4a13ff3

File tree

1 file changed

+18
-35
lines changed

1 file changed

+18
-35
lines changed

src/lib/components/filters/content.svelte

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@
1717
import { IconPlus } from '@appwrite.io/pink-icons-svelte';
1818
1919
let {
20+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2021
value = $bindable(null),
2122
columns,
2223
columnId = $bindable(null),
2324
arrayValues = $bindable([]),
2425
operatorKey = $bindable(null),
2526
singleCondition = false
2627
}: {
27-
value?: string | number | string[] | null;
28+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
29+
value?: any;
2830
columns: Writable<Column[]>;
2931
columnId?: string | null;
3032
arrayValues?: string[];
@@ -34,36 +36,23 @@
3436
3537
let columnsArray = $derived($columns);
3638
let column = $derived(columnsArray.find((c) => c.id === columnId));
37-
38-
let operatorsForColumn = $derived(() => {
39+
let operatorsForColumn = $derived.by(() => {
3940
if (!column?.type) return [];
4041
return Object.entries(operators)
4142
.filter(([, v]) => v.types.includes(column.type))
4243
.map(([k]) => ({ label: k, value: k }));
4344
});
44-
4545
let operator = $derived(operatorKey ? operators[operatorKey] : null);
4646
let isDisabled = $derived(!operator);
4747
let appliedTags = $derived($tags);
48-
49-
let columnOptions = $derived(() =>
50-
columnsArray
51-
.filter((c) => c.filter !== false)
52-
.map((c) => ({
53-
label: c.title,
54-
value: c.id
55-
}))
48+
let columnOptions = $derived.by(() =>
49+
columnsArray.filter((c) => c.filter !== false).map((c) => ({ label: c.title, value: c.id }))
5650
);
57-
58-
let enumOptions = $derived(() => {
51+
let enumOptions = $derived.by(() => {
5952
if (!column?.elements) return [];
60-
return column.elements.map((e) => ({
61-
label: e?.label ?? e,
62-
value: e?.value ?? e
63-
}));
53+
return column.elements.map((e) => ({ label: e?.label ?? e, value: e?.value ?? e }));
6454
});
65-
66-
let enumOptionsWithChecked = $derived(() => {
55+
let enumOptionsWithChecked = $derived.by(() => {
6756
if (!column?.elements) return [];
6857
return column.elements.map((e) => ({
6958
label: e?.label ?? e,
@@ -100,13 +89,13 @@
10089
<Layout.Stack gap="s" direction="row" alignItems="flex-start">
10190
<InputSelect
10291
id="column"
103-
options={columnOptions()}
92+
options={columnOptions}
10493
placeholder="Select column"
10594
bind:value={columnId} />
10695
<InputSelect
10796
id="operator"
10897
disabled={!column}
109-
options={operatorsForColumn()}
98+
options={operatorsForColumn}
11099
placeholder="Select operator"
111100
bind:value={operatorKey} />
112101
</Layout.Stack>
@@ -117,7 +106,7 @@
117106
name="value"
118107
bind:tags={arrayValues}
119108
placeholder="Select value"
120-
options={enumOptionsWithChecked()}>
109+
options={enumOptionsWithChecked}>
121110
</InputSelectCheckbox>
122111
{:else}
123112
<InputTags
@@ -131,14 +120,11 @@
131120
{#if column.format === 'enum'}
132121
<InputSelect
133122
id="value"
134-
bind:value={value as string}
123+
bind:value
135124
placeholder="Select value"
136-
options={enumOptions()} />
125+
options={enumOptions} />
137126
{:else if column.type === 'integer' || column.type === 'double'}
138-
<InputNumber
139-
id="value"
140-
bind:value={value as number}
141-
placeholder="Enter value" />
127+
<InputNumber id="value" bind:value placeholder="Enter value" />
142128
{:else if column.type === 'boolean'}
143129
<InputSelect
144130
id="value"
@@ -148,16 +134,13 @@
148134
{ label: 'True', value: true },
149135
{ label: 'False', value: false }
150136
]}
151-
bind:value={value as unknown as boolean} />
137+
bind:value />
152138
{:else if column.type === 'datetime'}
153139
{#key value}
154-
<InputDateTime id="value" bind:value={value as string} step={60} />
140+
<InputDateTime id="value" bind:value step={60} />
155141
{/key}
156142
{:else}
157-
<InputText
158-
id="value"
159-
bind:value={value as string}
160-
placeholder="Enter value" />
143+
<InputText id="value" bind:value placeholder="Enter value" />
161144
{/if}
162145
</ul>
163146
{/if}

0 commit comments

Comments
 (0)