From 2ea96973adf92efed7a2fc4e3630405660f7d047 Mon Sep 17 00:00:00 2001 From: Ari Date: Fri, 15 Jul 2022 18:35:25 -0400 Subject: [PATCH] top bar --- .gitignore | 1 + .../src/components/AutomationEditor/index.css | 33 +++++- .../AutomationEditor/index.stories.tsx | 3 +- .../src/components/AutomationEditor/index.tsx | 49 ++++++++ .../AutomationList/AutomationList.stories.tsx | 4 +- .../src/components/DAGGraph/board/index.tsx | 2 +- .../DAGGraph/elements/index.stories.tsx | 33 ++++++ .../components/DAGGraph/elements/index.tsx | 108 ++++++++++++------ .../src/components/DAGGraph/elements/util.tsx | 21 ++++ .../src/components/DAGGraph/error/index.tsx | 49 -------- .../nodes/CollectionNode/CollectionNode.tsx | 4 +- .../DAGGraph/nodes/CollectionNode/types.ts | 1 + .../DAGGraph/nodes/SequenceNode/types.ts | 2 +- .../DAGGraph/nodes/SequenceNode/util.ts | 2 + webapp/src/components/Inputs/InputList.css | 15 +++ webapp/src/components/Inputs/InputList.tsx | 20 +++- webapp/src/components/SimpleErrorElement.tsx | 29 ++++- webapp/src/types/validators/index.test.ts | 98 ++++++++-------- webapp/src/utils/automations.test.ts | 23 ++++ webapp/src/utils/automations.ts | 25 +++- 20 files changed, 372 insertions(+), 150 deletions(-) create mode 100644 webapp/src/components/DAGGraph/elements/util.tsx delete mode 100644 webapp/src/components/DAGGraph/error/index.tsx create mode 100644 webapp/src/components/Inputs/InputList.css create mode 100644 webapp/src/utils/automations.test.ts diff --git a/.gitignore b/.gitignore index 429b510..b15df9d 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .vscode/*.log +webapp/src/types/validators/index.test.ts diff --git a/webapp/src/components/AutomationEditor/index.css b/webapp/src/components/AutomationEditor/index.css index cb1bdc5..29eceb0 100644 --- a/webapp/src/components/AutomationEditor/index.css +++ b/webapp/src/components/AutomationEditor/index.css @@ -29,10 +29,41 @@ display: flex; flex-direction: row; gap: 0.25em; - justify-content: flex-end; + justify-content: space-between; margin-top: 0.25em; } +.automation-editor--flow-wrapper--toolbar--title { + display: flex; + flex-direction: row; + justify-content: flex-start; + align-items: center; + gap: 0.25em; + width: 100%; +} + +.automation-editor--flow-wrapper--toolbar--title--text .id { + font-size: 0.75em; + max-width: 15em; + padding: 0; + margin: 0; + white-space: break-word; + overflow: hidden; + text-overflow: ellipsis; +} + +.automation-editor--flow-wrapper--toolbar .automation-editor--flow-wrapper--toolbar--modes .MuiSelect-select { + padding-left: 0.25em; + padding-right: 0.25em; + padding-top: 1.15em; + padding-bottom: 0.25em; +} + +.automation-editor--flow-wrapper--toolbar .automation-editor--flow-wrapper--toolbar--modes .MuiInputLabel-root { + font-size: 0.9em; + left: -0.5em; +} + .automation-editor--flow-wrapper.changed>.automation-editor--flow-wrapper--toolbar * { border-color: var(--mui-success-light); color: var(--mui-success-light) diff --git a/webapp/src/components/AutomationEditor/index.stories.tsx b/webapp/src/components/AutomationEditor/index.stories.tsx index 8016148..8f1eefc 100644 --- a/webapp/src/components/AutomationEditor/index.stories.tsx +++ b/webapp/src/components/AutomationEditor/index.stories.tsx @@ -45,7 +45,8 @@ Simple.args = { Use: "Flushing", }, metadata: { - id: "random", + id: + "random" + String(Date.now()) + String(Date.now()) + String(Date.now()), alias: "Random", description: "Example Metadata", trigger_variables: { diff --git a/webapp/src/components/AutomationEditor/index.tsx b/webapp/src/components/AutomationEditor/index.tsx index 1377592..0e4ddee 100644 --- a/webapp/src/components/AutomationEditor/index.tsx +++ b/webapp/src/components/AutomationEditor/index.tsx @@ -16,6 +16,8 @@ import { ArrowBack } from "@mui/icons-material"; import { useCookies } from "react-cookie"; import { DAGDims } from "components/DAGGraph/elements/types"; import { DAGAutomationGraph } from "components/DAGGraph"; +import { InputAutoComplete } from "components/Inputs/InputAutoComplete"; +import { InputList } from "components/Inputs/InputList"; interface Props { automation?: AutomationData; @@ -95,6 +97,53 @@ export const AutomationEditor: FC = ({ className={["automation-editor--flow-wrapper", state.status].join(" ")} >
+
+ +
{state.data.metadata.id}
+ {state.data.metadata.alias} +
+ + updateMetadata( + { + ...state.data.metadata, + mode: id, + }, + state.data.tags + ) + } + getKey={({ id }) => id} + getDescription={({ label }) => label} + options={[ + { + id: "single", + label: "Do not start a new run. Issue a warning.", + }, + { + id: "parallel", + label: + "Start a new, independent run in parallel with previous runs.", + }, + { + id: "queued", + label: + "Start a new run after all previous runs complete. Runs are guaranteed to execute in the order they were queued.", + }, + { + id: "restart", + label: "Start a new run after first stopping previous run.", + }, + ]} + /> + {state.data.metadata.description} +
{!dims.flipped && ( - - - - */} -
- ); -}; diff --git a/webapp/src/components/DAGGraph/nodes/CollectionNode/CollectionNode.tsx b/webapp/src/components/DAGGraph/nodes/CollectionNode/CollectionNode.tsx index 70ec4de..c3f93df 100644 --- a/webapp/src/components/DAGGraph/nodes/CollectionNode/CollectionNode.tsx +++ b/webapp/src/components/DAGGraph/nodes/CollectionNode/CollectionNode.tsx @@ -71,11 +71,11 @@ export const CollectionNode: FC = ({
{nodes.map((n, i) => ( ))}
diff --git a/webapp/src/components/DAGGraph/nodes/CollectionNode/types.ts b/webapp/src/components/DAGGraph/nodes/CollectionNode/types.ts index 9f965f6..ff98919 100644 --- a/webapp/src/components/DAGGraph/nodes/CollectionNode/types.ts +++ b/webapp/src/components/DAGGraph/nodes/CollectionNode/types.ts @@ -6,6 +6,7 @@ import { AutomationActionData } from "types/automations"; export type CollectionNodeChildProps = Partial & { enabled: boolean; label: ReactNode; + color?: SequenceNodeColor; }; export type CollectionNodeDataProps = Size & { nodes: CollectionNodeChildProps[]; diff --git a/webapp/src/components/DAGGraph/nodes/SequenceNode/types.ts b/webapp/src/components/DAGGraph/nodes/SequenceNode/types.ts index 25e5943..dbca6b2 100644 --- a/webapp/src/components/DAGGraph/nodes/SequenceNode/types.ts +++ b/webapp/src/components/DAGGraph/nodes/SequenceNode/types.ts @@ -1,6 +1,6 @@ import { ReactNode } from "react"; -export type SequenceNodeColor = "red" | "blue" | "green" | "lblue"; +export type SequenceNodeColor = "red" | "blue" | "green" | "lblue" | "error"; export type SequenceNodeOnMove = Record< Direction, () => void diff --git a/webapp/src/components/DAGGraph/nodes/SequenceNode/util.ts b/webapp/src/components/DAGGraph/nodes/SequenceNode/util.ts index 1b3ecec..b33c738 100644 --- a/webapp/src/components/DAGGraph/nodes/SequenceNode/util.ts +++ b/webapp/src/components/DAGGraph/nodes/SequenceNode/util.ts @@ -11,6 +11,8 @@ export const useSequenceNodeColor = (color: SequenceNodeColor): string => { : color === "lblue" ? theme.palette.info.light : color === "red" + ? theme.palette.warning.dark + : color === "error" ? theme.palette.error.dark : "none"; }; diff --git a/webapp/src/components/Inputs/InputList.css b/webapp/src/components/Inputs/InputList.css new file mode 100644 index 0000000..eec287d --- /dev/null +++ b/webapp/src/components/Inputs/InputList.css @@ -0,0 +1,15 @@ +.MuiMenuItem-root.input-list--menu-item { + display: inherit; +} + +.input-list--menu-item .input-list--menu-item--description { + font-size: 0.75em; + max-width: 80vw; + overflow: hidden; + text-overflow: ellipsis; + overflow-wrap: break-word; +} + +.MuiSelect-select .input-list--menu-item--description { + display: none; +} \ No newline at end of file diff --git a/webapp/src/components/Inputs/InputList.tsx b/webapp/src/components/Inputs/InputList.tsx index b83dc0e..799f764 100644 --- a/webapp/src/components/Inputs/InputList.tsx +++ b/webapp/src/components/Inputs/InputList.tsx @@ -1,3 +1,5 @@ +import "./InputList.css"; + import FormHelperText from "@mui/material/FormHelperText"; import InputLabel from "@mui/material/InputLabel"; import MenuItem from "@mui/material/MenuItem"; @@ -15,11 +17,13 @@ export type Props = { className?: string; prettyOptionLabels?: boolean; getKey?: (n: T) => string; + getDescription?: (n: T) => string; placeholder?: any; title?: string; helperText?: string; endAdornment?: ReactNode; disabled?: boolean; + fullWidth?: boolean; }; export function InputList({ current, @@ -30,11 +34,13 @@ export function InputList({ className, prettyOptionLabels = true, getKey = String, + getDescription, placeholder, title, helperText, endAdornment, disabled, + fullWidth = true, }: Props) { const invalidCurrent = current && !options.map(getKey).includes(getKey(current)); @@ -43,7 +49,7 @@ export function InputList({ className={className} variant="filled" sx={{ marginRight: "0.25em", minWidth: `${label.length * 0.75}em` }} - fullWidth + fullWidth={fullWidth} disabled={disabled} > {label} @@ -62,12 +68,20 @@ export function InputList({ label={label} variant="filled" error={invalidCurrent} - fullWidth + fullWidth={fullWidth} disabled={disabled} > {options.map((t, i) => ( - + {prettyOptionLabels ? prettyName(getKey(t)) : getKey(t)} + {!!getDescription && ( + <> +
+
+ {getDescription(t)} +
+ + )}
))} diff --git a/webapp/src/components/SimpleErrorElement.tsx b/webapp/src/components/SimpleErrorElement.tsx index a0b9f61..2a02303 100644 --- a/webapp/src/components/SimpleErrorElement.tsx +++ b/webapp/src/components/SimpleErrorElement.tsx @@ -2,14 +2,31 @@ import { FC } from "react"; export const SimpleErrorElement: FC<{ error: Error }> = ({ error }) => { return ( - <> - {error?.name} +
+ Error Name: {error?.name}
- {error?.message} + Error Message + {error?.message}
- {error?.stack} + Error Stack + + {error?.stack?.split("\n").map((t, i) => ( + {t} + ))} +
- {JSON.stringify(error)} - + JSON: + {JSON.stringify(error)} +
); }; diff --git a/webapp/src/types/validators/index.test.ts b/webapp/src/types/validators/index.test.ts index 117c20f..d99e966 100644 --- a/webapp/src/types/validators/index.test.ts +++ b/webapp/src/types/validators/index.test.ts @@ -1,55 +1,61 @@ import * as st from "superstruct"; import { AutomationMetadata } from "./metadata"; -import { AutomationData } from './autmation'; -import { getFailures } from './helper'; +import { AutomationData } from "./autmation"; +import { getFailures } from "./helper"; import { AutomationTimeString } from "./common"; +import { ParallelAction } from "./actions"; -test('superstructure is', () => { - const badCheck = st.is({}, AutomationMetadata); - expect(badCheck).toBeFalsy() -}) +test("superstructure is", () => { + const badCheck = st.is({}, AutomationMetadata); + expect(badCheck).toBeFalsy(); +}); -test('getFailures returns failures', () => { - const failures = getFailures({ metadata: {} }, AutomationData); - expect(failures).toHaveLength(6) -}) +test("getFailures returns failures", () => { + const failures = getFailures({ metadata: {} }, AutomationData); + expect(failures).toHaveLength(6); +}); -test('getFailures returns null', () => { - const failures = getFailures({ - id: "test", - alias: "hey", - description: "wow", - mode: "single", - }, AutomationMetadata); - expect(failures).toBeNull() -}) +test("getFailures returns null", () => { + const failures = getFailures( + { + id: "test", + alias: "hey", + description: "wow", + mode: "single", + }, + AutomationMetadata + ); + expect(failures).toBeNull(); +}); -test('AutomationTimeString is valid', () => { - for (const c of [ - '10:23', - '15:02', - '13:00:1', - '23:00:23' - ]) { - const failures = getFailures(c, AutomationTimeString) - expect(failures).toBeNull() - } -}) +test("AutomationTimeString is valid", () => { + for (const c of ["10:23", "15:02", "13:00:1", "23:00:23"]) { + const failures = getFailures(c, AutomationTimeString); + expect(failures).toBeNull(); + } +}); +test("AutomationTimeString is invalid", () => { + for (const c of ["xx:23", "1x:02", "13:0a:1c", "25:00:23", "11"]) { + const failures = getFailures( + { + time: c, + }, + st.object({ + time: AutomationTimeString, + }) + ); + expect(failures).toHaveLength(1); + } +}); -test('AutomationTimeString is invalid', () => { - for (const c of [ - 'xx:23', - '1x:02', - '13:0a:1c', - '25:00:23', - '11' - ]) { - const failures = getFailures({ - "time": c - }, st.object({ - time: AutomationTimeString, - })) - expect(failures).toHaveLength(1) - } -}) \ No newline at end of file +test("Node Validation for parallel", () => { + expect( + getFailures( + { + parallel: { bad: "me" }, + }, + ParallelAction + ) + ).toHaveLength(1); +}); diff --git a/webapp/src/utils/automations.test.ts b/webapp/src/utils/automations.test.ts new file mode 100644 index 0000000..d2259a9 --- /dev/null +++ b/webapp/src/utils/automations.test.ts @@ -0,0 +1,23 @@ +import { validateNode } from "./automations"; + +test("validate works on bad conditions", () => { + expect( + validateNode( + { + condition: "and", + thisshouldnotbehere: "1", + conditions: "1234", + } as any, + ["condition"] + ) + ).toHaveLength(1); + + expect( + validateNode( + { + event: "triggerme", + }, + ["condition"] + ) + ).toHaveLength(2); +}); diff --git a/webapp/src/utils/automations.ts b/webapp/src/utils/automations.ts index cf8b075..8ecc27a 100644 --- a/webapp/src/utils/automations.ts +++ b/webapp/src/utils/automations.ts @@ -196,6 +196,18 @@ export const validateNode = ( node: AutomationNode, allowedNodeTypes: AutomationNodeTypes[] = [] ): MiniFailure[] | null => { + if (typeof node !== "object") { + return [ + { + message: [ + `Expected an object but got type of "${typeof node}" = ${JSON.stringify( + node + )}`, + ], + path: "$", + }, + ]; + } let nodeType = getNodeType(node); let errors: MiniFailure[] = []; if (allowedNodeTypes.length > 0 && !allowedNodeTypes.includes(nodeType)) { @@ -203,7 +215,7 @@ export const validateNode = ( message: [ `Got node of type "${nodeType}" but expected one of {${allowedNodeTypes}}`, ], - path: "", + path: "$", }); nodeType = allowedNodeTypes[0]; } @@ -214,7 +226,16 @@ export const validateNode = ( errors.push({ message: [`Failed to identifiy subtype`], path: "" }); } if (nodeSubType) { - const failures = getFailures(node, AllValidators[nodeType][nodeSubType]); + const validator = AllValidators[nodeType][nodeSubType]; + if (!validator) { + return errors.concat([ + { + message: [`"${nodeSubType}" is not a known type for ${nodeType}`], + path: "$", + }, + ]); + } + const failures = getFailures(node, validator); if (failures) { errors = errors.concat(failures); }