-
Notifications
You must be signed in to change notification settings - Fork 33
Add URL query-parameter filtering for dashboards #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
TanayBensuYurtturk
merged 6 commits into
main
from
TanayBensuYurtturk/dashboard-url-filters
Jul 28, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e0d6bbb
Add URL query-parameter filtering for dashboards
TanayBensuYurtturk 8468fed
Document URL-shareable filters in create-dashboard skill
TanayBensuYurtturk b818b19
Harden URL filter parsing and use repeated params for multi-select
TanayBensuYurtturk 651bf18
Re-apply URL filters on external navigation instead of shadowing them
TanayBensuYurtturk 2585970
Sync dashboard filters with the URL via a projection effect
TanayBensuYurtturk aa03e1b
Keep the self-write marker in sync so navigation is never skipped
TanayBensuYurtturk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| import type { Filter } from "../types/dashboard"; | ||
| import { resolvePreset } from "../themes/bruin/FilterBar"; | ||
|
|
||
| /** | ||
| * Convert filter values to/from URL query-string params, so each filter is one | ||
| * param keyed by its name. Multi-select uses repeated params (?x=a&x=b), read | ||
| * and written in DashboardView so option values may safely contain commas. | ||
| */ | ||
|
|
||
| const ISO_DATE_RE = /^\d{4}-\d{2}-\d{2}$/; | ||
|
|
||
| // True only for a real calendar date in YYYY-MM-DD form. The regex alone checks | ||
| // shape, not validity, so this also rejects impossible dates like 2026-99-99 or | ||
| // 2026-02-30 (which would otherwise roll over). | ||
| function isRealDate(s: string): boolean { | ||
| if (!ISO_DATE_RE.test(s)) return false; | ||
| const d = new Date(`${s}T00:00:00Z`); | ||
| return !Number.isNaN(d.getTime()) && d.toISOString().slice(0, 10) === s; | ||
| } | ||
|
|
||
| /** URL param string → typed filter value. Returns undefined to ignore the param. */ | ||
| export function fromParam(filter: Filter, raw: string): unknown { | ||
| switch (filter.type) { | ||
| case "number": { | ||
| if (raw === "") return undefined; | ||
| const n = Number(raw); | ||
| return Number.isFinite(n) ? n : undefined; | ||
| } | ||
| case "date": { | ||
| const v = raw.trim(); | ||
| return isRealDate(v) ? v : undefined; | ||
| } | ||
| case "date-range": { | ||
| const preset = resolvePreset(raw); // e.g. "last_30_days" | ||
| if (preset) return preset; | ||
| const [start = "", end = ""] = raw.split(/\.\.|,/).map((s) => s.trim()); // or "2025-01-01..2025-03-31" | ||
| return isRealDate(start) && isRealDate(end) ? { start, end } : undefined; | ||
| } | ||
| case "select": { | ||
| // Single-select only; multi-select is read from repeated params in | ||
| // DashboardView. Only accept a value the filter actually offers. | ||
| const allowed = filter.options?.values; | ||
| return !allowed || allowed.includes(raw) ? raw : undefined; | ||
| } | ||
| default: | ||
| return raw; // text | ||
| } | ||
| } | ||
|
|
||
| /** Typed filter value → URL param string. Returns null to drop the param. */ | ||
| export function toParam(filter: Filter, value: unknown): string | null { | ||
| if (value == null || value === "") return null; | ||
| if (filter.type === "date-range") { | ||
| const v = value as { start?: string; end?: string }; | ||
| return v.start && v.end ? `${v.start}..${v.end}` : null; | ||
| } | ||
| return String(value); | ||
| } | ||
|
|
||
| /** Keep only multi-select values the filter offers (empty option list = accept as-is). */ | ||
| export function keepAllowedValues(filter: Filter, vals: string[]): string[] { | ||
| const allowed = filter.options?.values; | ||
| return allowed ? vals.filter((v) => allowed.includes(v)) : vals; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.