From a609baae0bb232e659da9f9597db8e352be68bff Mon Sep 17 00:00:00 2001 From: som1 Date: Mon, 27 Oct 2025 17:40:41 +0900 Subject: [PATCH 1/2] fix: generate filter map dynamically --- apps/landing/src/app/test-case/page.tsx | 9 ++- .../test-case/TestCaseDisplayBoundary.tsx | 8 +- .../components/test-case/TestCaseProvider.tsx | 7 +- apps/landing/src/constants/index.ts | 81 ++++++------------- 4 files changed, 38 insertions(+), 67 deletions(-) diff --git a/apps/landing/src/app/test-case/page.tsx b/apps/landing/src/app/test-case/page.tsx index 753297d0..d9c7d56d 100644 --- a/apps/landing/src/app/test-case/page.tsx +++ b/apps/landing/src/app/test-case/page.tsx @@ -14,7 +14,7 @@ import { TestCaseProvider } from '@/components/test-case/TestCaseProvider' import { TestCaseRuleContainer } from '@/components/test-case/TestCaseRuleContainer' import { TestCaseStat } from '@/components/test-case/TestCaseStat' import { TestCaseTypeToggle } from '@/components/test-case/TestCaseTypeToggle' -import { TEST_CASE_FILTERS } from '@/constants' +import { TEST_CASE_FILTERS, createFilterMap } from '@/constants' import { TestStatusMap } from '@/types' export const metadata: Metadata = { @@ -32,6 +32,9 @@ export default async function TestCasePage() { JSON.parse(data), ) as Promise>, ]) + + // Dynamically create filter map based on rule_map keys + const filterMap = createFilterMap(Object.keys(ruleMap)) let totalTest = 0 let totalFail = 0 const cases = Object.entries(ruleMap).map(([key, value]) => { @@ -87,7 +90,7 @@ export default async function TestCasePage() { }) return ( - + ) -} +} \ No newline at end of file diff --git a/apps/landing/src/components/test-case/TestCaseDisplayBoundary.tsx b/apps/landing/src/components/test-case/TestCaseDisplayBoundary.tsx index 2d6dbe73..842ef302 100644 --- a/apps/landing/src/components/test-case/TestCaseDisplayBoundary.tsx +++ b/apps/landing/src/components/test-case/TestCaseDisplayBoundary.tsx @@ -2,8 +2,6 @@ import { useMemo } from 'react' -import { FILTER_MAP } from '@/constants' - import { TestCaseOptions, useTestCase } from './TestCaseProvider' export type TestFailCount = number @@ -27,13 +25,13 @@ export function TestCaseDisplayBoundary({ option: T children: React.ReactNode }) { - const { options } = useTestCase() + const { options, filterMap } = useTestCase() const shouldRender = useMemo(() => { switch (option) { case 'filters': return options.filters.some((filter) => - FILTER_MAP[filter].includes(value as string), + filterMap[filter].includes(value as string), ) case 'failedOnly': return options.failedOnly ? (value as TestFailCount) > 0 : true @@ -42,7 +40,7 @@ export function TestCaseDisplayBoundary({ default: return false } - }, [option, value, options]) + }, [option, value, options, filterMap]) if (!shouldRender) return null return children diff --git a/apps/landing/src/components/test-case/TestCaseProvider.tsx b/apps/landing/src/components/test-case/TestCaseProvider.tsx index 1b6de5ab..b38d0542 100644 --- a/apps/landing/src/components/test-case/TestCaseProvider.tsx +++ b/apps/landing/src/components/test-case/TestCaseProvider.tsx @@ -20,8 +20,11 @@ export type TestCaseOptions = { type: 'list' | 'table' } +export type FilterMap = Record + const TestCaseContext = createContext<{ testStatusMap: TestStatusMap + filterMap: FilterMap options: TestCaseOptions onChangeOptions: (options: Partial) => void } | null>(null) @@ -36,9 +39,11 @@ export function useTestCase() { export function TestCaseProvider({ testStatusMap, + filterMap, children, }: { testStatusMap: TestStatusMap + filterMap: FilterMap children: React.ReactNode }) { const [options, setOptions] = useState({ @@ -52,7 +57,7 @@ export function TestCaseProvider({ return ( {children} diff --git a/apps/landing/src/constants/index.ts b/apps/landing/src/constants/index.ts index 8ba48875..3779457a 100644 --- a/apps/landing/src/constants/index.ts +++ b/apps/landing/src/constants/index.ts @@ -29,65 +29,30 @@ export const TEST_CASE_FILTERS: { label: string; value: TestCaseFilter }[] = [ }, ] +/** + * Create a filter map based on rule_map.json keys. + * Automatically includes newly added rules. + * @param ruleMapKeys - Array of rule keys from rule_map.json + * @returns Filter map grouped by categories + */ +export function createFilterMap(ruleMapKeys: string[]): Record { + // Default all rules to korean category + // Can be extended with category field in rule_map.json for classification + return { + korean: ruleMapKeys, + math: [], + science: [], + music: [], + western: [], + 'foreign-language': [], + ipa: [], + corpus: [], + } +} + +// Default FILTER_MAP for backward compatibility (legacy migration support) export const FILTER_MAP: Record = { - korean: [ - 'rule_1', - 'rule_10', - 'rule_11', - 'rule_11_b1', - 'rule_12', - 'rule_12_b1', - 'rule_13', - 'rule_14', - 'rule_14_b1', - 'rule_15', - 'rule_16', - 'rule_17', - 'rule_18', - 'rule_18_b1', - 'rule_1_b1', - 'rule_2', - 'rule_28', - 'rule_29', - 'rule_3', - 'rule_33', - 'rule_33_b1', - 'rule_34', - 'rule_35', - 'rule_4', - 'rule_40', - 'rule_41', - 'rule_42', - 'rule_43', - 'rule_43_b1', - 'rule_44', - 'rule_44_b1', - 'rule_45', - 'rule_46', - 'rule_47', - 'rule_48', - 'rule_49', - 'rule_5', - 'rule_50', - 'rule_51', - 'rule_51_b1', - 'rule_51_b2', - 'rule_52', - 'rule_53', - 'rule_53_b1', - 'rule_54', - 'rule_55', - 'rule_55_b1', - 'rule_56', - 'rule_57', - 'rule_58', - 'rule_59', - 'rule_6', - 'rule_7', - 'rule_8', - 'rule_9', - 'sentence', - ], + korean: [], math: [], science: [], music: [], From 7d1ec6afc29dd1ff01ecfcb28028de89fe9062cd Mon Sep 17 00:00:00 2001 From: som1 Date: Mon, 27 Oct 2025 18:07:00 +0900 Subject: [PATCH 2/2] fix: resolve ESLint and Prettier formatting issues --- apps/landing/src/app/test-case/page.tsx | 8 ++++---- .../landing/src/components/test-case/TestCaseProvider.tsx | 7 ++++++- apps/landing/src/constants/index.ts | 4 +++- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/apps/landing/src/app/test-case/page.tsx b/apps/landing/src/app/test-case/page.tsx index d9c7d56d..b2724929 100644 --- a/apps/landing/src/app/test-case/page.tsx +++ b/apps/landing/src/app/test-case/page.tsx @@ -14,7 +14,7 @@ import { TestCaseProvider } from '@/components/test-case/TestCaseProvider' import { TestCaseRuleContainer } from '@/components/test-case/TestCaseRuleContainer' import { TestCaseStat } from '@/components/test-case/TestCaseStat' import { TestCaseTypeToggle } from '@/components/test-case/TestCaseTypeToggle' -import { TEST_CASE_FILTERS, createFilterMap } from '@/constants' +import { createFilterMap, TEST_CASE_FILTERS } from '@/constants' import { TestStatusMap } from '@/types' export const metadata: Metadata = { @@ -32,7 +32,7 @@ export default async function TestCasePage() { JSON.parse(data), ) as Promise>, ]) - + // Dynamically create filter map based on rule_map keys const filterMap = createFilterMap(Object.keys(ruleMap)) let totalTest = 0 @@ -90,7 +90,7 @@ export default async function TestCasePage() { }) return ( - + ) -} \ No newline at end of file +} diff --git a/apps/landing/src/components/test-case/TestCaseProvider.tsx b/apps/landing/src/components/test-case/TestCaseProvider.tsx index b38d0542..ec87fa71 100644 --- a/apps/landing/src/components/test-case/TestCaseProvider.tsx +++ b/apps/landing/src/components/test-case/TestCaseProvider.tsx @@ -57,7 +57,12 @@ export function TestCaseProvider({ return ( {children} diff --git a/apps/landing/src/constants/index.ts b/apps/landing/src/constants/index.ts index 3779457a..df8cdba7 100644 --- a/apps/landing/src/constants/index.ts +++ b/apps/landing/src/constants/index.ts @@ -35,7 +35,9 @@ export const TEST_CASE_FILTERS: { label: string; value: TestCaseFilter }[] = [ * @param ruleMapKeys - Array of rule keys from rule_map.json * @returns Filter map grouped by categories */ -export function createFilterMap(ruleMapKeys: string[]): Record { +export function createFilterMap( + ruleMapKeys: string[], +): Record { // Default all rules to korean category // Can be extended with category field in rule_map.json for classification return {