@lavalogic/scoria 0.5.4 → 0.5.6

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
 
@@ -115,7 +115,14 @@
115
115
  return;
116
116
  }
117
117
  void filteringStateValue;
118
+ if (def.debug) {
119
+ console.log('filtering state value:', $state.snapshot(filteringStateValue));
120
+ }
118
121
  if (hasQuery) {
122
+ if (def.debug) {
123
+ console.log('has query');
124
+ }
125
+
119
126
  untrack(async () => {
120
127
  const gotValue = filteringStateValue as unknown as
121
128
  | Array<string | number | SelectOption<unknown>>
@@ -125,6 +132,9 @@
125
132
  // as unknown as string | number | undefined;
126
133
 
127
134
  if (gotValue != undefined) {
135
+ if (def.debug) {
136
+ console.log(`query values:`, tableContext.dataRepo.__queryValues);
137
+ }
128
138
  const key =
129
139
  customFilter?.id ??
130
140
  customFilter?.label ??
@@ -132,7 +142,16 @@
132
142
  customFilter?.queryKey ??
133
143
  def.id;
134
144
  const x = key == null ? null : tableContext.dataRepo.__queryValues.get(key);
145
+
146
+ if (def.debug) {
147
+ console.log('value:', $state.snapshot(x));
148
+ }
135
149
  value = (x ?? null) as SelectOption<unknown> | null;
150
+ } else if (def.debug) {
151
+ console.log(
152
+ 'filtering state value was undefined',
153
+ $state.snapshot(tableContext.paginationRepo?.filtering)
154
+ );
136
155
  }
137
156
  } catch (e) {
138
157
  console.warn(e);
@@ -140,6 +159,10 @@
140
159
  }
141
160
  });
