Skip to content

Commit 59128b1

Browse files
authored
Merge pull request #2150 from HarshMN2345/fix-SER-36-dropdowns-aint-populating-issue-check
fix: broken filter issue
2 parents 28d3a06 + bbe7dd5 commit 59128b1

File tree

1 file changed

+54
-52
lines changed

1 file changed

+54
-52
lines changed

src/lib/components/filters/content.svelte

Lines changed: 54 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -8,41 +8,58 @@
88
InputSelectCheckbox,
99
InputDateTime
1010
} from '$lib/elements/forms';
11-
import { createEventDispatcher, onMount } from 'svelte';
12-
import { operators, addFilter, queries, type TagValue } from './store';
11+
import { onMount, createEventDispatcher } from 'svelte';
12+
import { operators, addFilter, queries, tags } from './store';
1313
import type { Column } from '$lib/helpers/types';
1414
import type { Writable } from 'svelte/store';
1515
import { TagList } from '.';
1616
import { Icon, Layout } from '@appwrite.io/pink-svelte';
1717
import { IconPlus } from '@appwrite.io/pink-icons-svelte';
1818
19-
// We cast to any to not cause type errors in the input components
20-
/* eslint @typescript-eslint/no-explicit-any: 'off' */
21-
export let value: any = null;
22-
export let columns: Writable<Column[]>;
23-
export let columnId: string | null = null;
24-
export let arrayValues: string[] = [];
25-
export let operatorKey: string | null = null;
26-
export let singleCondition = false;
19+
let {
20+
value = $bindable(null),
21+
columns,
22+
columnId = $bindable(null),
23+
arrayValues = $bindable([]),
24+
operatorKey = $bindable(null),
25+
singleCondition = false
26+
}: {
27+
// We cast to any to not cause type errors in the input components
28+
/* eslint @typescript-eslint/no-explicit-any: 'off' */
29+
value?: any;
30+
columns: Writable<Column[]>;
31+
columnId?: string | null;
32+
arrayValues?: string[];
33+
operatorKey?: string | null;
34+
singleCondition?: boolean;
35+
} = $props();
2736
28-
$: column = $columns.find((c) => c.id === columnId) as Column;
29-
30-
$: operatorsForColumn = Object.entries(operators)
31-
.filter(([, v]) => v.types.includes(column?.type))
32-
.map(([k]) => ({
33-
label: k,
34-
value: k
37+
let columnsArray = $derived($columns);
38+
let column = $derived(columnsArray.find((c) => c.id === columnId));
39+
let operatorsForColumn = $derived.by(() => {
40+
if (!column?.type) return [];
41+
return Object.entries(operators)
42+
.filter(([, v]) => v.types.includes(column.type))
43+
.map(([k]) => ({ label: k, value: k }));
44+
});
45+
let operator = $derived(operatorKey ? operators[operatorKey] : null);
46+
let isDisabled = $derived(!operator);
47+
let appliedTags = $derived($tags);
48+
let columnOptions = $derived.by(() =>
49+
columnsArray.filter((c) => c.filter !== false).map((c) => ({ label: c.title, value: c.id }))
50+
);
51+
let enumOptions = $derived.by(() => {
52+
if (!column?.elements) return [];
53+
return column.elements.map((e) => ({ label: e?.label ?? e, value: e?.value ?? e }));
54+
});
55+
let enumOptionsWithChecked = $derived.by(() => {
56+
if (!column?.elements) return [];
57+
return column.elements.map((e) => ({
58+
label: e?.label ?? e,
59+
value: e?.value ?? e,
60+
checked: arrayValues.includes(e?.value ?? e)
3561
}));
36-
37-
$: operator = operatorKey ? operators[operatorKey] : null;
38-
$: {
39-
columnId;
40-
operatorKey = null;
41-
}
42-
43-
$: isDisabled = !operator;
44-
45-
let localTags: TagValue[] = [];
62+
});
4663
4764
onMount(() => {
4865
value = column?.array ? [] : null;
@@ -52,35 +69,27 @@
5269
}
5370
});
5471
72+
const dispatch = createEventDispatcher<{ clear: void; apply: { applied: number } }>();
73+
5574
function addFilterAndReset() {
56-
addFilter($columns, columnId, operatorKey, value, arrayValues);
75+
addFilter(columnsArray, columnId, operatorKey, value, arrayValues);
5776
columnId = null;
5877
operatorKey = null;
5978
value = null;
6079
arrayValues = [];
80+
dispatch('apply', { applied: appliedTags.length });
6181
if (singleCondition) {
6282
queries.apply();
6383
}
6484
}
65-
66-
const dispatch = createEventDispatcher<{
67-
clear: void;
68-
apply: { applied: number };
69-
}>();
70-
dispatch('apply', { applied: localTags.length });
7185
</script>
7286

7387
<div>
7488
<form on:submit|preventDefault={addFilterAndReset}>
7589
<Layout.Stack gap="s" direction="row" alignItems="flex-start">
7690
<InputSelect
7791
id="column"
78-
options={$columns
79-
.filter((c) => c.filter !== false)
80-
.map((c) => ({
81-
label: c.title,
82-
value: c.id
83-
}))}
92+
options={columnOptions}
8493
placeholder="Select column"
8594
bind:value={columnId} />
8695
<InputSelect
@@ -97,11 +106,7 @@
97106
name="value"
98107
bind:tags={arrayValues}
99108
placeholder="Select value"
100-
options={column?.elements?.map((e) => ({
101-
label: e?.label ?? e,
102-
value: e?.value ?? e,
103-
checked: arrayValues.includes(e?.value ?? e)
104-
}))}>
109+
options={enumOptionsWithChecked}>
105110
</InputSelectCheckbox>
106111
{:else}
107112
<InputTags
@@ -117,10 +122,7 @@
117122
id="value"
118123
bind:value
119124
placeholder="Select value"
120-
options={column?.elements?.map((e) => ({
121-
label: e?.label ?? e,
122-
value: e?.value ?? e
123-
}))} />
125+
options={enumOptions} />
124126
{:else if column.type === 'integer' || column.type === 'double'}
125127
<InputNumber id="value" bind:value placeholder="Enter value" />
126128
{:else if column.type === 'boolean'}
@@ -131,7 +133,7 @@
131133
options={[
132134
{ label: 'True', value: true },
133135
{ label: 'False', value: false }
134-
].filter(Boolean)}
136+
]}
135137
bind:value />
136138
{:else if column.type === 'datetime'}
137139
{#key value}
@@ -151,10 +153,10 @@
151153
{/if}
152154
</form>
153155

154-
{#if !singleCondition}
156+
{#if !singleCondition && appliedTags.length > 0}
155157
<ul class="u-flex u-flex-wrap u-cross-center u-gap-8 u-margin-block-start-16 tags">
156158
<TagList
157-
tags={localTags}
159+
tags={appliedTags}
158160
on:remove={(e) => {
159161
queries.removeFilter(e.detail);
160162
queries.apply();

0 commit comments

Comments
 (0)