-
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 6 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 |
|---|---|---|
| @@ -1,27 +1,38 @@ | ||
| import { useEffect, useState } from "react" | ||
| import { CommandResponse } from "../data/response" | ||
| import { getCommands } from "./command_api" | ||
| import CommandRow from "./row" | ||
| import { useEffect, useState } from "react"; | ||
| import { CommandResponse } from "../data/response"; | ||
| import { getCommands, deleteCommand } from "./command_api"; | ||
|
|
||
| import CommandRow from "./row"; | ||
|
|
||
| const CommandTable = () => { | ||
| const [commands, setCommands] = useState<CommandResponse[]>([]) | ||
| const [commands, setCommands] = useState<CommandResponse[]>([]); | ||
|
|
||
| useEffect(() => { | ||
| const getCommandsFn = async () => { | ||
| const data = await getCommands(); | ||
| setCommands(data.data) | ||
| } | ||
| try { | ||
| const data = await getCommands(); | ||
| setCommands(data.data); | ||
| } catch (error) { | ||
| alert("Failed to retrieve commands"); | ||
| } | ||
| }; | ||
|
|
||
| getCommandsFn(); | ||
| }, []) | ||
| }, []); | ||
|
|
||
| const handleDelete = (id: number) => { | ||
| return () => { | ||
| try { | ||
| deleteCommand(id); | ||
| window.location.reload(); | ||
| } catch (error) { | ||
| alert(`Failed to delete command with id ${id}`); | ||
| } | ||
|
Comment on lines
18
to
30
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. make this async |
||
|
|
||
| // TODO: (Member) Handle delete logic here | ||
| // You will need to create a function in `command_api.ts` before you can finish this part. | ||
|
|
||
| } | ||
| } | ||
| }; | ||
| }; | ||
|
|
||
| return ( | ||
| <table> | ||
|
|
@@ -37,10 +48,12 @@ const CommandTable = () => { | |
| </tr> | ||
| </thead> | ||
| <thead> | ||
| {commands.map(value => (<CommandRow {...value} handleDelete={handleDelete(value.id)} />))} | ||
| {commands.map((value) => ( | ||
| <CommandRow {...value} handleDelete={handleDelete(value.id)} /> | ||
| ))} | ||
| </thead> | ||
| </table> | ||
| ) | ||
| } | ||
| ); | ||
| }; | ||
|
|
||
| export default CommandTable; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,30 +1,77 @@ | ||
| 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 | null>( | ||
| null | ||
| ); | ||
| const [commandParams, setCommandParams] = useState<string | null>(null); | ||
|
|
||
| useEffect(() => { | ||
| const getMainCommandsFn = async () => { | ||
| try { | ||
| const data = await getMainCommands(); | ||
| setMainCommands(data.data); | ||
| setSelectedCommandId(data.data[0].id.toString()); | ||
| } catch (error) { | ||
| alert("Failed to retrieve main commands"); | ||
| } | ||
| }; | ||
|
|
||
| getMainCommandsFn(); | ||
| }, []); | ||
|
|
||
| const handleSubmit = (e: React.FormEvent) => { | ||
| e.preventDefault(); | ||
|
|
||
| console.log("submitting command"); | ||
|
|
||
| if (!selectedCommandId) { | ||
| alert(`Select a command with an existing ID before submitting`); | ||
| return; | ||
| } | ||
|
|
||
| const command: CommandRequest = { | ||
| command_type: selectedCommandId, | ||
| params: commandParams, | ||
| }; | ||
|
|
||
| try { | ||
| createCommand(command); | ||
| window.location.reload(); | ||
| } catch (err) { | ||
| console.log("Failed to create command:", err); | ||
| } | ||
| }; | ||
|
|
||
| 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, index) => ( | ||
| <option key={index} 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