@lavalogic/scoria 0.0.32 → 0.0.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
import { AccessorDef } from '../Types/Columns/Definitions/Accessors/AccessorDef.svelte.js';
|
|
35
35
|
import { NumberInputDef } from '../Types/Columns/Definitions/Accessors/NumberInputDef.svelte.js';
|
|
36
36
|
import { dev } from '$app/environment';
|
|
37
|
+
import { QuerySelect } from '../../../index.js';
|
|
37
38
|
|
|
38
39
|
export interface QuickSearchCellProps<T extends object> {
|
|
39
40
|
column: Column<T>;
|
|
@@ -77,6 +78,8 @@
|
|
|
77
78
|
: []
|
|
78
79
|
);
|
|
79
80
|
const isDate = $derived(def instanceof DateInputDef);
|
|
81
|
+
const isRemoteSelect = $derived(customFilter?.type === CustomFilterType.Select);
|
|
82
|
+
const hasQuery = $derived(isRemoteSelect && customFilter?.query);
|
|
80
83
|
|
|
81
84
|
let inputRef: HTMLInputElement | undefined = $state();
|
|
82
85
|
|
|
@@ -88,7 +91,7 @@
|
|
|
88
91
|
|
|
89
92
|
const isSelectOpen = $derived(openedSelect?.value === selectSymbol);
|
|
90
93
|
|
|
91
|
-
let value: string | number | null | undefined = $state(null);
|
|
94
|
+
let value: SelectOption<string | number> | string | number | null | undefined = $state(null);
|
|
92
95
|
let valueMin: number | null = $state(null);
|
|
93
96
|
let valueMax: number | null = $state(null);
|
|
94
97
|
|
|
@@ -98,6 +101,7 @@
|
|
|
98
101
|
);
|
|
99
102
|
|
|
100
103
|
let selectedOptions: Array<SelectOption<string | number>> = $state([]);
|
|
104
|
+
let lastQueryOptions: Array<SelectOption<unknown>> = $state([]);
|
|
101
105
|
|
|
102
106
|
const inputId = $derived(`${tableContext.tableName}-cell-quicksearch-${column.id}`);
|
|
103
107
|
|
|
@@ -118,22 +122,38 @@
|
|
|
118
122
|
}
|
|
119
123
|
|
|
120
124
|
$effect(() => {
|
|
121
|
-
if (
|
|
122
|
-
if (!tableContext.paginationRepo?.filtering) {
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
|
|
125
|
+
if (hasQuery) {
|
|
126
126
|
untrack(async () => {
|
|
127
127
|
const gotValue = getFilteringStateValue() as unknown as
|
|
128
128
|
| Array<string | number | SelectOption<string | number>>
|
|
129
129
|
| undefined;
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
130
|
+
|
|
131
|
+
try {
|
|
132
|
+
// as unknown as string | number | undefined;
|
|
133
|
+
|
|
134
|
+
if (gotValue != undefined) {
|
|
135
|
+
const key = customFilter?.label ?? customFilter?.objectName ?? customFilter?.queryKey;
|
|
136
|
+
const x = key == null ? null : tableContext.__queryValues.get(key);
|
|
137
|
+
value = (x ?? null) as SelectOption<string | number> | null;
|
|
138
|
+
}
|
|
139
|
+
} catch (e) {
|
|
140
|
+
console.warn(e);
|
|
141
|
+
value = null;
|
|
134
142
|
}
|
|
135
|
-
|
|
136
|
-
|
|
143
|
+
});
|
|
144
|
+
} else if (isSelect) {
|
|
145
|
+
if (!tableContext.paginationRepo?.filtering) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const gotValue = getFilteringStateValue() as unknown as
|
|
150
|
+
| Array<string | number | SelectOption<string | number>>
|
|
151
|
+
| undefined;
|
|
152
|
+
|
|
153
|
+
untrack(async () => {
|
|
154
|
+
const x = (await options).filter((it) => {
|
|
155
|
+
return (gotValue as unknown as Array<string | number> | undefined)?.includes(it.value);
|
|
156
|
+
});
|
|
137
157
|
selectedOptions = x;
|
|
138
158
|
});
|
|
139
159
|
} else if (isNumeric) {
|
|
@@ -186,7 +206,7 @@
|
|
|
186
206
|
} else {
|
|
187
207
|
value = valueMin?.toString();
|
|
188
208
|
}
|
|
189
|
-
} else {
|
|
209
|
+
} else if (!hasQuery) {
|
|
190
210
|
const gotValue = filterOption.value;
|
|
191
211
|
if (gotValue == null || typeof gotValue == 'string' || typeof gotValue == 'number') {
|
|
192
212
|
value = gotValue;
|
|
@@ -260,22 +280,49 @@
|
|
|
260
280
|
{/if}
|
|
261
281
|
{/if}
|
|
262
282
|
{:else if isSelect}
|
|
263
|
-
{#
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
283
|
+
{#if hasQuery}
|
|
284
|
+
{#if typeof value == 'object'}
|
|
285
|
+
{@const label =
|
|
286
|
+
customFilter!.label ?? customFilter?.objectName ?? customFilter!.queryKey!}
|
|
287
|
+
<!-- TODO: multiselect -->
|
|
288
|
+
|
|
289
|
+
<QuerySelect
|
|
290
|
+
valueAsObject
|
|
291
|
+
{label}
|
|
292
|
+
clearable
|
|
293
|
+
name={customFilter?.objectName ?? 'Item'}
|
|
294
|
+
valueProp="value"
|
|
295
|
+
labelProp="label"
|
|
296
|
+
selectedValue={value}
|
|
297
|
+
query={customFilter!.query!}
|
|
298
|
+
bind:options={lastQueryOptions}
|
|
299
|
+
onchange={(newValue) => {
|
|
300
|
+
console.log(newValue);
|
|
301
|
+
tableContext.paginationRepo?.filterBy(def.id, newValue?.value ?? null);
|
|
302
|
+
tableContext.__queryValues.set(label, newValue);
|
|
303
|
+
}}
|
|
304
|
+
/>
|
|
305
|
+
{:else}
|
|
306
|
+
{@debug value}
|
|
307
|
+
{/if}
|
|
308
|
+
{:else}
|
|
309
|
+
{#await options then options}
|
|
310
|
+
<MultiSelect
|
|
311
|
+
labelProp="label"
|
|
312
|
+
valueProp="value"
|
|
313
|
+
{options}
|
|
314
|
+
valueAsObject
|
|
315
|
+
onchange={(e) => {
|
|
316
|
+
tableContext.paginationRepo?.filterBy(
|
|
317
|
+
def.id,
|
|
318
|
+
e.map((it) => it.value)
|
|
319
|
+
);
|
|
320
|
+
}}
|
|
321
|
+
selectedValues={selectedOptions}
|
|
322
|
+
collapseSelection
|
|
323
|
+
/>
|
|
324
|
+
{/await}
|
|
325
|
+
{/if}
|
|
279
326
|
{:else if isNumeric}
|
|
280
327
|
{#if selectedNumberFilterType.value === NumberDateFilterMode.Between}
|
|
281
328
|
<div class="input-wrapper left">
|
|
@@ -304,7 +351,7 @@
|
|
|
304
351
|
onkeydown={closeOnCtrlF}
|
|
305
352
|
/>
|
|
306
353
|
</div>
|
|
307
|
-
{:else if typeof value
|
|
354
|
+
{:else if value == null || typeof value == 'string'}
|
|
308
355
|
<div class="input-wrapper right">
|
|
309
356
|
<TextInput
|
|
310
357
|
data-type="quicksearch"
|
|
@@ -319,7 +366,7 @@
|
|
|
319
366
|
/>
|
|
320
367
|
</div>
|
|
321
368
|
{/if}
|
|
322
|
-
{:else if typeof value
|
|
369
|
+
{:else if value == null || typeof value == 'string'}
|
|
323
370
|
<div class="input-wrapper right">
|
|
324
371
|
<TextInput
|
|
325
372
|
data-type="quicksearch"
|
|
@@ -173,14 +173,9 @@
|
|
|
173
173
|
value = null;
|
|
174
174
|
}
|
|
175
175
|
});
|
|
176
|
-
} else if (
|
|
176
|
+
} else if (isSelect) {
|
|
177
177
|
untrack(async () => {
|
|
178
178
|
try {
|
|
179
|
-
if (dev) {
|
|
180
|
-
// eslint-disable-next-line no-debugger
|
|
181
|
-
debugger;
|
|
182
|
-
}
|
|
183
|
-
// TODO see if we can change the below not to use array.includes
|
|
184
179
|
const x = (await options).filter((it) => {
|
|
185
180
|
return (filteringStateValue as unknown as Array<string | number> | undefined)?.includes(
|
|
186
181
|
it.value
|