Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions apps/landing/src/app/test-case/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 { createFilterMap, TEST_CASE_FILTERS } from '@/constants'
import { TestStatusMap } from '@/types'

export const metadata: Metadata = {
Expand All @@ -32,6 +32,9 @@ export default async function TestCasePage() {
JSON.parse(data),
) as Promise<Record<string, { title: string; description: string }>>,
])

// 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]) => {
Expand Down Expand Up @@ -87,7 +90,7 @@ export default async function TestCasePage() {
})

return (
<TestCaseProvider testStatusMap={testStatus}>
<TestCaseProvider filterMap={filterMap} testStatusMap={testStatus}>
<Box maxW="1520px" mx="auto" pb="40px" w="100%">
<VStack
gap="20px"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import { useMemo } from 'react'

import { FILTER_MAP } from '@/constants'

import { TestCaseOptions, useTestCase } from './TestCaseProvider'

export type TestFailCount = number
Expand All @@ -27,13 +25,13 @@ export function TestCaseDisplayBoundary<T extends keyof TestCaseOptions>({
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
Expand All @@ -42,7 +40,7 @@ export function TestCaseDisplayBoundary<T extends keyof TestCaseOptions>({
default:
return false
}
}, [option, value, options])
}, [option, value, options, filterMap])

if (!shouldRender) return null
return children
Expand Down
12 changes: 11 additions & 1 deletion apps/landing/src/components/test-case/TestCaseProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ export type TestCaseOptions = {
type: 'list' | 'table'
}

export type FilterMap = Record<TestCaseFilter, string[]>

const TestCaseContext = createContext<{
testStatusMap: TestStatusMap
filterMap: FilterMap
options: TestCaseOptions
onChangeOptions: (options: Partial<TestCaseOptions>) => void
} | null>(null)
Expand All @@ -36,9 +39,11 @@ export function useTestCase() {

export function TestCaseProvider({
testStatusMap,
filterMap,
children,
}: {
testStatusMap: TestStatusMap
filterMap: FilterMap
children: React.ReactNode
}) {
const [options, setOptions] = useState<TestCaseOptions>({
Expand All @@ -52,7 +57,12 @@ export function TestCaseProvider({

return (
<TestCaseContext.Provider
value={{ testStatusMap, options, onChangeOptions: handleChangeOptions }}
value={{
filterMap,
onChangeOptions: handleChangeOptions,
options,
testStatusMap,
}}
>
{children}
</TestCaseContext.Provider>
Expand Down
83 changes: 25 additions & 58 deletions apps/landing/src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,65 +29,32 @@ 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<TestCaseFilter, string[]> {
// 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<TestCaseFilter, string[]> = {
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: [],
Expand Down
Loading