From 0e4e4783fadf584318d8b9a109db8ecfb2e60ad4 Mon Sep 17 00:00:00 2001 From: Ari Date: Fri, 15 Jul 2022 22:53:51 -0400 Subject: [PATCH] Moved infobox to modal --- .../AutomationEditor/AutoInfoBox.css | 23 +---- .../AutomationEditor/AutoInfoBox.stories.tsx | 41 ++++---- .../AutomationEditor/AutoInfoBox.tsx | 4 +- .../src/components/AutomationEditor/index.css | 32 +++--- .../src/components/AutomationEditor/index.tsx | 55 +++++++---- .../AutomationList/AutomationListBoxGroup.tsx | 23 ++++- .../AutomationList/AutomationMetadataBox.css | 18 ++++ .../AutomationList/AutomationMetadataBox.tsx | 98 ++++++++++++------- .../AutomationList/index.mobile.css | 48 +-------- .../src/components/AutomationList/index.tsx | 29 ++++-- .../src/components/DAGGraph/board/index.css | 7 +- .../src/components/DAGGraph/board/index.tsx | 5 +- webapp/src/components/DAGGraph/board/types.ts | 1 + webapp/src/components/DAGGraph/index.tsx | 5 +- .../src/components/Inputs/InputTextView.css | 13 ++- .../src/components/Inputs/InputTextView.tsx | 2 +- 16 files changed, 222 insertions(+), 182 deletions(-) diff --git a/webapp/src/components/AutomationEditor/AutoInfoBox.css b/webapp/src/components/AutomationEditor/AutoInfoBox.css index 5c57cff..56f5061 100644 --- a/webapp/src/components/AutomationEditor/AutoInfoBox.css +++ b/webapp/src/components/AutomationEditor/AutoInfoBox.css @@ -1,31 +1,16 @@ .automation-editor--info-box { - height: 100%; - padding-left: 10px; - padding-right: 10px; display: flex; flex-direction: column; - justify-content: flex-start; - overflow: hidden; - position: relative; + align-items: center; + gap: 0.5em; } .automation-editor--info-box-inner { - height: 100%; + max-width: 95vw; + max-height: 90vh; overflow: auto; } -.automation-editor--info-box.show { - min-width: 20em; -} - -.automation-editor--info-box.hide { - min-width: 1em; -} - -.automation-editor--info-box.hide>.automation-editor--info-box-inner { - display: none; -} - .automation-editor--info-box--tags { padding: 0.25em 0.75em 1em 0.75em; border-color: var(--mui-grey-400); diff --git a/webapp/src/components/AutomationEditor/AutoInfoBox.stories.tsx b/webapp/src/components/AutomationEditor/AutoInfoBox.stories.tsx index de5daec..ad89e27 100644 --- a/webapp/src/components/AutomationEditor/AutoInfoBox.stories.tsx +++ b/webapp/src/components/AutomationEditor/AutoInfoBox.stories.tsx @@ -1,40 +1,35 @@ - import { ComponentMeta, ComponentStory } from "@storybook/react"; import { makeTagDB } from "components/AutomationList/TagDB"; import { Page } from "components/Page"; import { useState } from "react"; import { AutoInfoBox } from "./AutoInfoBox"; -import { defaultAutomation } from 'utils/defaults'; +import { defaultAutomation } from "utils/defaults"; export default { - title: 'App/AutomationList/Editor/InfoBox', + title: "App/AutomationList/Editor/InfoBox", component: AutoInfoBox, - parameters: { actions: { argTypesRegex: '^on.*' } }, + parameters: { actions: { argTypesRegex: "^on.*" } }, args: { - tagDB: makeTagDB([ - defaultAutomation("test") - ]) - } + tagDB: makeTagDB([defaultAutomation("test")]), + }, } as ComponentMeta; - -export const NoTags: ComponentStory = args => { - const [[metadata, tags], setState] = useState([args.metadata, args.tags]) +export const NoTags: ComponentStory = (args) => { + const [[metadata, tags], setState] = useState([args.metadata, args.tags]); return ( { - args.onUpdate(m, t) - setState([m, t]) + args.onUpdate(m, t); + setState([m, t]); }} /> - ) -} + ); +}; NoTags.args = { ...NoTags.args, tags: [], @@ -43,13 +38,13 @@ NoTags.args = { alias: "Random", description: "Example Metadata", trigger_variables: { - 'wowo': '!' + wowo: "!", }, - mode: 'single', + mode: "single", }, -} +}; -export const SomeTags: ComponentStory = NoTags.bind({}) +export const SomeTags: ComponentStory = NoTags.bind({}); SomeTags.args = { ...SomeTags.args, tags: [ @@ -61,8 +56,8 @@ SomeTags.args = { alias: "Bathroom Vent", description: "Turn the vent when the humidity is high", trigger_variables: { - 'wowo': '!' + wowo: "!", }, - mode: 'single', + mode: "single", }, -} +}; diff --git a/webapp/src/components/AutomationEditor/AutoInfoBox.tsx b/webapp/src/components/AutomationEditor/AutoInfoBox.tsx index 206916b..942b362 100644 --- a/webapp/src/components/AutomationEditor/AutoInfoBox.tsx +++ b/webapp/src/components/AutomationEditor/AutoInfoBox.tsx @@ -9,7 +9,6 @@ import { TagDB } from "components/AutomationList/TagDB"; import { ButtonIcon } from "components/Icons/ButtonIcons"; interface Props { - className: string; metadata: AutomationMetadata; tags: Array<[string, string]>; onUpdate: (m: AutomationMetadata, tags: Array<[string, string]>) => void; @@ -20,7 +19,6 @@ export const AutoInfoBox: FC = ({ metadata, tags, onUpdate, - className, children, tagDB, }) => { @@ -97,7 +95,7 @@ export const AutoInfoBox: FC = ({ ]); // render return ( -
+
.automation-editor--flow-wrapper--toolbar button { +.automation-editor.changed .automation-editor--flow-wrapper--toolbar--save-btn, +.automation-editor--info-box--buttons.changed .automation-editor--flow-wrapper--toolbar--save-btn { border-color: var(--mui-success-light); color: var(--mui-success-light); } @@ -92,21 +102,6 @@ position: relative; } -.automation-editor .automation-editor--info-box--icon { - position: absolute; - left: 0.25em; - bottom: 0em; - z-index: 10; - max-width: 1.5em; - max-height: 1.5em; -} - -.automation-editor--info-box.hide>.automation-editor--info-box--icon { - transform: rotate(180deg); - z-index: 2; - left: 0.1em; -} - .automation-editor.loading .mock-list { position: absolute; left: 0; @@ -127,4 +122,9 @@ top: 0; left: 0; width: 100%; +} + +.automation-editor--info-box--buttons { + display: flex; + gap: 1em; } \ No newline at end of file diff --git a/webapp/src/components/AutomationEditor/index.tsx b/webapp/src/components/AutomationEditor/index.tsx index 7eec762..6bfb803 100644 --- a/webapp/src/components/AutomationEditor/index.tsx +++ b/webapp/src/components/AutomationEditor/index.tsx @@ -3,8 +3,9 @@ import Icon from "@mui/material/Icon"; import { CheckMarkIcon } from "components/Icons"; import { FC, useState } from "react"; import { AutomationData } from "types/automations"; +import { Modal } from "components/Modal"; import { AutoInfoBox } from "./AutoInfoBox"; -import { ButtonIcon } from "components/Icons/ButtonIcons"; +import ModeEditOutlineTwoToneIcon from "@mui/icons-material/ModeEditOutlineTwoTone"; import { Button } from "components/Inputs/Button"; import { useAutomatioEditorState, EditorData } from "./state"; import { MiniFailure } from "types/validators/helper"; @@ -12,13 +13,12 @@ import InputYaml from "components/Inputs/InputYaml"; import { TagDB } from "components/AutomationList/TagDB"; import Skeleton from "@mui/material/Skeleton"; import LinearProgress from "@mui/material/LinearProgress"; -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"; import { InputTextView } from "components/Inputs/InputTextView"; +import { ControlButton } from "react-flow-renderer"; interface Props { automation?: AutomationData; @@ -43,7 +43,7 @@ export const AutomationEditor: FC = ({ save, saveAndUpdate, } = useAutomatioEditorState(propsAutos, propsOnUpdate); - const [closeInfo, setCloseInfo] = useState(false); + const [infoBoxOpen, setInfoBox] = useState(false); const [ { ckFlipped }, setCookies, @@ -74,25 +74,34 @@ export const AutomationEditor: FC = ({ ); } return ( -
+
{state.status === "saving" && ( )} - - setCloseInfo(!closeInfo)} - title={closeInfo ? "Show Metadata" : "Hide Metadata"} - color="success" - icon={} - /> - + + +
+ + +
+
+
= ({ ]} /> @@ -194,6 +204,11 @@ export const AutomationEditor: FC = ({ onTriggerUpdate={updateTrigger} onConditionUpdate={updateCondition} isFlipped={flipped} + additionalControls={ + setInfoBox(!infoBoxOpen)}> + + + } />
diff --git a/webapp/src/components/AutomationList/AutomationListBoxGroup.tsx b/webapp/src/components/AutomationList/AutomationListBoxGroup.tsx index 2aabea3..f145f4d 100644 --- a/webapp/src/components/AutomationList/AutomationListBoxGroup.tsx +++ b/webapp/src/components/AutomationList/AutomationListBoxGroup.tsx @@ -177,9 +177,10 @@ export const AutomationListBoxItem: FC<{ onSave, }) => { // state - const [{ tags, isModified }, setState] = useState({ + const [{ tags, isModified, alias }, setState] = useState({ isModified: false, tags: Object.entries(auto.tags), + alias: auto.metadata.alias ?? "", }); // effects @@ -187,14 +188,22 @@ export const AutomationListBoxItem: FC<{ setState({ isModified: false, tags: Object.entries(auto.tags), + alias: auto.metadata.alias ?? "", }); }, [auto]); // alias + const setAlias = (a: string) => + setState({ + isModified: true, + tags, + alias: a, + }); const setTags = (t: [string, string][]) => setState({ isModified: true, tags: t, + alias, }); // sub elements let title = "BadAuto<>"; @@ -215,10 +224,14 @@ export const AutomationListBoxItem: FC<{ onClick={() => onSelectAutomation(autoIndex)} >
{isModified && ( @@ -229,6 +242,10 @@ export const AutomationListBoxItem: FC<{ onSave({ ...auto, tags: Object.fromEntries(tags), + metadata: { + ...auto.metadata, + alias, + }, }) } /> diff --git a/webapp/src/components/AutomationList/AutomationMetadataBox.css b/webapp/src/components/AutomationList/AutomationMetadataBox.css index 47844d9..43b9c2d 100644 --- a/webapp/src/components/AutomationList/AutomationMetadataBox.css +++ b/webapp/src/components/AutomationList/AutomationMetadataBox.css @@ -7,6 +7,13 @@ .automation-list-box--body--item--title>b { font-size: 1em; + display: flex; + align-items: center; + gap: 0.25em; +} + +.automation-list-box--body--item--title .input-text-view span { + max-height: 1.5em; } .automation-list-box--body--item--title>span, .automation-list-box--body--item--title>b>span { @@ -80,4 +87,15 @@ .automation-list-box--body--item--tags--item>.text .icon:hover svg { fill: var(--mui-common-black); +} + +.automation-list-box--body--item--tags--item .delete { + font-size: 1em; + color: var(--mui-error-light); +} + +.automation-list-box--body--item--tags--item .delete:hover { + color: var(--mui-error-dark); + outline: 1px solid var(--mui-error-dark); + border-radius: 20px; } \ No newline at end of file diff --git a/webapp/src/components/AutomationList/AutomationMetadataBox.tsx b/webapp/src/components/AutomationList/AutomationMetadataBox.tsx index b695900..5982997 100644 --- a/webapp/src/components/AutomationList/AutomationMetadataBox.tsx +++ b/webapp/src/components/AutomationList/AutomationMetadataBox.tsx @@ -4,13 +4,16 @@ import { FC, useState } from "react"; import { AutomationMetadata } from "types/automations"; import { InputAutoComplete } from "components/Inputs/InputAutoComplete"; import { TagDB } from "./TagDB"; +import DeleteIcon from "@mui/icons-material/ClearTwoTone"; +import { InputTextView } from "components/Inputs/InputTextView"; export const MetadataBox: FC<{ metadata: AutomationMetadata; - onUpdate: (t: [string, string][]) => void; + onAliasUpdate: (t: string) => void; + onTagUpdate: (t: [string, string][]) => void; tags: [string, string][]; tagsDB: TagDB; -}> = ({ tags, onUpdate, tagsDB, metadata }) => { +}> = ({ tags, onTagUpdate, onAliasUpdate, tagsDB, metadata }) => { // state const [newTag, setNewTag] = useState< | { @@ -30,9 +33,12 @@ export const MetadataBox: FC<{ if (metadata) { title = ( <> - - {String(metadata.alias ?? "").slice(0, 15)}{" "} - ({String(metadata.id).slice(0, 5)}) + + + ({String(metadata.id).slice(0, 10)}) {String(metadata.description ?? "").slice(0, 25)} @@ -47,8 +53,14 @@ export const MetadataBox: FC<{ options={[tagOptions, tagsDB.getTagValues(tagName)]} key={tagIndex} value={[tagName, tagValue]} + onDelete={() => + onTagUpdate([ + ...tags.slice(0, tagIndex), + ...tags.slice(tagIndex + 1), + ]) + } onChange={([newName, newValue]) => - onUpdate([ + onTagUpdate([ ...tags.slice(0, tagIndex), [newName, newValue], ...tags.slice(tagIndex + 1), @@ -56,29 +68,34 @@ export const MetadataBox: FC<{ } /> ))} - {newTag.on && ( + {newTag.on ? ( { - if (name.trim() !== "" && value.trim() !== "") { - setNewTag({ - on: false, - }); - onUpdate([...tags, [name, value]]); - } else { - setNewTag({ - on: true, - name, - value, - }); + setNewTag({ + on: true, + name, + value, + }); + }} + onToggle={(em) => { + if (!em) { + if (newTag.name.trim() !== "" && newTag.value.trim() !== "") { + onTagUpdate(tags.concat([[newTag.name, newTag.value]])); + setNewTag({ + on: false, + }); + } } + setNewTag({ + on: false, + }); }} /> - )} - {!newTag.on && ( + ) : ( @@ -101,16 +118,29 @@ export const MetadataBoxTag: FC<{ value: [string, string]; onChange: (t: [string, string]) => void; options: [string[], string[]]; - initialState?: [boolean, boolean]; + initialState?: boolean; + onToggle?: (em: boolean) => void; + onDelete?: () => void; }> = (props) => { - const [[editMode1, editMode2], setEditMode] = useState( - props.initialState ? props.initialState : [false, false] + const [editMode, setEditMode] = useState( + props.initialState ? props.initialState : false ); - const toggle1 = () => setEditMode([!editMode1, editMode2]); - const toggle2 = () => setEditMode([editMode1, !editMode2]); + const toggle = () => { + if (editMode) { + if (props.value[0].trim() === "" || props.value[1].trim() === "") { + props.onToggle && props.onToggle(true); + return setEditMode(true); + } + } + props.onToggle && props.onToggle(!editMode); + setEditMode(!editMode); + }; return ( - {editMode1 ? ( + {props.onDelete && ( + + )} + {editMode ? ( props.onChange([v ?? "", props.value[1]])} onlyShowLabel - endAdornment={} + endAdornment={} /> ) : ( - + {props.value[0]}: )} - {editMode2 ? ( + {editMode ? ( props.onChange([props.value[0], v ?? ""])} onlyShowLabel - endAdornment={} + endAdornment={} /> ) : ( - + {props.value[1]} )} diff --git a/webapp/src/components/AutomationList/index.mobile.css b/webapp/src/components/AutomationList/index.mobile.css index 79e34d1..2ba13e0 100644 --- a/webapp/src/components/AutomationList/index.mobile.css +++ b/webapp/src/components/AutomationList/index.mobile.css @@ -17,28 +17,6 @@ left: 0.25em; } -.automation-list--root.mobile .automation-editor--info-box { - min-width: 100vw; - min-height: calc(100vh - 5em); - max-width: 100vw; - max-height: calc(100vh - 5em); - padding: 0; -} - -.automation-list--root.mobile .automation-editor--info-box-inner { - margin-top: 2.5em; - padding-left: 0.5em; - padding-right: 0.5em; - margin-bottom: 2em; -} - -.automation-list--root.mobile .automation-editor--info-box--icon { - left: 0.5em; - bottom: 0em; - background-color: var(--mui-common-black); - transform: rotate(90deg); -} - /* list hide */ .automation-list--root.mobile .automation-list--list.hide { @@ -50,29 +28,11 @@ .automation-list--root.mobile .automation-list--list.hide .automation-list--list-hide { transform: rotate(270deg); position: fixed; - top: 0; + top: 0.5em; z-index: 5; } -/* info box hide */ -.automation-list--root.mobile .automation-editor--info-box.hide { - width: 100vw; - min-height: 0; - max-height: 0; -} - -.automation-list--root.mobile .automation-editor--info-box.hide .automation-editor--info-box--icon { - transform: rotate(270deg); - position: fixed; - top: 0em; - left: 0.25em; - z-index: 10; -} - - - -.automation-list--root.mobile .automation-editor--flow-wrapper.unchanged>.automation-editor--flow-wrapper--toolbar { - height: 0; - opacity: 0; - overflow: hidden; +.automation-list--root.mobile .automation-editor--flow-wrapper>.automation-editor--flow-wrapper--toolbar .input-text-view, +.automation-list--root.mobile .automation-editor--flow-wrapper>.automation-editor--flow-wrapper--toolbar .id { + display: none; } \ No newline at end of file diff --git a/webapp/src/components/AutomationList/index.tsx b/webapp/src/components/AutomationList/index.tsx index af61960..cb75626 100644 --- a/webapp/src/components/AutomationList/index.tsx +++ b/webapp/src/components/AutomationList/index.tsx @@ -152,16 +152,22 @@ export const ConnectedAutomationList: FC = ({ dims, }) => { const { reloadAutomations } = useHA(); + const [saving, setSaving] = useState(false); const removeAutomation = async (args: any) => { const resp = await methods.removeAutomation(args); + setSaving(true); await reloadAutomations(); + setSaving(false); return resp; }; const updateAutomation = async (args: any) => { const resp = await methods.updateAutomation(args); + setSaving(true); await reloadAutomations(); + setSaving(false); return resp; }; + if (!automations.ready) { return (
@@ -176,15 +182,18 @@ export const ConnectedAutomationList: FC = ({ return Error {automations.error}; } return ( - {}} - onAdd={(auto) => - updateAutomation({ auto, index: automations.data.totalItems + 1 }) - } - onRemove={(index) => removeAutomation({ index })} - onUpdate={(index, auto) => updateAutomation({ index, auto })} - /> + <> + {saving && } + {}} + onAdd={(auto) => + updateAutomation({ auto, index: automations.data.totalItems + 1 }) + } + onRemove={(index) => removeAutomation({ index })} + onUpdate={(index, auto) => updateAutomation({ index, auto })} + /> + ); }; diff --git a/webapp/src/components/DAGGraph/board/index.css b/webapp/src/components/DAGGraph/board/index.css index 922387a..c326b35 100644 --- a/webapp/src/components/DAGGraph/board/index.css +++ b/webapp/src/components/DAGGraph/board/index.css @@ -1,10 +1,7 @@ -.dag-graphboard { - min-height: 100%; - min-width: 100%; -} - .dag-graphboard.loading { position: relative; + min-height: 100%; + min-width: 100%; } .dag-graphboard.loading span { diff --git a/webapp/src/components/DAGGraph/board/index.tsx b/webapp/src/components/DAGGraph/board/index.tsx index 733deaf..04b389f 100644 --- a/webapp/src/components/DAGGraph/board/index.tsx +++ b/webapp/src/components/DAGGraph/board/index.tsx @@ -22,6 +22,7 @@ export const DAGGraphBoardInner: FC = ({ modalState, state, closeModal, + additionalControls, }) => { // render unready or errored states if (!state.ready) { @@ -69,7 +70,9 @@ export const DAGGraphBoardInner: FC = ({ nodesDraggable={false} {...elements} > - + + {additionalControls} + ); diff --git a/webapp/src/components/DAGGraph/board/types.ts b/webapp/src/components/DAGGraph/board/types.ts index 999aadd..dd49a03 100644 --- a/webapp/src/components/DAGGraph/board/types.ts +++ b/webapp/src/components/DAGGraph/board/types.ts @@ -21,6 +21,7 @@ export type DAGGraphBoardProps = { state: DAGGraphBoardState; modalState?: ModalState; closeModal: () => void; + additionalControls?: ReactNode; }; export type ModalState< diff --git a/webapp/src/components/DAGGraph/index.tsx b/webapp/src/components/DAGGraph/index.tsx index fdda7bf..6aaf943 100644 --- a/webapp/src/components/DAGGraph/index.tsx +++ b/webapp/src/components/DAGGraph/index.tsx @@ -1,4 +1,4 @@ -import { FC, useState } from "react"; +import { FC, useState, ReactNode } from "react"; import { AutomationSequenceNode } from "types/automations"; import { useHA } from "haService"; import { ModalState } from "./board/types"; @@ -17,7 +17,9 @@ export const DAGAutomationGraph: FC<{ onTriggerUpdate: (t: AutomationTrigger[]) => void; onConditionUpdate: (c: AutomationCondition[]) => void; isFlipped: boolean; + additionalControls?: ReactNode; }> = (props) => { + console.log({ props }); const { namer } = useHA(); const [modalState, setModalState] = useState(undefined); @@ -62,6 +64,7 @@ export const DAGAutomationGraph: FC<{ elements: elementData, }, }} + additionalControls={props.additionalControls} /> ); }; diff --git a/webapp/src/components/Inputs/InputTextView.css b/webapp/src/components/Inputs/InputTextView.css index 02432a7..e970b02 100644 --- a/webapp/src/components/Inputs/InputTextView.css +++ b/webapp/src/components/Inputs/InputTextView.css @@ -1,9 +1,17 @@ .input-text-view { - width: 100%; - height: 100%; max-height: 2em; } +.input-text-view.view span { + height: 100%; + overflow: hidden; + text-overflow: ellipsis; + word-break: break-all; + word-wrap: break-word; + line-break: loose; + overflow-wrap: break-word; +} + .input-text-view.edit .MuiFilledInput-input { padding-top: 0.5em; padding-bottom: 0.5em; @@ -38,4 +46,5 @@ .input-text-view.view .input-text-view--edit:hover { transform: rotate(15deg); + cursor: pointer; } \ No newline at end of file diff --git a/webapp/src/components/Inputs/InputTextView.tsx b/webapp/src/components/Inputs/InputTextView.tsx index f2a0c1b..7b09646 100644 --- a/webapp/src/components/Inputs/InputTextView.tsx +++ b/webapp/src/components/Inputs/InputTextView.tsx @@ -26,7 +26,7 @@ export const InputTextView: FC = (props) => { return (
setViewMode(false)}> {!!props.value ? ( - props.value + {props.value} ) : ( {props.placeholder}