@fuentis/phoenix-ui 0.0.9-alpha.360 → 0.0.9-alpha.362

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.
@@ -2230,29 +2230,21 @@ class TableCaptionComponent {
2230
2230
  (!Array.isArray(filter.selected) || filter.selected.length > 0);
2231
2231
  let defaultValue;
2232
2232
  if (filter.type === 'multiselect') {
2233
- if (hasSelected) {
2234
- defaultValue = (Array.isArray(filter.selected) ? filter.selected : [filter.selected])
2235
- .map((s) => (s && typeof s === 'object' && 'key' in s ? s.key : s));
2236
- }
2237
- else {
2238
- defaultValue = [];
2239
- }
2233
+ defaultValue = hasSelected
2234
+ ? (Array.isArray(filter.selected) ? filter.selected : [filter.selected])
2235
+ : [];
2240
2236
  }
2241
2237
  else {
2242
- defaultValue = hasSelected
2243
- ? (filter.selected && typeof filter.selected === 'object' && 'key' in filter.selected
2244
- ? filter.selected.key
2245
- : filter.selected)
2246
- : null;
2238
+ defaultValue = hasSelected ? filter.selected : null;
2247
2239
  }
2248
2240
  this.filtersForm.addControl(filter.key, this.fb.control(defaultValue));
2249
2241
  }
2250
- // Emit initial state
2251
- const initial = this.filtersForm.getRawValue();
2252
- this.applyFiltersEvent.emit(initial);
2253
2242
  this.filtersForm.valueChanges
2254
- .pipe(takeUntilDestroyed(this.dr))
2255
- .subscribe((val) => this.applyFiltersEvent.emit(val));
2243
+ .pipe(takeUntilDestroyed(this.dr), debounceTime(150))
2244
+ .subscribe((val) => {
2245
+ this.applyFiltersEvent.emit(val);
2246
+ this.storeTableState(val, this.FILTER_KEY);
2247
+ });
2256
2248
  }
2257
2249
  }
2258
2250
  /** Default selected columns = all non-hidden columns */
@@ -2361,7 +2353,15 @@ class TableCaptionComponent {
2361
2353
  }
2362
2354
  /** Thin wrapper to persist a JSON-serializable state in localStorage */
2363
2355
  storeTableState(state, key) {
2364
- localStorage.setItem(key, JSON.stringify(state));
2356
+ const isEmpty = (v) => v == null ||
2357
+ (typeof v === 'object' && !Array.isArray(v) && Object.keys(v).length === 0) ||
2358
+ (Array.isArray(v) && v.length === 0);
2359
+ if (isEmpty(state)) {
2360
+ localStorage.removeItem(key);
2361
+ }
2362
+ else {
2363
+ localStorage.setItem(key, JSON.stringify(state));
2364
+ }
2365
2365
  }
2366
2366
  /**
2367
2367
  * Handler for the PrimeNG MultiSelect clear button.