@fuentis/phoenix-ui 0.0.9-alpha.375 → 0.0.9-alpha.376
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.
|
@@ -2250,8 +2250,9 @@ class TableCaptionComponent {
|
|
|
2250
2250
|
this.filtersForm.valueChanges
|
|
2251
2251
|
.pipe(takeUntilDestroyed(this.dr), debounceTime(150))
|
|
2252
2252
|
.subscribe((val) => {
|
|
2253
|
-
this.
|
|
2254
|
-
this.
|
|
2253
|
+
const sanitized = this.sanitizeByOptions(val, this.filters);
|
|
2254
|
+
this.applyFiltersEvent.emit(sanitized);
|
|
2255
|
+
this.storeTableState(sanitized, this.FILTER_KEY);
|
|
2255
2256
|
});
|
|
2256
2257
|
}
|
|
2257
2258
|
}
|
|
@@ -2276,20 +2277,48 @@ class TableCaptionComponent {
|
|
|
2276
2277
|
return;
|
|
2277
2278
|
try {
|
|
2278
2279
|
const parsed = JSON.parse(stored);
|
|
2280
|
+
// zadrži samo poznate ključeve
|
|
2279
2281
|
const validKeys = this.filters.map((f) => f.key);
|
|
2280
|
-
const
|
|
2282
|
+
const filteredByKey = Object.keys(parsed)
|
|
2281
2283
|
.filter((k) => validKeys.includes(k))
|
|
2282
2284
|
.reduce((acc, k) => {
|
|
2283
2285
|
acc[k] = parsed[k];
|
|
2284
2286
|
return acc;
|
|
2285
2287
|
}, {});
|
|
2286
|
-
this.
|
|
2288
|
+
const sanitized = this.sanitizeByOptions(filteredByKey, this.filters);
|
|
2289
|
+
this.filtersForm.patchValue(sanitized, { emitEvent: false });
|
|
2287
2290
|
this.applyFiltersEvent.emit(this.filtersForm.getRawValue());
|
|
2288
2291
|
}
|
|
2289
2292
|
catch (e) {
|
|
2290
2293
|
console.warn('Invalid filter state in localStorage:', e);
|
|
2291
2294
|
}
|
|
2292
2295
|
}
|
|
2296
|
+
// helper: remove all values that do not exist in the options for the given filter.key
|
|
2297
|
+
sanitizeByOptions(formValue, filtersCfg) {
|
|
2298
|
+
const cfgMap = new Map(filtersCfg.map((f) => [f.key, f]));
|
|
2299
|
+
const cleaned = {};
|
|
2300
|
+
Object.keys(formValue ?? {}).forEach((key) => {
|
|
2301
|
+
const cfg = cfgMap.get(key);
|
|
2302
|
+
if (!cfg)
|
|
2303
|
+
return;
|
|
2304
|
+
const opts = (cfg.options ?? []).map((o) => o?.key ?? o?.value ?? o?.label ?? o);
|
|
2305
|
+
const has = new Set(opts.map((v) => String(v).toLowerCase()));
|
|
2306
|
+
const keep = (v) => v !== null &&
|
|
2307
|
+
v !== undefined &&
|
|
2308
|
+
v !== '' &&
|
|
2309
|
+
has.has(String(v?.key ?? v).toLowerCase());
|
|
2310
|
+
const val = formValue[key];
|
|
2311
|
+
if (Array.isArray(val)) {
|
|
2312
|
+
const filtered = val.filter(keep);
|
|
2313
|
+
if (filtered.length)
|
|
2314
|
+
cleaned[key] = filtered;
|
|
2315
|
+
}
|
|
2316
|
+
else if (keep(val)) {
|
|
2317
|
+
cleaned[key] = val;
|
|
2318
|
+
}
|
|
2319
|
+
});
|
|
2320
|
+
return cleaned;
|
|
2321
|
+
}
|
|
2293
2322
|
/**
|
|
2294
2323
|
* Restore previously saved visible columns set.
|
|
2295
2324
|
* If saved state is invalid or outdated, fall back to default (all non-hidden).
|