Skip to content

Commit

Permalink
fix(fe): differentiate sample and user id (#2218)
Browse files Browse the repository at this point in the history
* fix(fe): differentiate sample and user id

* chore(fe): fix-code-style-because-of-repetition-of-logic

* fix(fe): modify variable name, fix TestResultDetail bug

---------

Co-authored-by: b0xercat <[email protected]>
  • Loading branch information
juhyeong0505 and B0XERCAT authored Nov 23, 2024
1 parent bf8a4a6 commit b71e24a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ export default function TestcasePanel() {
.concat(result)
.filter(
(item, index, self) =>
index === self.findIndex((t) => t.id === item.id)
index === self.findIndex((t) => t.originalId === item.originalId)
)
)
setCurrentTab(result.id)
setCurrentTab(result.originalId)
}

const removeTab = (testcaseId: number) => {
setTestcaseTabList((state) =>
state.filter((item) => item.id !== testcaseId)
state.filter((item) => item.originalId !== testcaseId)
)
if (currentTab === testcaseId) {
setCurrentTab(0)
Expand Down Expand Up @@ -56,7 +56,7 @@ export default function TestcasePanel() {
<TestcaseTab
currentTab={currentTab}
onClickTab={() => setCurrentTab(0)}
nextTab={testcaseTabList[0]?.id}
nextTab={testcaseTabList[0]?.originalId}
className="flex-shrink-0"
>
{testcaseTabList.length < 7 ? 'Testcase Result' : 'TC Res'}
Expand All @@ -72,12 +72,12 @@ export default function TestcasePanel() {
{testcaseTabList.map((testcase, index) => (
<TestcaseTab
currentTab={currentTab}
prevTab={testcaseTabList[index - 1]?.id}
nextTab={testcaseTabList[index + 1]?.id}
onClickTab={() => setCurrentTab(testcase.id)}
onClickCloseButton={() => removeTab(testcase.id)}
testcaseId={testcase.id}
key={testcase.id}
prevTab={testcaseTabList[index - 1]?.originalId}
nextTab={testcaseTabList[index + 1]?.originalId}
onClickTab={() => setCurrentTab(testcase.originalId)}
onClickCloseButton={() => removeTab(testcase.originalId)}
testcaseId={testcase.originalId}
key={testcase.originalId}
>
{
(testcaseTabList.length < 7
Expand Down Expand Up @@ -117,7 +117,7 @@ export default function TestcasePanel() {
</div>
) : (
<TestResultDetail
data={processedData.find((item) => item.id === currentTab)}
data={processedData.find((item) => item.originalId === currentTab)}
/>
)}
</ScrollArea>
Expand Down Expand Up @@ -200,9 +200,9 @@ function TestSummary({
const total = data.length

const notAcceptedTestcases = data
.map((testcase, index) =>
.map((testcase) =>
testcase.result !== 'Accepted'
? `${testcase.isUserTestcase ? 'User' : 'Sample'} #${index + 1}`
? `${testcase.isUserTestcase ? 'User' : 'Sample'} #${testcase.id}`
: -1
)
.filter((index) => index !== -1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,20 @@ export const useTestResults = () => {
})

const testcases = useTestcaseStore((state) => state.getTestcases())
let userTestcaseCount = 1
let sampleTestcaseCount = 1
const testResults =
data.length > 0
? testcases.map((testcase, index) => {
const testResult = data.find((item) => item.id === testcase.id)
if (testcase.isUserTestcase) {
testcase.id = userTestcaseCount++
} else {
testcase.id = sampleTestcaseCount++
}
return {
id: index + 1,
originalId: testcase.id,
id: testcase.id,
originalId: index + 1,
input: testcase.input,
expectedOutput: testcase.output,
output: testResult?.output ?? '',
Expand Down
1 change: 1 addition & 0 deletions apps/frontend/types/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ export interface TestResultDetail extends TestResult {
input: string
expectedOutput: string
isUserTestcase: boolean
originalId: number
}

export interface SettingsFormat {
Expand Down

0 comments on commit b71e24a

Please sign in to comment.