@lavalogic/scoria 0.5.2 → 0.5.5

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.
@@ -91,7 +91,7 @@
91
91
  let valueMax: number | null = $state(null);
92
92
 
93
93
  let selectedOptions: Array<SelectOption<unknown>> = $state([]);
94
- let lastQueryOptions: Array<SelectOption<unknown>> = $state([]);
94
+ let lastQueryOptions: Array<SelectOption<string | number>> = $state([]);
95
95
 
96
96
  const inputId = $derived(`${tableContext.tableName}-cell-quicksearch-${column.id}`);
97
97
 
@@ -125,7 +125,12 @@
125
125
  // as unknown as string | number | undefined;
126
126
 
127
127
  if (gotValue != undefined) {
128
- const key = customFilter?.label ?? customFilter?.objectName ?? customFilter?.queryKey;
128
+ const key =
129
+ customFilter?.id ??
130
+ customFilter?.label ??
131
+ customFilter?.objectName ??
132
+ customFilter?.queryKey ??
133
+ def.id;
129
134
  const x = key == null ? null : tableContext.dataRepo.__queryValues.get(key);
130
135
  value = (x ?? null) as SelectOption<unknown> | null;
131
136
  }
@@ -225,6 +230,21 @@
225
230
 
226
231
  let showFromDateModal = $state(false);
227
232
  let showToDateModal = $state(false);
233
+
234
+ function generateOnChangeObject(label: string) {
235
+ return (newValue: SelectOption<string | number> | null) => {
236
+ tableContext.paginationRepo?.filterBy(def.id, newValue?.value ?? null);
237
+ tableContext.dataRepo.__queryValues.set(label, newValue);
238
+ value = newValue;
239
+ };
240
+ }
241
+ function generateOnChangePrimitive(label: string) {
242
+ return (newValue: SelectOption<string | number> | null) => {
243
+ tableContext.paginationRepo?.filterBy(def.id, newValue ?? null);
244
+ tableContext.dataRepo.__queryValues.set(label, newValue);
245
+ value = newValue as string | number | null;
246
+ };
247
+ }
228
248
  </script>
229
249
 
230
250
  <td class="input-cell {inputId}">
@@ -284,28 +304,48 @@
284
304
  {/if}
285
305
  {:else if isSelect}
