From ef876a1c0a91617f026655f0bc7e6ed152326ac7 Mon Sep 17 00:00:00 2001 From: Ari Date: Fri, 13 May 2022 16:29:27 -0400 Subject: [PATCH] cleaned up styling for editor --- .../src/components/AutomationEditor/state.ts | 1 - .../AutomationList/AutomationList.stories.tsx | 11 +- .../AutomationList/AutomationListBox.test.ts | 3 + .../ConnectedAutomationList.stories.tsx | 13 +- webapp/src/components/Inputs/InputBoolean.css | 20 +++ .../Inputs/InputBoolean.stories.tsx | 26 +++ webapp/src/components/Inputs/InputBoolean.tsx | 13 +- .../components/Inputs/InputList.stories.tsx | 21 ++- webapp/src/components/Inputs/InputList.tsx | 24 ++- .../src/components/Inputs/InputTextArea.tsx | 4 +- webapp/src/components/Inputs/InputWrapper.tsx | 6 +- webapp/src/components/Inputs/InputYaml.tsx | 43 +++-- webapp/src/components/Inputs/styles.ts | 24 ++- .../src/components/MultiNodeEditors/index.css | 4 + .../MultiNodeEditors/index.stories.tsx | 21 ++- .../src/components/MultiNodeEditors/index.tsx | 118 +++----------- .../src/components/MultiNodeEditors/state.ts | 154 ++++++++++++++++++ .../src/components/MultiNodeEditors/types.ts | 8 + .../NodeEditor/OptionManager/index.ts | 57 ------- .../NodeEditor/OptionManager/index.tsx | 106 ++++++++++++ webapp/src/components/NodeEditor/index.tsx | 29 ++-- webapp/src/styles/root.css | 1 + webapp/src/styles/theme.ts | 1 + webapp/src/utils/automations.ts | 31 +++- webapp/src/utils/useDelay.ts | 23 +++ 25 files changed, 532 insertions(+), 230 deletions(-) create mode 100644 webapp/src/components/Inputs/InputBoolean.css create mode 100644 webapp/src/components/Inputs/InputBoolean.stories.tsx create mode 100644 webapp/src/components/MultiNodeEditors/state.ts create mode 100644 webapp/src/components/MultiNodeEditors/types.ts delete mode 100644 webapp/src/components/NodeEditor/OptionManager/index.ts create mode 100644 webapp/src/components/NodeEditor/OptionManager/index.tsx create mode 100644 webapp/src/utils/useDelay.ts diff --git a/webapp/src/components/AutomationEditor/state.ts b/webapp/src/components/AutomationEditor/state.ts index 0913d2d..a92d7ce 100644 --- a/webapp/src/components/AutomationEditor/state.ts +++ b/webapp/src/components/AutomationEditor/state.ts @@ -18,7 +18,6 @@ export const useAutomatioEditorState = ( const [state, update] = useState({ status: "loading", }); - const makeUpdate = (name: K) => ( data: D ) => state.status !== 'loading' && update({ diff --git a/webapp/src/components/AutomationList/AutomationList.stories.tsx b/webapp/src/components/AutomationList/AutomationList.stories.tsx index 3214d8b..9c727a3 100644 --- a/webapp/src/components/AutomationList/AutomationList.stories.tsx +++ b/webapp/src/components/AutomationList/AutomationList.stories.tsx @@ -10,16 +10,7 @@ export default { component: AutomationList, parameters: { actions: { argTypesRegex: '^on.*' } }, args: { - dims: { - nodeHeight: dgconst.NODE_HEIGHT, - nodeWidth: dgconst.NODE_WIDTH, - distanceFactor: dgconst.DISTANCE_FACTOR, - circleSize: dgconst.CIRCLE_SIZE, - padding: { - x: dgconst.PADDING, - y: dgconst.PADDING, - }, - } + dims: dgconst.DEFAULT_DIMS } } as ComponentMeta; diff --git a/webapp/src/components/AutomationList/AutomationListBox.test.ts b/webapp/src/components/AutomationList/AutomationListBox.test.ts index 81c6fda..fbf196d 100644 --- a/webapp/src/components/AutomationList/AutomationListBox.test.ts +++ b/webapp/src/components/AutomationList/AutomationListBox.test.ts @@ -5,6 +5,7 @@ import { createMockAuto } from 'utils/mocks'; test('group automations', () => { const automations: AutomationData[] = [ { + condition: [], metadata: { id: '1', alias: '', @@ -19,6 +20,7 @@ test('group automations', () => { trigger: [], }, { + condition: [], metadata: { id: '2', alias: '', @@ -33,6 +35,7 @@ test('group automations', () => { trigger: [], }, { + condition: [], metadata: { id: '3', alias: '', diff --git a/webapp/src/components/AutomationList/ConnectedAutomationList.stories.tsx b/webapp/src/components/AutomationList/ConnectedAutomationList.stories.tsx index c1c3e6b..849ffea 100644 --- a/webapp/src/components/AutomationList/ConnectedAutomationList.stories.tsx +++ b/webapp/src/components/AutomationList/ConnectedAutomationList.stories.tsx @@ -2,23 +2,14 @@ import { ComponentMeta, ComponentStory } from "@storybook/react"; import { ConnectedAutomationList } from "."; import { createMockAuto } from "utils/mocks"; import { useMockApiService } from "apiService"; -import * as dgconst from 'components/DAGSvgs/constants'; +import { DEFAULT_DIMS } from 'components/DAGSvgs/constants'; export default { title: 'App/AutomationList/Connected', component: ConnectedAutomationList, parameters: { actions: { argTypesRegex: '^on.*' } }, args: { - dims: { - nodeHeight: dgconst.NODE_HEIGHT, - nodeWidth: dgconst.NODE_WIDTH, - distanceFactor: dgconst.DISTANCE_FACTOR, - circleSize: dgconst.CIRCLE_SIZE, - padding: { - x: dgconst.PADDING, - y: dgconst.PADDING, - }, - }, + dims: DEFAULT_DIMS, initialAutomations: [], } } as ComponentMeta; diff --git a/webapp/src/components/Inputs/InputBoolean.css b/webapp/src/components/Inputs/InputBoolean.css new file mode 100644 index 0000000..266a185 --- /dev/null +++ b/webapp/src/components/Inputs/InputBoolean.css @@ -0,0 +1,20 @@ +.input-boolean { + display: flex; + flex-direction: row; + justify-content: center; + align-items: center; + max-width: fit-content; + border: 1px solid var(--secondary-accent); + border-radius: 5px; + padding: 0.5em; + background-color: var(--secondary); +} + +.input-boolean:hover, .input-boolean:hover * { + cursor: pointer; + background-color: var(--secondary-opaque); +} + +.input-boolean * { + user-select: none; +} \ No newline at end of file diff --git a/webapp/src/components/Inputs/InputBoolean.stories.tsx b/webapp/src/components/Inputs/InputBoolean.stories.tsx new file mode 100644 index 0000000..b38c8e9 --- /dev/null +++ b/webapp/src/components/Inputs/InputBoolean.stories.tsx @@ -0,0 +1,26 @@ +import { ComponentMeta, ComponentStory } from "@storybook/react"; +import { useState } from "react"; + +import InputBoolean from "./InputBoolean"; + +export default { + title: 'Inputs/InputBoolean', + component: InputBoolean, + parameters: { actions: { argTypesRegex: '^on.*' } }, +} as ComponentMeta; + + +const Template: ComponentStory = args => { + const [state, onChange] = useState(args.value) + return
+ { + args.onChange(v) + onChange(v) + }} /> +
+} + +export const SimpleText = Template.bind({}) +SimpleText.args = { + label: "Template", +} diff --git a/webapp/src/components/Inputs/InputBoolean.tsx b/webapp/src/components/Inputs/InputBoolean.tsx index 611bbca..063b9d8 100644 --- a/webapp/src/components/Inputs/InputBoolean.tsx +++ b/webapp/src/components/Inputs/InputBoolean.tsx @@ -1,3 +1,4 @@ +import "./InputBoolean.css"; import InputWrapper from "./InputWrapper"; export interface Props { @@ -10,12 +11,8 @@ export default function InputBoolean({ value = false, onChange, }: Props) { - return - { - e.preventDefault() - onChange(!value) - }}> - {value ? '✔️' : ' '} - - + return
onChange(!value)}> + { }} /> + +
} diff --git a/webapp/src/components/Inputs/InputList.stories.tsx b/webapp/src/components/Inputs/InputList.stories.tsx index 6264575..0ec1bea 100644 --- a/webapp/src/components/Inputs/InputList.stories.tsx +++ b/webapp/src/components/Inputs/InputList.stories.tsx @@ -1,5 +1,5 @@ import { ComponentMeta, ComponentStory } from "@storybook/react"; -import { useState } from "react"; +import { useState, useEffect } from 'react'; import { InputList } from "./InputList"; @@ -12,7 +12,12 @@ export default { const Template: ComponentStory = args => { - const [value, setValue] = useState('') + const [value, setValue] = useState(args.current); + useEffect(() => { + if (value !== args.current) { + setValue(args.current) + } + }, [args.current]) return
@@ -27,3 +32,15 @@ SimpleText.args = { "Toots" ] } + + +export const InvalidSelection = Template.bind({}) +InvalidSelection.args = { + current: "Derek", + label: "Entity ID", + options: [ + 'Bob', + 'Martin', + "Toots" + ] +} diff --git a/webapp/src/components/Inputs/InputList.tsx b/webapp/src/components/Inputs/InputList.tsx index 2c7db67..dba38a1 100644 --- a/webapp/src/components/Inputs/InputList.tsx +++ b/webapp/src/components/Inputs/InputList.tsx @@ -15,17 +15,33 @@ export const InputList: FC> = ({ current, options, onChange, label, ...selattr }) => { - const { classes } = useInputListStyles({}); - return + const invalidCurrent = !options.includes(current); + const { classes } = useInputListStyles({ + invalidCurrent + }); + return } diff --git a/webapp/src/components/Inputs/InputTextArea.tsx b/webapp/src/components/Inputs/InputTextArea.tsx index 917ca7a..ca99be5 100644 --- a/webapp/src/components/Inputs/InputTextArea.tsx +++ b/webapp/src/components/Inputs/InputTextArea.tsx @@ -9,6 +9,7 @@ export interface Props { value: string; onChange: (v: string) => void; additionalTooltipFilters?: Record; + error?: string; resizable?: boolean; } export default function InputTextArea({ @@ -16,13 +17,14 @@ export default function InputTextArea({ textBoxFor, value = "", onChange, + error, additionalTooltipFilters = {}, resizable = false, }: Props) { const { classes } = useInputTextAreaStyles({ resizable }); const tooltip = useToolTip(); const [isFocused, setIsFocused] = useState(false) - return + return