Skip to content

Commit bcd74d4

Browse files
authored
Made changes to frontend based on Kashif's feedback (#3)
# Purpose Made changes to frontend based on Kashif's feedback and some minor other changes. # New Changes - Add command status to string mapping - Update CommandResponse to have proper response fields - Fix typo in CommandResponseList - Add deleteCommand API function explanation (One of Kashif's feedback was to add task to create endpoint that uses axios) - Update row in command table to display proper data - Fix useEffect function performance issue # Testing - Frontend builds - No changes to backend but backend runs as expected - Ran the frontend and backend combo, they displays the correct data in the table # Outstanding Changes - Make changes based on other members feedback
1 parent b336c0f commit bcd74d4

File tree

6 files changed

+29
-17
lines changed

6 files changed

+29
-17
lines changed

frontend/src/data/other.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const CommandStatusMapping = ["Pending", "Scheduled", "Ongoing", "Cancelled", "Failed", "Completed"]

frontend/src/data/response.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ export interface MainCommandListResponse {
1313

1414
export interface CommandResponse {
1515
id: number
16-
name: string
16+
command_type: number
17+
status: number
1718
params: string | null
18-
format: string | null
1919
created_on: string
2020
updated_on: string
2121
}
2222

23-
export interface CommandListReponse {
23+
export interface CommandListResponse {
2424
data: CommandResponse[]
2525
}
Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
import axios from "axios";
2-
import { CommandListReponse } from "../data/response";
2+
import { CommandListResponse } from "../data/response";
33
import { API_URL } from "../environment";
44

5-
export const getCommands = async (): Promise<CommandListReponse> => {
5+
export const getCommands = async (): Promise<CommandListResponse> => {
66
try {
7-
const { data } = await axios.get<CommandListReponse>(`${API_URL}/commands/`)
7+
const { data } = await axios.get<CommandListResponse>(`${API_URL}/commands/`)
88
return data;
99
} catch (error) {
1010
console.error(error)
1111
throw error
1212
}
1313
}
14+
15+
/**
16+
* TODO: (Member) Create a deleteCommand API function based on the following specs. You should be using axios to make the API call
17+
*
18+
* Deletes the command with the given id on the backend and returns the list of commands after its deletion.
19+
*
20+
* @param id: command to delete
21+
* @returns Promise<CommandListResponse>: list of commands after the command with the given id was deleted
22+
*/

frontend/src/display/row.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1+
import { CommandStatusMapping } from "../data/other";
12
import { CommandResponse } from "../data/response";
23

34
interface CommandRowProp extends CommandResponse {
45
handleDelete: () => void;
56
}
67

7-
const CommandRow = ({ id, name, params, format, created_on, updated_on, handleDelete }: CommandRowProp) => {
8+
const CommandRow = ({ id, command_type, params, status, created_on, updated_on, handleDelete }: CommandRowProp) => {
89
return (
910
<tr>
1011
<th>{id}</th>
11-
<th>{name}</th>
12+
<th>{command_type}</th>
1213
<th>{params}</th>
13-
<th>{format}</th>
14+
<th>{CommandStatusMapping[status]}</th>
1415
<th>{created_on}</th>
1516
<th>{updated_on}</th>
1617
<th><button onClick={handleDelete}>Delete {id}</button></th>

frontend/src/display/table.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,19 @@ import CommandRow from "./row"
66
const CommandTable = () => {
77
const [commands, setCommands] = useState<CommandResponse[]>([])
88

9-
const getCommandsFn = async () => {
10-
const data = await getCommands();
11-
setCommands(data.data)
12-
}
13-
149
useEffect(() => {
10+
const getCommandsFn = async () => {
11+
const data = await getCommands();
12+
setCommands(data.data)
13+
}
14+
1515
getCommandsFn();
1616
}, [])
1717

1818
const handleDelete = (id: number) => {
1919
return () => {
2020
// TODO: (Member) Handle delete logic here
21+
// You will need to create a function in `command_api.ts` before you can finish this part.
2122

2223
}
2324
}
@@ -27,9 +28,9 @@ const CommandTable = () => {
2728
<thead>
2829
<tr>
2930
<th>ID: </th>
30-
<th>Name: </th>
31+
<th>Main Command ID: </th>
3132
<th>Params: </th>
32-
<th>Format: </th>
33+
<th>Status: </th>
3334
<th>Created On: </th>
3435
<th>Updated On: </th>
3536
<th>Delete</th>

frontend/src/input/input_api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { CommandRequest } from "../data/request";
33
import axios from "axios";
44
import { CommandResponse, MainCommandListResponse } from "../data/response";
55

6-
export const createCommand = async (requestData: CommandRequest): Promise<CommandResponse | undefined> => {
6+
export const createCommand = async (requestData: CommandRequest): Promise<CommandResponse> => {
77
try {
88
const { data } = await axios.post<CommandResponse>(`${API_URL}/commands`, requestData);
99
return data

0 commit comments

Comments
 (0)