From 09a1d3c7b77358c18c10397c76e52152d1044302 Mon Sep 17 00:00:00 2001 From: Lukas Date: Sun, 19 Apr 2026 18:18:24 +0200 Subject: [PATCH] Move frontend runtime constants out of types/ban.ts --- Docs/Tasks.md | 2 ++ frontend/src/components/DashboardFilterBar.tsx | 2 +- frontend/src/types/ban.ts | 15 --------------- frontend/src/utils/constants.ts | 17 +++++++++++++++++ 4 files changed, 20 insertions(+), 16 deletions(-) create mode 100644 frontend/src/utils/constants.ts diff --git a/Docs/Tasks.md b/Docs/Tasks.md index c5ec60b..79f3ff1 100644 --- a/Docs/Tasks.md +++ b/Docs/Tasks.md @@ -384,6 +384,8 @@ Reference: `Docs/Refactoring.md` for full analysis of each issue. **Docs changes needed:** None. +**Status:** Completed. + **Why this is needed:** The `types/` directory is meant to contain zero runtime code — only TypeScript type declarations that are erased at compile time. A runtime `const` object in a types file is confusing, breaks the "no runtime code in types/" rule, and pollutes the bundle with a lookup table alongside pure type transpile artifacts. --- diff --git a/frontend/src/components/DashboardFilterBar.tsx b/frontend/src/components/DashboardFilterBar.tsx index b2fbcf4..f0ba69a 100644 --- a/frontend/src/components/DashboardFilterBar.tsx +++ b/frontend/src/components/DashboardFilterBar.tsx @@ -20,7 +20,7 @@ import type { BanOriginFilter, TimeRange } from "../types/ban"; import { BAN_ORIGIN_FILTER_LABELS, TIME_RANGE_LABELS, -} from "../types/ban"; +} from "../utils/constants"; // --------------------------------------------------------------------------- // Types diff --git a/frontend/src/types/ban.ts b/frontend/src/types/ban.ts index 4a1d51e..a104757 100644 --- a/frontend/src/types/ban.ts +++ b/frontend/src/types/ban.ts @@ -20,21 +20,6 @@ export type TimeRange = "24h" | "7d" | "30d" | "365d"; */ export type BanOriginFilter = "all" | "blocklist" | "selfblock"; -/** Human-readable labels for each origin filter option. */ -export const BAN_ORIGIN_FILTER_LABELS: Record = { - all: "All", - blocklist: "Blocklist", - selfblock: "Selfblock", -} as const; - -/** Human-readable labels for each time-range preset. */ -export const TIME_RANGE_LABELS: Record = { - "24h": "Last 24 h", - "7d": "Last 7 days", - "30d": "Last 30 days", - "365d": "Last 365 days", -} as const; - // --------------------------------------------------------------------------- // Ban-list table item // --------------------------------------------------------------------------- diff --git a/frontend/src/utils/constants.ts b/frontend/src/utils/constants.ts new file mode 100644 index 0000000..c2ec297 --- /dev/null +++ b/frontend/src/utils/constants.ts @@ -0,0 +1,17 @@ +/** + * Shared runtime constants used by the frontend UI. + */ +import type { BanOriginFilter, TimeRange } from "../types/ban"; + +export const BAN_ORIGIN_FILTER_LABELS: Record = { + all: "All", + blocklist: "Blocklist", + selfblock: "Selfblock", +} as const; + +export const TIME_RANGE_LABELS: Record = { + "24h": "Last 24 h", + "7d": "Last 7 days", + "30d": "Last 30 days", + "365d": "Last 365 days", +} as const;