Skip to content

Commit b3ec91d

Browse files
committed
Add Code Viewing Components
1 parent b161602 commit b3ec91d

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

frontend/src/presentation/components/RecentAttemptsTable.tsx

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import React, { useEffect, useState } from "react";
2-
import { Table, Tag, Typography, Badge, Button, message, Empty } from 'antd';
2+
import { Table, Tag, Typography, Badge, Button, message, Empty, Modal } from 'antd';
33
import type { ColumnsType } from 'antd/es/table';
44
import styles from "./RecentAttemptsTable.module.css";
55
import { HistoryEntry } from "domain/entities/HistoryEntry";
66
import { historyUseCases } from "domain/usecases/HistoryUseCases";
7+
import { ReactMarkdown } from "./common/ReactMarkdown";
78

89
export const RecentAttemptsTable: React.FC = () => {
910
const [recentAttemptsData, setRecentAttemptsData] = useState<HistoryEntry[]>([]);
1011
const [loading, setLoading] = useState<boolean>(true);
1112
const [selectedRowKeys, setSelectedRowKeys] = useState<React.Key[]>([]);
13+
const [isModalVisible, setIsModalVisible] = useState<boolean>(false);
14+
const [currentCode, setCurrentCode] = useState<string>("");
1215

1316
useEffect(() => {
1417
fetchRecentAttempts();
@@ -71,12 +74,31 @@ export const RecentAttemptsTable: React.FC = () => {
7174
}
7275
};
7376

77+
const showModal = (code: string) => {
78+
setCurrentCode(code);
79+
setIsModalVisible(true);
80+
};
81+
82+
const handleModalClose = () => {
83+
setIsModalVisible(false);
84+
setCurrentCode("");
85+
};
86+
7487
const columns: ColumnsType<HistoryEntry> = [
7588
{
7689
title: 'Date',
7790
dataIndex: 'date',
7891
key: 'date',
7992
sorter: (a, b) => new Date(a.attemptCompletedAt).getTime() - new Date(b.attemptCompletedAt).getTime(),
93+
render: (_text, record) => {
94+
const startDate = new Date(record.attemptStartedAt).toLocaleString();
95+
const endDate = new Date(record.attemptCompletedAt).toLocaleString();
96+
return (
97+
<span>
98+
{startDate} - {endDate}
99+
</span>
100+
);
101+
},
80102
},
81103
{
82104
title: 'Title',
@@ -118,6 +140,15 @@ export const RecentAttemptsTable: React.FC = () => {
118140
</>
119141
),
120142
},
143+
{
144+
title: 'Action',
145+
key: 'action',
146+
render: (_text, record) => (
147+
<Button type="link" onClick={() => showModal(record.attemptCode)}>
148+
View Code
149+
</Button>
150+
),
151+
},
121152
];
122153

123154
// Row Selection Configuration
@@ -152,7 +183,23 @@ export const RecentAttemptsTable: React.FC = () => {
152183
locale={{
153184
emptyText: <Empty description="No attempts yet" />,
154185
}}
186+
rowKey="key" // Ensure that each row has a unique key
155187
/>
188+
189+
{/* Modal for Viewing Code */}
190+
<Modal
191+
title="Attempt Code"
192+
open={isModalVisible}
193+
onCancel={handleModalClose}
194+
footer={[
195+
<Button key="close" onClick={handleModalClose}>
196+
Close
197+
</Button>,
198+
]}
199+
width={800}
200+
>
201+
<ReactMarkdown isReadOnly value={currentCode} />
202+
</Modal>
156203
</div>
157204
);
158205
};

0 commit comments

Comments
 (0)