Watch
0
0
Fork
You've already forked hyperhive
0

swarm-ui: ignore a saved table filter whose column is gone

This commit is contained in:
iris 2026-10-21 21:08:26 +02:00 • committed by mara
commit 885c051b33
3 changed files with 43 additions and 1 deletions

View file

@ -24,6 +24,7 @@ import { useLocalSetting } from "@hive/shared/settings-storage.js";
import { MultiselectFilterOptions } from "../multiselect-filter/MultiselectFilter.js";
import { focusInto, restoreFocus } from "../popover/focus.js";
import { clampLeft } from "./popover-position.js";
import { forExistingColumns } from "./table-filters.js";
import "./Table.css";
export interface TableColumn<T> {
@ -157,9 +158,15 @@ export function useTableFilters<T>(
rows: T[],
storageKey: string,
) {
const [filters, setFilters] = useLocalSetting<
const [saved, setFilters] = useLocalSetting<
Record<string, ColumnFilterState>
>(storageKey, {});
// A saved filter on a column that no longer exists would hide every row;
// work from the live ones, so the next save drops the rest.
const filters = forExistingColumns(
saved,
columns.map((c) => c.key),
);
const activeFilters = Object.entries(filters).filter(([, f]) =>
isFilterActive(f),

View file

@ -0,0 +1,16 @@
// What a table does with the filters it remembered, without a DOM.
/**
* The saved filters whose column still exists. Filters are kept by column
* key, so one saved for a column a later deploy renamed or removed would
* match no row and hide every one; it is ignored instead, and dropped the
* next time the filters are saved.
*/
export function forExistingColumns<F>(
filters: Record<string, F>,
columnKeys: string[],
): Record<string, F> {
return Object.fromEntries(
Object.entries(filters).filter(([key]) => columnKeys.includes(key)),
);
}