286
306
  {#if hasQuery}
287
- {#if typeof value == 'object'}
307
+ {#if customFilter!.valueAsObject == false}
288
308
  {@const label =
289
- customFilter!.label ?? customFilter?.objectName ?? customFilter!.queryKey!}
309
+ customFilter?.id ??
310
+ customFilter?.label ??
311
+ customFilter?.objectName ??
312
+ customFilter?.queryKey ??
313
+ def.id}
290
314
  <!-- TODO: multiselect -->
291
315
 
292
316
  <QuerySelect
293
- valueAsObject
317
+ valueAsObject={false}
318
+ {label}
294
319
  clearable
295
320
  name={customFilter?.objectName ?? 'Item'}
296
321
  valueProp="value"
297
322
  labelProp="label"
298
- {value}
323
+ value={value as string | number | null}
299
324
  query={customFilter!.query!}
300
325
  bind:options={lastQueryOptions}
301
- onchange={(newValue) => {
302
- tableContext.paginationRepo?.filterBy(def.id, newValue?.value ?? null);
303
- tableContext.dataRepo.__queryValues.set(label, newValue);
304
- value = newValue as SelectOption<T> | null;
305
- }}
326
+ onchange={generateOnChangePrimitive(label)}
306
327
  />
307
328
  {:else}
308
- {@debug value}
329
+ {@const label =
330
+ customFilter?.id ??
331
+ customFilter?.label ??
332
+ customFilter?.objectName ??
333
+ customFilter?.queryKey ??
334
+ def.id}
335
+ <!-- TODO: multiselect -->
336
+
337
+ <QuerySelect
338
+ valueAsObject={true}
339
+ {label}
340
+ clearable
341
+ name={customFilter?.objectName ?? 'Item'}
342
+ valueProp="value"
343
+ labelProp="label"
344
+ value={value as null}
345
+ query={customFilter!.query!}
346
+ bind:options={lastQueryOptions}
347
+ onchange={generateOnChangeObject(label)}
348
+ />
309
349
  {/if}
310
350
  {:else}
311
351
  {#await options then options}
@@ -84,18 +84,16 @@
84
84
 
85
85
  const { def, customFilters }: FilterInputProps<T> = $props();
86
86
 
87
- const _uuid = generateShortUUID();
88
-
89
87
  const customFilter = $derived(customFilters?.get(def.id));
90
88
  const isRemoteSelect = $derived(customFilter?.type === CustomFilterType.Select);
91
89
  const isValueAsObject = $derived(!(customFilter?.valueAsObject == false));
92
90
 
93
- let value: SelectOption<unknown> | string | number | null | undefined = $state(null);
91
+ let value: SelectOption<unknown> | unknown | null | undefined = $state(null);
94
92
  let valueMin: number | null = $state(null);
95
93
  let valueMax: number | null = $state(null);
96
94
 
97
95
  let selectedOptions: Array<SelectOption<unknown>> = $state([]);
98
- let lastQueryOptions: Array<SelectOption<unknown>> = $state([]);
96
+ let lastQueryOptions: Array<SelectOption<string | number>> = $state([]);
99
97
 
100
98
  const isNumeric = $derived(
101
99
  def instanceof NumberInputDef || customFilter?.type === CustomFilterType.Number
@@ -163,13 +161,17 @@
163
161
  if (filteringStateValue != undefined) {
164
162
  console.log(`query values:`, tableContext.dataRepo.__queryValues);
165
163
  const x = tableContext.dataRepo.__queryValues.get(
166
- customFilter?.label ?? customFilter?.objectName ?? customFilter?.queryKey ?? _uuid
164
+ customFilter?.id ??
165
+ customFilter?.label ??
166
+ customFilter?.objectName ??
167
+ customFilter?.queryKey ??
168
+ def.id
167
169
  );
168
170
 
169
171
  if (def.debug) {
170
172
  console.log('value:', $state.snapshot(x));
171
173
  }
172
- value = (x ?? null) as SelectOption<unknown> | null;
174
+ value = (x ?? null) as SelectOption<string | number> | null;
173
175
  } else if (def.debug) {
174
176
  console.log(
175
177
  'filtering state value was undefined',
@@ -291,6 +293,23 @@
291
293
 
292
294
  let showFromDateModal = $state(false);
293
295
  let showToDateModal = $state(false);
296
+
297
+ function generateOnChangeObject(label: string) {
298
+ return (newValue: SelectOption<string | number> | null) => {
299
+ tableContext.paginationRepo?.filterBy(def.id, newValue?.value ?? null);
300
+ tableContext.dataRepo.__queryValues.set(label, newValue);
301
+ // FIXME <T> is lost when autoformatting. why?
302
+ value = newValue;
303
+ };
304
+ }
305
+ function generateOnChangePrimitive(label: string) {
306
+ return (newValue: SelectOption<string | number> | null) => {
307
+ tableContext.paginationRepo?.filterBy(def.id, newValue ?? null);
308
+ tableContext.dataRepo.__queryValues.set(label, newValue);
309
+ // FIXME <T> is lost when autoformatting. why?
310
+ value = newValue as string | number | null;
311
+ };
312
+ }
294
313
  </script>
295
314
 
296
315
  {#if isSearchable}
@@ -351,7 +370,11 @@
351
370
  <div class="maxwidth">
352
371
  {#await optionsPromise then options}
353
372
  <MultiSelect
354
- label={customFilter?.label ?? customFilter?.objectName ?? customFilter?.queryKey}
373
+ label={customFilter?.id ??
374
+ customFilter?.label ??
375
+ customFilter?.objectName ??
376
+ customFilter?.queryKey ??
377
+ def.id}
355
378
  labelProp="label"
356
379
  valueProp="value"
357
380
  name={customFilter?.objectName ?? 'Item'}
@@ -375,34 +398,56 @@
375
398
  <div class="contents">
376
399
  {#await options then options}
377
400
  {#if hasQuery}
378
- {#if typeof value == 'object'}
401
+ {#if customFilter!.valueAsObject == false}
379
402
  {@const label =
380
- customFilter?.label ?? customFilter?.objectName ?? customFilter?.queryKey}
403
+ customFilter?.id ??
404
+ customFilter?.label ??
405
+ customFilter?.objectName ??
406
+ customFilter?.queryKey ??
407
+ def.id}
381
408
  <!-- TODO: multiselect -->
382
409
 
383
410
  <QuerySelect
384
- valueAsObject={customFilter!.valueAsObject ?? true}
411
+ valueAsObject={false}
385
412
  {label}
386
413
  clearable
387
414
  name={customFilter?.objectName ?? 'Item'}
388
415
  valueProp="value"
389
416
  labelProp="label"
390
- {value}
417
+ value={value as string | number | null}
391
418
  query={customFilter!.query!}
392
419
  bind:options={lastQueryOptions}
393
- onchange={(newValue) => {
394
- tableContext.paginationRepo?.filterBy(def.id, newValue?.value ?? null);
395
- tableContext.dataRepo.__queryValues.set(label ?? _uuid, newValue);
396
- // FIXME <T> is lost when autoformatting. why?
397
- value = newValue as SelectOption<T> | null;
398
- }}
420
+ onchange={generateOnChangePrimitive(label)}
399
421
  />
400
422
  {:else}
401
- {@debug value}
423
+ {@const label =
424
+ customFilter?.id ??
425
+ customFilter?.label ??
426
+ customFilter?.objectName ??
427
+ customFilter?.queryKey ??
428
+ def.id}
429
+ <!-- TODO: multiselect -->
430
+
431
+ <QuerySelect
432
+ valueAsObject={true}
433
+ {label}
434
+ clearable
435
+ name={customFilter?.objectName ?? 'Item'}
436
+ valueProp="value"
437
+ labelProp="label"
438
+ value={value as null}
439
+ query={customFilter!.query!}
440
+ bind:options={lastQueryOptions}
441
+ onchange={generateOnChangeObject(label)}
442
+ />
402
443
  {/if}
403
444
  {:else}
404
445
  <MultiSelect
405
- label={customFilter?.label ?? customFilter?.objectName ?? customFilter?.queryKey}
446
+ label={customFilter?.id ??
447
+ customFilter?.label ??
448
+ customFilter?.objectName ??
449
+ customFilter?.queryKey ??
450
+ def.id}
406
451
  labelProp="label"
407
452
  valueProp="value"
408
453
  name={customFilter?.objectName ?? 'Item'}
@@ -3,6 +3,7 @@ import type { CustomFilterType } from './CustomFilterType.js';
3
3
  export interface CustomFilter {
4
4
  queryKey: string;
5
5
  type: CustomFilterType;
6
+ id: string;
6
7
  valueAsObject?: boolean;
7
8
  options?: Array<SelectOption<string | number>> | Promise<Array<SelectOption<string | number>>>;
8
9
  multiSelect?: boolean;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lavalogic/scoria",
3
3
  "description": "Svelte components used for the FloWMS Web Frontend",
4
- "version": "0.5.2",
4
+ "version": "0.5.5",
5
5
  "publishConfig": {
6
6
  "access": "restricted"
7
7
  },