Files
windmill/frontend/src/lib/components/dbTableLayoutStorage.ts
8064fa8fb6 feat: show s3 csv and parquet results in the db table with filters (#12712)
* feat: filter a db table from its column headers

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat: accept column filters, header row and separator on app s3 table routes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat: show s3 csv and parquet results in the db table with filters

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat: apply db table header filters as you type and widen filterable columns

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: harden db table header filters, column widths and narrow s3 tables

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* chore: point ee ref at the unknown filter column fix

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: compare postgres arrays as text, ignore stale s3 table counts, clearable separator

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Ruben Fiszel <ruben@windmill.dev>
2026-11-30 21:58:26 +01:00

54 lines
1.8 KiB
TypeScript

import { getLocalSetting, storeLocalSetting } from '$lib/utils'
import type { DbTableJoin } from './dbTableJoins'
import type { ColumnFormat } from './dbTableFormat'
export const DB_TABLE_LAYOUT_PREFIX = 'dbTableLayout:'
// Every table opened gets a layout, so without a cap they pile up forever.
const MAX_LAYOUTS = 60
const PRUNED_PER_OVERFLOW = 10
export type DbTableLayout = {
widths?: Record<string, number>
pinned?: Record<string, 'left' | 'right'>
joins?: DbTableJoin[]
/** Columns left out of the grid. */
hidden?: string[]
formats?: Record<string, ColumnFormat>
/** `widths` leave room for the header's filter button. */
widthsFitFilterButton?: boolean
lastUsed?: number
}
export function readDbTableLayout(key: string): DbTableLayout {
try {
const parsed = JSON.parse(getLocalSetting(key) ?? '{}')
return parsed && typeof parsed === 'object' ? parsed : {}
} catch {
return {}
}
}
export function saveDbTableLayout(key: string, layout: DbTableLayout) {
try {
if (!layout.widths && !layout.pinned && !layout.joins && !layout.hidden && !layout.formats) {
storeLocalSetting(key, undefined)
return
}
const isNew = getLocalSetting(key) == null
storeLocalSetting(key, JSON.stringify({ ...layout, lastUsed: Date.now() }))
if (isNew) pruneDbTableLayouts(key)
} catch {}
}
/** Drops the least recently used layouts once there are more than the cap, never `keep`. */
function pruneDbTableLayouts(keep: string) {
const keys = Object.keys(localStorage).filter((k) => k.startsWith(DB_TABLE_LAYOUT_PREFIX))
if (keys.length <= MAX_LAYOUTS) return
keys
.filter((k) => k !== keep)
.map((k) => ({ k, lastUsed: readDbTableLayout(k).lastUsed ?? 0 }))
.sort((a, b) => a.lastUsed - b.lastUsed)
.slice(0, PRUNED_PER_OVERFLOW)
.forEach(({ k }) => localStorage.removeItem(k))
}