142
161
  } else if (isSelect) {
162
+ if (def.debug) {
163
+ console.log('is select (not query)');
164
+ }
165
+
143
166
  if (!tableContext.paginationRepo?.filtering) {
144
167
  return;
145
168
  }
@@ -149,18 +172,34 @@
149
172
  | undefined;
150
173
 
151
174
  untrack(async () => {
152
- const x = (await options).filter((it) => {
153
- if (it.value == undefined) {
154
- return true;
175
+ try {
176
+ const opts = await options;
177
+ if (def.debug) {
178
+ console.log('possible options:', $state.snapshot(opts));
155
179
  }
180
+ const x = opts.filter((it) => {
181
+ if (it.value == undefined) {
182
+ return true;
183
+ }
156
184
 
157
- if (typeof it.value == 'string' || typeof it.value == 'number') {
158
- return (gotValue as unknown as Array<string | number> | undefined)?.includes(it.value);
159
- }
185
+ if (typeof it.value == 'string' || typeof it.value == 'number') {
186
+ return (gotValue as unknown as Array<string | number> | undefined)?.includes(
187
+ it.value
188
+ );
189
+ }
190
+
191
+ return false;
192
+ });
160
193
 
161
- return false;
162
- });
163
- selectedOptions = x;
194
+ if (def.debug) {
195
+ console.log('selected options:', x);
196
+ }
197
+ selectedOptions = x;
198
+ } catch (e) {
199
+ if (dev || def.debug) {
200
+ console.log(e);
201
+ }
202
+ }
164
203
  });
165
204
  } else if (isNumeric) {
166
205
  if (
@@ -230,6 +269,21 @@
230
269
 
231
270
  let showFromDateModal = $state(false);
232
271
  let showToDateModal = $state(false);
272
+
273
+ function generateOnChangeObject(label: string) {
274
+ return (newValue: SelectOption<string | number> | null) => {
275
+ tableContext.paginationRepo?.filterBy(def.id, newValue?.value ?? null);
276
+ tableContext.dataRepo.__queryValues.set(label, newValue);
277
+ value = newValue;
278
+ };
279
+ }
280
+ function generateOnChangePrimitive(label: string) {
281
+ return (newValue: SelectOption<string | number> | null) => {
282
+ tableContext.paginationRepo?.filterBy(def.id, newValue ?? null);
283
+ tableContext.dataRepo.__queryValues.set(label, newValue);
284
+ value = newValue as string | number | null;
285
+ };
286
+ }
233
287
  </script>
234
288
 
235
289
  <td class="input-cell {inputId}">
@@ -289,7 +343,7 @@
289
343
  {/if}
290
344
  {:else if isSelect}
291
345
  {#if hasQuery}
292
- {#if typeof value == 'object'}
346
+ {#if customFilter!.valueAsObject == false}
293
347
  {@const label =
294
348
  customFilter?.id ??
295
349
  customFilter?.label ??
@@ -299,22 +353,36 @@
299
353
  <!-- TODO: multiselect -->
300
354
 
301
355
  <QuerySelect
302
- valueAsObject
356
+ valueAsObject={false}
303
357
  clearable
304
358
  name={customFilter?.objectName ?? 'Item'}
305
359
  valueProp="value"
306
360
  labelProp="label"
307
- {value}
361
+ value={value as string | number | null}
308
362
  query={customFilter!.query!}
309
363
  bind:options={lastQueryOptions}
310
- onchange={(newValue) => {
311
- tableContext.paginationRepo?.filterBy(def.id, newValue?.value ?? null);
312
- tableContext.dataRepo.__queryValues.set(label, newValue);
313
- value = newValue as SelectOption<T> | null;
314
- }}
364
+ onchange={generateOnChangePrimitive(label)}
315
365
  />
316
366
  {:else}
317
- {@debug value}
367
+ {@const label =
368
+ customFilter?.id ??
369
+ customFilter?.label ??
370
+ customFilter?.objectName ??
371
+ customFilter?.queryKey ??
372
+ def.id}
373
+ <!-- TODO: multiselect -->
374
+
375
+ <QuerySelect
376
+ valueAsObject={true}
377
+ clearable
378
+ name={customFilter?.objectName ?? 'Item'}
379
+ valueProp="value"
380
+ labelProp="label"
381
+ value={value as null}
382
+ query={customFilter!.query!}
383
+ bind:options={lastQueryOptions}
384
+ onchange={generateOnChangeObject(label)}
385
+ />
318
386
  {/if}
319
387
  {:else}
320
388
  {#await options then options}
@@ -6,7 +6,6 @@
6
6
  import NumberInput from '../../NumberInput.svelte';
7
7
  import SingleSelect from '../../SingleSelect.svelte';
8
8
  import TextInput from '../../TextInput.svelte';
9
- import { generateShortUUID } from '../../../Helpers/Helpers.svelte.js';
10
9
  import { getContext, onMount, untrack } from 'svelte';
11
10
  import { ColumnType } from '../Types/Columns/ColumnType.js';
12
11
  import { AccessorType } from '../Types/Columns/Definitions/Accessors/AccessorType.js';
@@ -84,18 +83,16 @@
84
83
 
85
84
  const { def, customFilters }: FilterInputProps<T> = $props();
86
85
 
87
- const _uuid = generateShortUUID();
88
-
89
86
  const customFilter = $derived(customFilters?.get(def.id));
90
87
  const isRemoteSelect = $derived(customFilter?.type === CustomFilterType.Select);
91
88
  const isValueAsObject = $derived(!(customFilter?.valueAsObject == false));
92
89
 
93
- let value: SelectOption<unknown> | string | number | null | undefined = $state(null);
90
+ let value: SelectOption<unknown> | unknown | null | undefined = $state(null);
94
91
  let valueMin: number | null = $state(null);
95
92
  let valueMax: number | null = $state(null);
96
93
 
97
94
  let selectedOptions: Array<SelectOption<unknown>> = $state([]);
98
- let lastQueryOptions: Array<SelectOption<unknown>> = $state([]);
95
+ let lastQueryOptions: Array<SelectOption<string | number>> = $state([]);
99
96
 
100
97
  const isNumeric = $derived(
101
98
  def instanceof NumberInputDef || customFilter?.type === CustomFilterType.Number
@@ -146,10 +143,10 @@
146
143
  if (isRemoteSelect && !tableContext.paginationRepo?.filtering) {
147
144
  return;
148
145
  }
146
+ void filteringStateValue;
149
147
  if (def.debug) {
150
148
  console.log('filtering state value:', $state.snapshot(filteringStateValue));
151
149
  }
152
- void filteringStateValue;
153
150
 
154
151
  if (hasQuery) {
155
152
  if (def.debug) {
@@ -161,19 +158,21 @@
161
158
  // as unknown as string | number | undefined;
162
159
 
163
160
  if (filteringStateValue != undefined) {
164
- console.log(`query values:`, tableContext.dataRepo.__queryValues);
161
+ if (def.debug) {
162
+ console.log(`query values:`, tableContext.dataRepo.__queryValues);
163
+ }
165
164
  const x = tableContext.dataRepo.__queryValues.get(
166
- customFilter?.id ?? customFilter?.label ??
165
+ customFilter?.id ??
166
+ customFilter?.label ??
167
167
  customFilter?.objectName ??
168
168
  customFilter?.queryKey ??
169
- def.id ??
170
- _uuid
169
+ def.id
171
170
  );
172
171
 
173
172
  if (def.debug) {
174
173
  console.log('value:', $state.snapshot(x));
175
174
  }
176
- value = (x ?? null) as SelectOption<unknown> | null;
175
+ value = (x ?? null) as SelectOption<string | number> | null;
177
176
  } else if (def.debug) {
178
177
  console.log(
179
178
  'filtering state value was undefined',
@@ -208,7 +207,9 @@
208
207
  }
209
208
  selectedOptions = x;
210
209
  } catch (e) {
211
- console.warn(e);
210
+ if (dev || def.debug) {
211
+ console.log(e);
212
+ }
212
213
  }
213
214
  });
214
215
  } else if (isNumeric) {
@@ -295,6 +296,23 @@
295
296
 
296
297
  let showFromDateModal = $state(false);
297
298
  let showToDateModal = $state(false);
299
+
300
+ function generateOnChangeObject(label: string) {
301
+ return (newValue: SelectOption<string | number> | null) => {
302
+ tableContext.paginationRepo?.filterBy(def.id, newValue?.value ?? null);
303
+ tableContext.dataRepo.__queryValues.set(label, newValue);
304
+ // FIXME <T> is lost when autoformatting. why?
305
+ value = newValue;
306
+ };
307
+ }
308
+ function generateOnChangePrimitive(label: string) {
309
+ return (newValue: SelectOption<string | number> | null) => {
310
+ tableContext.paginationRepo?.filterBy(def.id, newValue ?? null);
311
+ tableContext.dataRepo.__queryValues.set(label, newValue);
312
+ // FIXME <T> is lost when autoformatting. why?
313
+ value = newValue as string | number | null;
314
+ };
315
+ }
298
316
  </script>
299
317
 
300
318
  {#if isSearchable}
@@ -355,7 +373,8 @@
355
373
  <div class="maxwidth">
356
374
  {#await optionsPromise then options}
357
375
  <MultiSelect
358
- label={customFilter?.id ?? customFilter?.label ??
376
+ label={customFilter?.id ??
377
+ customFilter?.label ??
359
378
  customFilter?.objectName ??
360
379
  customFilter?.queryKey ??
361
380
  def.id}
@@ -382,34 +401,53 @@
382
401
  <div class="contents">
383
402
  {#await options then options}
384
403
  {#if hasQuery}
385
- {#if typeof value == 'object'}
386
- {@const label = customFilter?.id ??
387
- customFilter?.label ?? customFilter?.objectName ?? customFilter?.queryKey ?? def.id}
404
+ {#if customFilter!.valueAsObject == false}
405
+ {@const label =
406
+ customFilter?.id ??
407
+ customFilter?.label ??
408
+ customFilter?.objectName ??
409
+ customFilter?.queryKey ??
410
+ def.id}
388
411
  <!-- TODO: multiselect -->
389
412
 
390
413
  <QuerySelect
391
- valueAsObject={customFilter!.valueAsObject ?? true}
414
+ valueAsObject={false}
392
415
  {label}
393
416
  clearable
394
417
  name={customFilter?.objectName ?? 'Item'}
395
418
  valueProp="value"
396
419
  labelProp="label"
397
- {value}
420
+ value={value as string | number | null}
398
421
  query={customFilter!.query!}
399
422
  bind:options={lastQueryOptions}
400
- onchange={(newValue) => {
401
- tableContext.paginationRepo?.filterBy(def.id, newValue?.value ?? null);
402
- tableContext.dataRepo.__queryValues.set(label ?? _uuid, newValue);
403
- // FIXME <T> is lost when autoformatting. why?
404
- value = newValue as SelectOption<T> | null;
405
- }}
423
+ onchange={generateOnChangePrimitive(label)}
406
424
  />
407
425
  {:else}
408
- {@debug value}
426
+ {@const label =
427
+ customFilter?.id ??
428
+ customFilter?.label ??
429
+ customFilter?.objectName ??
430
+ customFilter?.queryKey ??
431
+ def.id}
432
+ <!-- TODO: multiselect -->
433
+
434
+ <QuerySelect
435
+ valueAsObject={true}
436
+ {label}
437
+ clearable
438
+ name={customFilter?.objectName ?? 'Item'}
439
+ valueProp="value"
440
+ labelProp="label"
441
+ value={value as null}
442
+ query={customFilter!.query!}
443
+ bind:options={lastQueryOptions}
444
+ onchange={generateOnChangeObject(label)}
445
+ />
409
446
  {/if}
410
447
  {:else}
411
448
  <MultiSelect
412
- label={customFilter?.id ?? customFilter?.label ??
449
+ label={customFilter?.id ??
450
+ customFilter?.label ??
413
451
  customFilter?.objectName ??
414
452
  customFilter?.queryKey ??
415
453
  def.id}
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.4",
4
+ "version": "0.5.6",
5
5
  "publishConfig": {
6
6
  "access": "restricted"
7
7
  },