@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.
@@ -200,9 +200,6 @@
200
200
  line-height: 1;
201
201
  bottom: 0;
202
202
  }
203
- .spread_row.limited {
204
- overflow: hidden;
205
- }
206
203
  .spread_row .scrollable {
207
204
  display: flex;
208
205
  flex-flow: row nowrap;
@@ -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 (isSelect) {
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
- if (dev) {
131
- // eslint-disable-next-line no-debugger
132
- debugger;
133
- return;
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
- //TODO redo the below in a more performant way if possible
136
- const x = (await options).filter((it) => gotValue?.includes(it.value));
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
- {#await options then options}
264
- <MultiSelect
265
- labelProp="label"
266
- valueProp="value"
267
- {options}
268
- valueAsObject
269
- onchange={(e) => {
270
- tableContext.paginationRepo?.filterBy(
271
- def.id,
272
- e.map((it) => it.value)
273
- );
274
- }}
275
- selectedValues={selectedOptions}
276
- collapseSelection
277
- />
278
- {/await}
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 != 'number'}
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 != 'number'}
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 (def instanceof SelectDef) {
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) {
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.0.32",
4
+ "version": "0.0.34",
5
5
  "publishConfig": {
6
6
  "access": "restricted"
7
7
  },