Skip to content

Commit 1255bb1

Browse files
committed
feat: update frontend ui for crud testcases
1 parent 8a31a6f commit 1255bb1

File tree

1 file changed

+126
-6
lines changed

1 file changed

+126
-6
lines changed

apps/frontend/src/app/question/page.tsx

Lines changed: 126 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,17 @@ import {
1414
Tag,
1515
Modal,
1616
Form,
17+
Tabs,
18+
Checkbox,
19+
Tooltip,
20+
Card,
1721
} from "antd";
1822
import { Content } from "antd/es/layout/layout";
1923
import {
2024
DeleteOutlined,
2125
EditOutlined,
2226
PlusCircleOutlined,
27+
PlusOutlined,
2328
SearchOutlined,
2429
} from "@ant-design/icons";
2530
import "./styles.scss";
@@ -40,6 +45,7 @@ import {
4045
import Link from "next/link";
4146
import TextArea from "antd/es/input/TextArea";
4247
import { ValidateUser, VerifyTokenResponseType } from "../services/user";
48+
import TabPane from "antd/es/tabs/TabPane";
4349

4450
/**
4551
* defines the State of the page whe a user is deleing an object. Has 3 general states:
@@ -120,10 +126,9 @@ export default function QuestionListPage() {
120126
const [isAdmin, setIsAdmin] = useState<boolean | undefined>(undefined);
121127

122128
useLayoutEffect(() => {
123-
ValidateUser()
124-
.then((data: VerifyTokenResponseType) => {
125-
setIsAdmin(data.data.isAdmin);
126-
})
129+
ValidateUser().then((data: VerifyTokenResponseType) => {
130+
setIsAdmin(data.data.isAdmin);
131+
});
127132
}, []);
128133

129134
const handleEditClick = (index: number, question: Question) => {
@@ -248,6 +253,34 @@ export default function QuestionListPage() {
248253
return () => clearTimeout(timeout);
249254
}, [search]);
250255

256+
const [visibleTests, setVisibleTests] = useState<any>([
257+
{ key: "1", title: "Visible Test 1" },
258+
]);
259+
const [hiddenTests, setHiddenTests] = useState<any>([]); // FIXME: fix the type!!
260+
const [tabIndex, setTabIndex] = useState(2);
261+
262+
const handleAddVisibleTest = () => {
263+
const newKey = `${Date.now()}`; // Use unique timestamp as key
264+
setVisibleTests([...visibleTests, { key: newKey }]);
265+
};
266+
267+
const handleAddHiddenTest = () => {
268+
const newKey = `${Date.now()}`; // Use unique timestamp as key
269+
setHiddenTests([...hiddenTests, { key: newKey }]);
270+
};
271+
272+
const handleRemoveVisibleTest = (targetKey: string) => {
273+
if (visibleTests.length > 1) {
274+
setVisibleTests(
275+
visibleTests.filter((test: any) => test.key !== targetKey)
276+
);
277+
}
278+
};
279+
280+
const handleRemoveHiddenTest = (targetKey: string) => {
281+
setHiddenTests(hiddenTests.filter((test: any) => test.key !== targetKey));
282+
};
283+
251284
// Table column specification
252285
var columns: TableProps<Question>["columns"];
253286
if (isAdmin) {
@@ -343,7 +376,7 @@ export default function QuestionListPage() {
343376
},
344377
]}
345378
>
346-
<TextArea name="description" />
379+
<TextArea name="description" rows={12} />
347380
</Form.Item>
348381
<Form.Item
349382
name="complexity"
@@ -395,6 +428,93 @@ export default function QuestionListPage() {
395428
allowClear
396429
/>
397430
</Form.Item>
431+
<Tabs defaultActiveKey="1">
432+
{/* Visible Tests Tab */}
433+
<TabPane tab="Visible Testcases" key="1">
434+
<Tabs
435+
type="editable-card"
436+
onEdit={(targetKey, action) =>
437+
action === "add"
438+
? handleAddVisibleTest()
439+
: handleRemoveVisibleTest(targetKey.toString())
440+
}
441+
>
442+
{visibleTests.map((test: any, index: number) => (
443+
<TabPane
444+
tab={`Test ${index + 1}`} // Dynamic numbering based on index
445+
key={test.key}
446+
closable={visibleTests.length > 1} // Restrict removing if only one visible test
447+
>
448+
<Form.Item
449+
label="Input"
450+
name={`input_${test.key}`}
451+
rules={[
452+
{
453+
required: true,
454+
message: "Please enter input value",
455+
},
456+
]}
457+
>
458+
<Input placeholder="Input" />
459+
</Form.Item>
460+
<Form.Item
461+
label="Output"
462+
name={`output_${test.key}`}
463+
rules={[
464+
{
465+
required: true,
466+
message: "Please enter output value",
467+
},
468+
]}
469+
>
470+
<Input placeholder="Output" />
471+
</Form.Item>
472+
</TabPane>
473+
))}
474+
</Tabs>
475+
</TabPane>
476+
477+
{/* Hidden Tests Tab */}
478+
<TabPane tab="Hidden Testcases" key="2">
479+
<Tabs
480+
type="editable-card"
481+
onEdit={(targetKey, action) =>
482+
action === "add"
483+
? handleAddHiddenTest()
484+
: handleRemoveHiddenTest(targetKey.toString())
485+
}
486+
>
487+
{hiddenTests.map((test: any, index: number) => (
488+
<TabPane tab={`Test ${index + 1}`} key={test.key}>
489+
<Form.Item
490+
label="Input"
491+
name={`input_${test.key}`}
492+
rules={[
493+
{
494+
required: true,
495+
message: "Please enter input value",
496+
},
497+
]}
498+
>
499+
<Input placeholder="Input" />
500+
</Form.Item>
501+
<Form.Item
502+
label="Output"
503+
name={`output_${test.key}`}
504+
rules={[
505+
{
506+
required: true,
507+
message: "Please enter output value",
508+
},
509+
]}
510+
>
511+
<Input placeholder="Output" />
512+
</Form.Item>
513+
</TabPane>
514+
))}
515+
</Tabs>
516+
</TabPane>
517+
</Tabs>
398518
<Form.Item
399519
style={{ display: "flex", justifyContent: "flex-end" }}
400520
>
@@ -596,7 +716,7 @@ export default function QuestionListPage() {
596716
},
597717
]}
598718
>
599-
<TextArea name="description" />
719+
<TextArea name="description" rows={12} />
600720
</Form.Item>
601721
<Form.Item
602722
name="complexity"

0 commit comments

Comments
 (0)