Skip to content

Commit 1e2be50

Browse files
authored
Merge pull request #105 from 1wos/main
fix: generate filter map dynamically
2 parents 9ef0392 + 7d1ec6a commit 1e2be50

File tree

4 files changed

+44
-66
lines changed

4 files changed

+44
-66
lines changed

apps/landing/src/app/test-case/page.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { TestCaseProvider } from '@/components/test-case/TestCaseProvider'
1414
import { TestCaseRuleContainer } from '@/components/test-case/TestCaseRuleContainer'
1515
import { TestCaseStat } from '@/components/test-case/TestCaseStat'
1616
import { TestCaseTypeToggle } from '@/components/test-case/TestCaseTypeToggle'
17-
import { TEST_CASE_FILTERS } from '@/constants'
17+
import { createFilterMap, TEST_CASE_FILTERS } from '@/constants'
1818
import { TestStatusMap } from '@/types'
1919

2020
export const metadata: Metadata = {
@@ -32,6 +32,9 @@ export default async function TestCasePage() {
3232
JSON.parse(data),
3333
) as Promise<Record<string, { title: string; description: string }>>,
3434
])
35+
36+
// Dynamically create filter map based on rule_map keys
37+
const filterMap = createFilterMap(Object.keys(ruleMap))
3538
let totalTest = 0
3639
let totalFail = 0
3740
const cases = Object.entries(ruleMap).map(([key, value]) => {
@@ -87,7 +90,7 @@ export default async function TestCasePage() {
8790
})
8891

8992
return (
90-
<TestCaseProvider testStatusMap={testStatus}>
93+
<TestCaseProvider filterMap={filterMap} testStatusMap={testStatus}>
9194
<Box maxW="1520px" mx="auto" pb="40px" w="100%">
9295
<VStack
9396
gap="20px"

apps/landing/src/components/test-case/TestCaseDisplayBoundary.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import { useMemo } from 'react'
44

5-
import { FILTER_MAP } from '@/constants'
6-
75
import { TestCaseOptions, useTestCase } from './TestCaseProvider'
86

97
export type TestFailCount = number
@@ -27,13 +25,13 @@ export function TestCaseDisplayBoundary<T extends keyof TestCaseOptions>({
2725
option: T
2826
children: React.ReactNode
2927
}) {
30-
const { options } = useTestCase()
28+
const { options, filterMap } = useTestCase()
3129

3230
const shouldRender = useMemo(() => {
3331
switch (option) {
3432
case 'filters':
3533
return options.filters.some((filter) =>
36-
FILTER_MAP[filter].includes(value as string),
34+
filterMap[filter].includes(value as string),
3735
)
3836
case 'failedOnly':
3937
return options.failedOnly ? (value as TestFailCount) > 0 : true
@@ -42,7 +40,7 @@ export function TestCaseDisplayBoundary<T extends keyof TestCaseOptions>({
4240
default:
4341
return false
4442
}
45-
}, [option, value, options])
43+
}, [option, value, options, filterMap])
4644

4745
if (!shouldRender) return null
4846
return children

apps/landing/src/components/test-case/TestCaseProvider.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@ export type TestCaseOptions = {
2020
type: 'list' | 'table'
2121
}
2222

23+
export type FilterMap = Record<TestCaseFilter, string[]>
24+
2325
const TestCaseContext = createContext<{
2426
testStatusMap: TestStatusMap
27+
filterMap: FilterMap
2528
options: TestCaseOptions
2629
onChangeOptions: (options: Partial<TestCaseOptions>) => void
2730
} | null>(null)
@@ -36,9 +39,11 @@ export function useTestCase() {
3639

3740
export function TestCaseProvider({
3841
testStatusMap,
42+
filterMap,
3943
children,
4044
}: {
4145
testStatusMap: TestStatusMap
46+
filterMap: FilterMap
4247
children: React.ReactNode
4348
}) {
4449
const [options, setOptions] = useState<TestCaseOptions>({
@@ -52,7 +57,12 @@ export function TestCaseProvider({
5257

5358
return (
5459
<TestCaseContext.Provider
55-
value={{ testStatusMap, options, onChangeOptions: handleChangeOptions }}
60+
value={{
61+
filterMap,
62+
onChangeOptions: handleChangeOptions,
63+
options,
64+
testStatusMap,
65+
}}
5666
>
5767
{children}
5868
</TestCaseContext.Provider>

apps/landing/src/constants/index.ts

Lines changed: 25 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -29,65 +29,32 @@ export const TEST_CASE_FILTERS: { label: string; value: TestCaseFilter }[] = [
2929
},
3030
]
3131

32+
/**
33+
* Create a filter map based on rule_map.json keys.
34+
* Automatically includes newly added rules.
35+
* @param ruleMapKeys - Array of rule keys from rule_map.json
36+
* @returns Filter map grouped by categories
37+
*/
38+
export function createFilterMap(
39+
ruleMapKeys: string[],
40+
): Record<TestCaseFilter, string[]> {
41+
// Default all rules to korean category
42+
// Can be extended with category field in rule_map.json for classification
43+
return {
44+
korean: ruleMapKeys,
45+
math: [],
46+
science: [],
47+
music: [],
48+
western: [],
49+
'foreign-language': [],
50+
ipa: [],
51+
corpus: [],
52+
}
53+
}
54+
55+
// Default FILTER_MAP for backward compatibility (legacy migration support)
3256
export const FILTER_MAP: Record<TestCaseFilter, string[]> = {
33-
korean: [
34-
'rule_1',
35-
'rule_10',
36-
'rule_11',
37-
'rule_11_b1',
38-
'rule_12',
39-
'rule_12_b1',
40-
'rule_13',
41-
'rule_14',
42-
'rule_14_b1',
43-
'rule_15',
44-
'rule_16',
45-
'rule_17',
46-
'rule_18',
47-
'rule_18_b1',
48-
'rule_1_b1',
49-
'rule_2',
50-
'rule_28',
51-
'rule_29',
52-
'rule_3',
53-
'rule_33',
54-
'rule_33_b1',
55-
'rule_34',
56-
'rule_35',
57-
'rule_4',
58-
'rule_40',
59-
'rule_41',
60-
'rule_42',
61-
'rule_43',
62-
'rule_43_b1',
63-
'rule_44',
64-
'rule_44_b1',
65-
'rule_45',
66-
'rule_46',
67-
'rule_47',
68-
'rule_48',
69-
'rule_49',
70-
'rule_5',
71-
'rule_50',
72-
'rule_51',
73-
'rule_51_b1',
74-
'rule_51_b2',
75-
'rule_52',
76-
'rule_53',
77-
'rule_53_b1',
78-
'rule_54',
79-
'rule_55',
80-
'rule_55_b1',
81-
'rule_56',
82-
'rule_57',
83-
'rule_58',
84-
'rule_59',
85-
'rule_6',
86-
'rule_7',
87-
'rule_8',
88-
'rule_9',
89-
'sentence',
90-
],
57+
korean: [],
9158
math: [],
9259
science: [],
9360
music: [],

0 commit comments

Comments
 (0)