Skip to content

Commit e45f35a

Browse files
authored
Merge pull request #2338 from appwrite/spatial-type-attributes
2 parents 567bf90 + 7640efd commit e45f35a

File tree

25 files changed

+1310
-76
lines changed

25 files changed

+1310
-76
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
},
2323
"dependencies": {
2424
"@ai-sdk/svelte": "^1.1.24",
25-
"@appwrite.io/console": "https://pkg.pr.new/appwrite-labs/cloud/@appwrite.io/console@6031134",
25+
"@appwrite.io/console": "https://pkg.pr.new/appwrite-labs/cloud/@appwrite.io/console@7747562",
2626
"@appwrite.io/pink-icons": "0.25.0",
2727
"@appwrite.io/pink-icons-svelte": "https://pkg.vc/-/@appwrite/@appwrite.io/pink-icons-svelte@f4da718",
2828
"@appwrite.io/pink-legacy": "^1.0.3",

pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lib/components/filters/content.svelte

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
InputText,
77
InputTags,
88
InputSelectCheckbox,
9-
InputDateTime
9+
InputDateTime,
10+
InputPoint
1011
} from '$lib/elements/forms';
1112
import { onMount, createEventDispatcher } from 'svelte';
12-
import { operators, addFilter, queries, tags } from './store';
13+
import { operators, addFilter, queries, tags, ValidOperators } from './store';
1314
import type { Column } from '$lib/helpers/types';
1415
import type { Writable } from 'svelte/store';
1516
import { TagList } from '.';
@@ -18,6 +19,7 @@
1819
1920
let {
2021
value = $bindable(null),
22+
distanceValue = $bindable(null),
2123
columns,
2224
columnId = $bindable(null),
2325
arrayValues = $bindable([]),
@@ -27,6 +29,7 @@
2729
// We cast to any to not cause type errors in the input components
2830
/* eslint @typescript-eslint/no-explicit-any: 'off' */
2931
value?: any;
32+
distanceValue?: number | null;
3033
columns: Writable<Column[]>;
3134
columnId?: string | null;
3235
arrayValues?: string[];
@@ -61,21 +64,57 @@
6164
}));
6265
});
6366
67+
// Check if the current operator is a distance-based operator
68+
let isDistanceOperator = $derived(
69+
operatorKey &&
70+
[
71+
ValidOperators.DistanceEqual,
72+
ValidOperators.DistanceNotEqual,
73+
ValidOperators.DistanceGreaterThan,
74+
ValidOperators.DistanceLessThan
75+
].includes(operatorKey as ValidOperators)
76+
);
77+
6478
onMount(() => {
6579
value = column?.array ? [] : null;
6680
if (column?.type === 'datetime') {
6781
const now = new Date();
6882
value = now.toISOString().slice(0, 16);
6983
}
84+
// Initialize spatial data with default values
85+
if (column?.type === 'point') {
86+
value = [0, 0];
87+
} else if (column?.type === 'linestring') {
88+
value = [
89+
[0, 0],
90+
[1, 1]
91+
];
92+
} else if (column?.type === 'polygon') {
93+
value = [
94+
[
95+
[0, 0],
96+
[1, 1],
97+
[2, 2],
98+
[0, 0]
99+
]
100+
];
101+
}
70102
});
71103
72104
const dispatch = createEventDispatcher<{ clear: void; apply: { applied: number } }>();
73105
74106
function addFilterAndReset() {
75-
addFilter(columnsArray, columnId, operatorKey, value, arrayValues);
107+
// For distance operators, pass the distance as a separate parameter
108+
if (isDistanceOperator && distanceValue !== null && value !== null) {
109+
addFilter(columnsArray, columnId, operatorKey, value, arrayValues, distanceValue);
110+
} else {
111+
addFilter(columnsArray, columnId, operatorKey, value, arrayValues);
112+
}
113+
76114
columnId = null;
77115
operatorKey = null;
78116
value = null;
117+
distanceValue = null;
79118
arrayValues = [];
80119
dispatch('apply', { applied: appliedTags.length });
81120
if (singleCondition) {
@@ -143,11 +182,29 @@
143182
{#key value}
144183
<InputDateTime id="value" bind:value step={60} type="datetime-local" />
145184
{/key}
185+
{:else if column.type === 'point' || column.type === 'linestring' || column.type === 'polygon'}
186+
<InputPoint
187+
values={value || [0, 0]}
188+
onChangePoint={(index, newValue) => {
189+
if (!value) value = [0, 0];
190+
value[index] = newValue;
191+
}} />
146192
{:else}
147193
<InputText id="value" bind:value placeholder="Enter value" />
148194
{/if}
149195
</ul>
150196
{/if}
197+
198+
{#if isDistanceOperator}
199+
<div class="u-margin-block-start-8">
200+
<InputNumber
201+
id="distance"
202+
bind:value={distanceValue}
203+
placeholder="Enter distance"
204+
step={0.001}
205+
required />
206+
</div>
207+
{/if}
151208
{/if}
152209
{#if !singleCondition}
153210
<Button text disabled={isDisabled} class="u-margin-block-start-4" submit>

src/lib/components/filters/filters.svelte

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
3737
/* eslint @typescript-eslint/no-explicit-any: 'off' */
3838
let value: any = null;
39+
let distanceValue: number | null = null;
3940
let selectedColumn: string | null = null;
4041
let operatorKey: string | null = null;
4142
let arrayValues: string[] = [];
@@ -46,6 +47,16 @@
4647
4748
$: filtersAppliedCount = $tags.length;
4849
50+
// Check if the current operator is a distance-based operator
51+
$: isDistanceOperator =
52+
operatorKey &&
53+
[
54+
ValidOperators.DistanceEqual,
55+
ValidOperators.DistanceNotEqual,
56+
ValidOperators.DistanceGreaterThan,
57+
ValidOperators.DistanceLessThan
58+
].includes(operatorKey as ValidOperators);
59+
4960
beforeNavigate(() => {
5061
showFiltersDesktop = false;
5162
showFiltersMobile = false;
@@ -54,6 +65,8 @@
5465
5566
function clearAll() {
5667
selectedColumn = null;
68+
value = null;
69+
distanceValue = null;
5770
queries.clearAll();
5871
if (clearOnClick) {
5972
trackEvent(Submit.FilterClear, { source: analyticsSource });
@@ -73,9 +86,15 @@
7386
value ||
7487
arrayValues.length)
7588
) {
76-
addFilter($columns, selectedColumn, operatorKey, value, arrayValues);
89+
// For distance operators, pass the distance as a separate parameter
90+
if (isDistanceOperator && distanceValue !== null && value !== null) {
91+
addFilter($columns, selectedColumn, operatorKey, value, arrayValues, distanceValue);
92+
} else {
93+
addFilter($columns, selectedColumn, operatorKey, value, arrayValues);
94+
}
7795
selectedColumn = null;
7896
value = null;
97+
distanceValue = null;
7998
operatorKey = null;
8099
arrayValues = [];
81100
}
@@ -97,6 +116,7 @@
97116
$: if (!showFiltersDesktop && !showFiltersMobile) {
98117
selectedColumn = null;
99118
value = null;
119+
distanceValue = null;
100120
operatorKey = null;
101121
arrayValues = [];
102122
}
@@ -163,6 +183,7 @@
163183
bind:columnId={selectedColumn}
164184
bind:operatorKey
165185
bind:value
186+
bind:distanceValue
166187
bind:arrayValues
167188
{columns}
168189
{singleCondition}
@@ -225,6 +246,7 @@
225246
bind:columnId={selectedColumn}
226247
bind:operatorKey
227248
bind:value
249+
bind:distanceValue
228250
bind:arrayValues
229251
{singleCondition}
230252
on:apply={afterApply}

0 commit comments

Comments
 (0)