-
Notifications
You must be signed in to change notification settings - Fork 73
(Post feedback version) GS Onboarding #22
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
Changes from 3 commits
1b81099
14feae2
fda6f11
f415bed
efa1cd7
da545ce
1b88801
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,9 +32,13 @@ def validate_params_format(self): | |
| In either of these cases return self. Otherwise raise a ValueError. | ||
| The format of the comma seperated values is "data1,data2" so no spaces between data and the commas. | ||
| """ | ||
| # TODO: (Member) Implement this method | ||
| return self | ||
|
|
||
| if self.params is None and self.format is None: | ||
| return self | ||
| elif isinstance(self.params, str) and isinstance(self.format, str) and self.params.count(",", 0, -1) == self.format.count(",", 0, -1): | ||
| return self | ||
|
||
|
|
||
| raise ValueError("Params and format either both be None or have the same number of comma separated values.") | ||
|
|
||
| class Command(BaseSQLModel, table=True): | ||
| """ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,5 @@ | ||
| export interface CommandRequest { | ||
| name: string | ||
| command_type: string | ||
| params: string | null | ||
| format: string | null | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,3 +20,12 @@ export const getCommands = async (): Promise<CommandListResponse> => { | |
| * @param id: command to delete | ||
| * @returns Promise<CommandListResponse>: list of commands after the command with the given id was deleted | ||
| */ | ||
| export const deleteCommand = async (id: number): Promise<CommandListResponse> => { | ||
| try { | ||
| const { data } = await axios.delete(`${API_URL}/${id}`) | ||
|
||
| return data; | ||
| } catch (error) { | ||
| console.error(error) | ||
| throw error | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| import { useEffect, useState } from "react" | ||
| import { CommandResponse } from "../data/response" | ||
| import { getCommands } from "./command_api" | ||
| import { getCommands, deleteCommand } from "./command_api" | ||
|
|
||
| import CommandRow from "./row" | ||
|
|
||
| const CommandTable = () => { | ||
|
|
@@ -17,6 +18,13 @@ const CommandTable = () => { | |
|
|
||
| const handleDelete = (id: number) => { | ||
| return () => { | ||
| try { | ||
| deleteCommand(id) | ||
|
||
| } catch (error) { | ||
| console.error(error) | ||
| throw error | ||
|
||
| } | ||
|
|
||
| // TODO: (Member) Handle delete logic here | ||
| // You will need to create a function in `command_api.ts` before you can finish this part. | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,30 +1,63 @@ | ||
| import "./command_input.css" | ||
| import { useEffect, useState } from "react"; | ||
| import { MainCommandResponse } from "../data/response"; | ||
| import "./command_input.css"; | ||
| import { createCommand, getMainCommands } from "./input_api"; | ||
| import { CommandRequest } from "../data/request"; | ||
|
|
||
| const CommandInput = () => { | ||
| // TODO: (Member) Setup state and useEffect calls here | ||
| const [mainCommands, setMainCommands] = useState<MainCommandResponse[]>([]); | ||
|
|
||
| const handleSubmit = () => { | ||
| // TODO:(Member) Submit to your post endpoint | ||
| } | ||
| const [selectedCommandId, setSelectedCommandId] = useState<string>( | ||
| mainCommands[0].id.toString() | ||
|
||
| ); | ||
| const [commandParams, setCommandParams] = useState<string | null>(null); | ||
|
|
||
| useEffect(() => { | ||
| const getMainCommandsFn = async () => { | ||
| const data = await getMainCommands(); | ||
Yarik-Popov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| setMainCommands(data.data); | ||
| setSelectedCommandId(data.data[0].id.toString()); | ||
| }; | ||
|
|
||
| getMainCommandsFn(); | ||
| }, []); | ||
|
|
||
| const handleSubmit = (e: React.FormEvent) => { | ||
| e.preventDefault(); | ||
| const command: CommandRequest = { | ||
| command_type: selectedCommandId, | ||
| params: commandParams, | ||
| }; | ||
|
|
||
| createCommand(command); | ||
Yarik-Popov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }; | ||
|
|
||
| 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> | ||
| <select onChange={(e) => setSelectedCommandId(e.target.value)}> | ||
| {/* TODO: (Member) Display the list of commands based on the get commands request*/} | ||
| {mainCommands.map((command) => ( | ||
| <option | ||
| key={command.id} | ||
| value={command.id} | ||
| > | ||
| {command.name} | ||
| </option> | ||
| ))} | ||
| </select> | ||
| </div> | ||
| <input /> {/* TODO: (Member) Add input handling here if the selected command has a param input*/} | ||
| <button onClick={handleSubmit}>Submit</button> | ||
| <input onChange={(e) => setCommandParams(e.target.value)} />{" "} | ||
|
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. Each command can have different types and number of arguments and the frontend should be able to handle that. They are encoded in the mainCommands |
||
| {/* TODO: (Member) Add input handling here if the selected command has a param input*/} | ||
| <button type="submit">Submit</button> | ||
| </div> | ||
| </form> | ||
| </> | ||
| ) | ||
| } | ||
| ); | ||
| }; | ||
|
|
||
| export default CommandInput; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to print the datetime of request