Skip to content

feat: dynamic environment filter from observed data#278

Merged
ajianaz merged 1 commit into
developfrom
feat/dynamic-environments-filter
Jul 1, 2026
Merged

feat: dynamic environment filter from observed data#278
ajianaz merged 1 commit into
developfrom
feat/dynamic-environments-filter

Conversation

@ajianaz

@ajianaz ajianaz commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Problem

The Release Health page hardcoded only two environment options — production and development. SDKs sending other environments (e.g. staging from a Flutter app) had their data stored correctly, but there was no way to filter for it in the UI. Adding a new env required a code change every time.

Solution

Replace the hardcoded dropdown with a dynamic filter backed by a new endpoint that returns the distinct environment values actually observed for the project.

Changes

New endpoint: GET /api/0/projects/{slug}/environments["development", "production", "staging"]

Layer File Change
DB trait trapfall-db/src/lib.rs list_environments() method
SQLite impl trapfall-db/src/sqlite.rs SELECT DISTINCT environment UNION of release_health + transactions
Postgres impl trapfall-db/src/postgres.rs same query, $N placeholders
Store wrapper trapfall-core/src/store.rs expose list_environments
API trapfalld/src/server.rs route + handler
Spec openapi.yaml document endpoint
API client web/src/lib/api.ts listEnvironments()
UI release-health/+page.svelte dynamic envOptions derived from observed data

Design decisions

  • UNION of release_health + transactions — both have a proper environment column on sqlite + postgres. events stores environment inside a JSON blob, so excluded. (Also, transactions aren't persisted yet per 1c: Add transactions + transaction_spans DB tables and queries #237, but the column exists and the query is forward-compatible.)
  • Active filter always rendered — if filterEnv is restored from a URL param before the fetch resolves (or points to an env no longer in the DB), it still appears as a selected button rather than silently vanishing.
  • NULL environments excluded; results sorted alphabetically.

Verification

  • cargo fmt --all -- --check → clean
  • cargo test -p trapfall_db --lib → 23 passed (incl. new test_list_environments_unions_release_health_and_transactions)
  • cargo build -p trapfalld → ok
  • npm run check → 0 errors (1 pre-existing warning in transactions page, unrelated)
  • npm run build + npm run test → 5 passed

Result

Any environment an SDK reports — staging, qa, preview, anything — now appears in the filter automatically, no code changes needed.

The Release Health page hardcoded only two environment options
(production, development). SDKs sending other environments like
'staging' had no way to be filtered — the data was stored but
inaccessible from the UI.

Replace the hardcoded list with a dynamic filter backed by a new
endpoint that queries distinct environment values actually observed
for the project (union of release_health + transactions tables).

Backend:
- trapfall-db: list_environments() trait method + sqlite/postgres impls
  (SELECT DISTINCT environment UNION across release_health + transactions)
- trapfall-core: expose list_environments on Store wrapper
- trapfalld: GET /api/0/projects/{slug}/environments endpoint
- openapi.yaml: document the new endpoint
- test: list_environments unions release_health + transactions

Frontend:
- api.ts: listEnvironments() client method
- release-health page: dynamic envOptions derived from observed
  environments; active filter always rendered (handles URL-restore
  race before fetch resolves)

Any environment an SDK reports (staging, qa, preview, ...) now appears
automatically.
@ajianaz ajianaz merged commit b38d5e2 into develop Jul 1, 2026
12 checks passed
@ajianaz ajianaz deleted the feat/dynamic-environments-filter branch July 1, 2026 06:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant