@lavalogic/scoria 0.0.32 → 0.0.34
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,48 @@
|
|
|
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
|
+
clearable
|
|
292
|
+
name={customFilter?.objectName ?? 'Item'}
|
|
293
|
+
valueProp="value"
|
|
294
|
+
labelProp="label"
|
|
295
|
+
selectedValue={value}
|
|
296
|
+
query={customFilter!.query!}
|
|
297
|
+
bind:options={lastQueryOptions}
|
|
298
|
+
onchange={(newValue) => {
|
|
299
|
+
console.log(newValue);
|
|
300
|
+
tableContext.paginationRepo?.filterBy(def.id, newValue?.value ?? null);
|
|
301
|
+
tableContext.__queryValues.set(label, newValue);
|
|
302
|
+
}}
|
|
303
|
+
/>
|
|
304
|
+
{:else}
|
|
305
|
+
{@debug value}
|
|
306
|
+
{/if}
|
|
307
|
+
{:else}
|
|
308
|
+
{#await options then options}
|
|
309
|
+
<MultiSelect
|
|
310
|
+
labelProp="label"
|
|
311
|
+
valueProp="value"
|
|
312
|
+
{options}
|
|
313
|
+
valueAsObject
|
|
314
|
+
onchange={(e) => {
|
|
315
|
+
tableContext.paginationRepo?.filterBy(
|
|
316
|
+
def.id,
|
|
317
|
+
e.map((it) => it.value)
|
|
318
|
+
);
|
|
319
|
+
}}
|
|
320
|
+
selectedValues={selectedOptions}
|
|
321
|
+
collapseSelection
|
|
322
|
+
/>
|
|
323
|
+
{/await}
|
|
324
|
+
{/if}
|
|
279
325
|
{:else if isNumeric}
|
|
280
326
|
{#if selectedNumberFilterType.value === NumberDateFilterMode.Between}
|
|
281
327
|
<div class="input-wrapper left">
|
|
@@ -304,7 +350,7 @@
|
|
|
304
350
|
onkeydown={closeOnCtrlF}
|
|
305
351
|
/>
|
|
306
352
|
</div>
|
|
307
|
-
{:else if typeof value
|
|
353
|
+
{:else if value == null || typeof value == 'string'}
|
|
308
354
|
<div class="input-wrapper right">
|
|
309
355
|
<TextInput
|
|
310
356
|
data-type="quicksearch"
|
|
@@ -319,7 +365,7 @@
|
|
|
319
365
|
/>
|
|
320
366
|
</div>
|
|
321
367
|
{/if}
|
|
322
|
-
{:else if typeof value
|
|
368
|
+
{:else if value == null || typeof value == 'string'}
|
|
323
369
|
<div class="input-wrapper right">
|
|
324
370
|
<TextInput
|
|
325
371
|
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
|
|
@@ -542,7 +542,7 @@ export class TableContext {
|
|
|
542
542
|
}) ?? []);
|
|
543
543
|
return data;
|
|
544
544
|
}
|
|
545
|
-
return this.dataRepo?.data ?? [];
|
|
545
|
+
return this.showSelectedOnly ? [...this.selectedItems.values()] : (this.dataRepo?.data ?? []);
|
|
546
546
|
});
|
|
547
547
|
sortedData = $derived.by(() => {
|
|
548
548
|
if (this.paginationRepo?.paginationType == PaginationType.Local) {
|