-
Notifications
You must be signed in to change notification settings - Fork 73
GS Onboarding (backend and frontend) #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
6240c7b
Add data validation for commands
Jiatao7 c463b13
implement create command
Jiatao7 dcd195b
implement delete command
Jiatao7 bde659e
add logger middleware
Jiatao7 dafe1d4
finish onboarding for backend
Jiatao7 cb2bfe6
implement delete command
Jiatao7 957b4cc
implement create command
Jiatao7 2fa2963
fix create command
Jiatao7 1ff2486
make requested changes
Jiatao7 db6bb39
complete new changes for backend
Jiatao7 2822edb
complete new changes for frontend
Jiatao7 cc0b376
complete new changes for frontend
Jiatao7 1f2e9a2
add parameters missing to alert
Jiatao7 fe95383
finish frontend changes
Jiatao7 4a5fc21
finish frontend changes
Jiatao7 54c6b5f
minor change
Jiatao7 b8fae64
make requested changes
Jiatao7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| export interface CommandRequest { | ||
| name: string | ||
| command_type: number, | ||
| params: string | null | ||
| format: string | null | ||
| //format: string | null | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,30 +1,120 @@ | ||
| import "./command_input.css" | ||
| import { useState, useEffect } from "react" | ||
| import { MainCommandResponse } from "../data/response" | ||
| import { createCommand, getMainCommands } from "./input_api" | ||
|
|
||
|
|
||
| const CommandInput = () => { | ||
| // TODO: (Member) Setup state and useEffect calls here | ||
| const [mainCommands, setMainCommands] = useState<MainCommandResponse[]>([]) | ||
| const [commandType, setCommandType] = useState<MainCommandResponse | null>(null) | ||
| const [params, setParams] = useState<Map<string, string>>(new Map()); | ||
|
|
||
| useEffect(() => { | ||
| const setMainCommandsFn = async () => { | ||
| const data = await getMainCommands() | ||
| if(data.data.length === 0) { | ||
| alert("Error occurred. Please try again later.") | ||
| return | ||
| } | ||
| setMainCommands(data.data) | ||
| setCommandType(data.data[0]) | ||
|
|
||
| const parameters = data.data[0].params?.split(",") || [] | ||
| let paramsObject : Map<string, string> = new Map() | ||
|
|
||
| for(const param of parameters) { | ||
| paramsObject.set(param, "") | ||
| } | ||
| setParams(paramsObject); | ||
| } | ||
| setMainCommandsFn(); | ||
| }, []) | ||
|
|
||
|
|
||
| const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => { | ||
| // TODO:(Member) Submit to your post endpoint | ||
| e.preventDefault(); | ||
|
|
||
| //Check if parameters are valid | ||
| const allParams = commandType?.params?.split(",") || []; | ||
| const paramsList = [] | ||
|
|
||
| const missingParams = [] | ||
| for (const param of allParams) { | ||
| if (!params.get(param)) { | ||
| missingParams.push(param) | ||
| } | ||
| paramsList.push(params.get(param)) | ||
| } | ||
| if(missingParams.length !== 0) { | ||
| alert(`Parameters missing: ${missingParams.join(", ")}`) | ||
| return; | ||
| } | ||
|
|
||
|
|
||
| const reqBody = { | ||
| command_type: commandType?.id || 0, | ||
| params: paramsList.join(",") | ||
| }; | ||
|
|
||
|
|
||
| const createCommandFn = async () => { | ||
| await createCommand(reqBody); | ||
| window.location.reload(); | ||
| } | ||
| createCommandFn(); | ||
| } | ||
|
|
||
| const changeCommandType = (e: React.ChangeEvent<HTMLSelectElement>) => { | ||
| const cmdType = mainCommands.find(cmd => cmd.id === +e.target.value) | ||
| if(!cmdType) { | ||
| alert("Error occurred. Please try again later.") | ||
| return | ||
| } | ||
| setCommandType(cmdType) | ||
| const parameters = cmdType?.params?.split(",") || [] | ||
| let paramsObject : Map<string, string> = new Map() | ||
| for(const param of parameters) { | ||
| paramsObject.set(param, "") | ||
| } | ||
| setParams(paramsObject) | ||
| } | ||
|
|
||
| const changeParam = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
| const param = e.target.id | ||
| const value = e.target.value | ||
|
|
||
| const handleSubmit = () => { | ||
| // TODO:(Member) Submit to your post endpoint | ||
| setParams(prevParams => { | ||
| const newParams = new Map(prevParams); | ||
| newParams.set(param, value); | ||
| return newParams; | ||
| }) | ||
| } | ||
|
|
||
| return ( | ||
| <> | ||
| <form> | ||
| <form onSubmit={handleSubmit}> | ||
| <div className="spreader"> | ||
| <div> | ||
| <label>Command Type: </label> | ||
| <select>{/* TODO: (Member) Display the list of commands based on the get commands request*/} | ||
| <option value={"1"}>Command 1</option> | ||
| <option value={"2"}>Command 2</option> | ||
| <option value={"3"}>Command 3</option> | ||
| {/* TODO: (Member) Display the list of commands based on the get commands request*/} | ||
| <select | ||
| value={commandType?.id} | ||
| onChange={changeCommandType}> | ||
| {mainCommands.map(cmd => (<option value={cmd.id}>{cmd.name}</option>))} | ||
| </select> | ||
| </div> | ||
| <input /> {/* TODO: (Member) Add input handling here if the selected command has a param input*/} | ||
| <button onClick={handleSubmit}>Submit</button> | ||
|
|
||
| {/* TODO: (Member) Add input handling here if the selected command has a param input*/} | ||
| {commandType && | ||
| commandType.params?.split(",").map((param) => (<input value={params.get(param)} id={param} placeholder={`Enter ${param}`} onChange={changeParam}/>))} | ||
|
|
||
| <button type="submit">Submit</button> | ||
| </div> | ||
| </form> | ||
| </> | ||
| </> | ||
| ) | ||
| } | ||
|
|
||
| export default CommandInput; | ||
| export default CommandInput; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,8 @@ | |
| from backend.data.enums import CommandStatus | ||
| from backend.utils.time import to_unix_time | ||
|
|
||
| from datetime import datetime | ||
|
|
||
|
|
||
| def test_get_commands(fastapi_test_client: TestClient, commands_json): | ||
| with fastapi_test_client as client: | ||
|
|
@@ -24,8 +26,10 @@ def test_create_command(fastapi_test_client: TestClient): | |
| assert result.get("status") == CommandStatus.PENDING.value | ||
| assert result.get("params") == "123456789" | ||
| # TODO: Figure out a better way to check the times | ||
| assert result.get("created_on") | ||
| assert result.get("updated_on") | ||
| created_on_dt = datetime.fromisoformat(result.get("created_on")) | ||
| updated_on_dt = datetime.fromisoformat(result.get("updated_on")) | ||
| assert isinstance(created_on_dt, datetime) | ||
| assert isinstance(updated_on_dt, datetime) | ||
|
Comment on lines
28
to
+32
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks. Not a part of the onboarding but definitely something that can be improved. Ill link this in the task to improve the gs onboarding. |
||
|
|
||
| def test_delete_command_fail(fastapi_test_client: TestClient): | ||
| with fastapi_test_client as client: | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.