From cc2597c408195b27579161159ec43c7f8834702b Mon Sep 17 00:00:00 2001 From: Ari Date: Wed, 29 Jun 2022 12:06:06 -0400 Subject: [PATCH] rebuilt condition editor --- .../ConditionEditor.stories.tsx | 52 ------ .../ConditionEditor/ConditionNode.tsx | 160 ------------------ .../ConditionEditor/ConditionNodeBase.css | 66 ++++++++ .../ConditionNodeBase.mobile.css | 19 +++ .../ConditionNodeBase.stories.tsx | 65 +++++++ .../ConditionEditor/ConditionNodeBase.tsx | 130 ++++++++++++++ .../ConditionEditor/ConditionNodeSettings.css | 18 ++ .../ConditionNodeSettings.mobile.css | 19 +++ .../ConditionEditor/ConditionNodeSettings.tsx | 101 +++++++++++ .../ConditionEditor/editorRender.tsx | 28 ++- .../ConditionEditor/index.stories.tsx | 121 ++++++++----- .../src/components/ConditionEditor/index.tsx | 28 ++- .../ConditionEditor/nestedUpdater.ts | 48 +++--- .../src/components/ConditionEditor/style.ts | 142 ---------------- .../components/ConditionEditor/viewRender.tsx | 6 +- webapp/src/components/Icons/ButtonIcons.tsx | 5 +- webapp/src/components/Page/index.tsx | 24 +++ webapp/src/components/SpeedDial/index.css | 12 ++ 18 files changed, 599 insertions(+), 445 deletions(-) delete mode 100644 webapp/src/components/ConditionEditor/ConditionEditor.stories.tsx delete mode 100644 webapp/src/components/ConditionEditor/ConditionNode.tsx create mode 100644 webapp/src/components/ConditionEditor/ConditionNodeBase.css create mode 100644 webapp/src/components/ConditionEditor/ConditionNodeBase.mobile.css create mode 100644 webapp/src/components/ConditionEditor/ConditionNodeBase.stories.tsx create mode 100644 webapp/src/components/ConditionEditor/ConditionNodeBase.tsx create mode 100644 webapp/src/components/ConditionEditor/ConditionNodeSettings.css create mode 100644 webapp/src/components/ConditionEditor/ConditionNodeSettings.mobile.css create mode 100644 webapp/src/components/ConditionEditor/ConditionNodeSettings.tsx delete mode 100644 webapp/src/components/ConditionEditor/style.ts diff --git a/webapp/src/components/ConditionEditor/ConditionEditor.stories.tsx b/webapp/src/components/ConditionEditor/ConditionEditor.stories.tsx deleted file mode 100644 index 20ea035..0000000 --- a/webapp/src/components/ConditionEditor/ConditionEditor.stories.tsx +++ /dev/null @@ -1,52 +0,0 @@ -import { ComponentMeta, ComponentStory } from "@storybook/react"; -import { useState } from "react"; -import { ConditionEditor } from "."; -import { AutomationCondition } from 'types/automations/conditions'; -import { Page } from "components/Page"; - -export default { - title: 'ConditionEditor', - component: ConditionEditor, - parameters: { actions: { argTypesRegex: '^on.*' } }, -} as ComponentMeta; - - -export const Basic: ComponentStory = args => { - const [state, setState] = useState({ - "condition": "or", - "conditions": [ - { - "condition": "and", - "conditions": [ - { - "condition": "numeric_state", - "entity_id": [ - "sensor.kitchen_humidity" - ], - "above": "40" - }, - { - "condition": "template", - "value_template": "states('switch.kitchen') == 'on'" - } - ] - }, - { - "condition": "numeric_state", - "entity_id": [ - "sensor.kitchen_temperature" - ], - "above": "51" - } - ] - }) - return ( - - { }} - condition={state} - /> - - ) -} diff --git a/webapp/src/components/ConditionEditor/ConditionNode.tsx b/webapp/src/components/ConditionEditor/ConditionNode.tsx deleted file mode 100644 index 34156d1..0000000 --- a/webapp/src/components/ConditionEditor/ConditionNode.tsx +++ /dev/null @@ -1,160 +0,0 @@ -import { Classes } from "jss"; -import { FC, useState, useEffect } from "react"; -import { getConditionDefaultValues } from "utils/defaults"; -import { AutomationCondition } from "types/automations/conditions"; -import { CheckMarkIcon, PencilIcon } from "components/Icons"; -import { InputList } from "components/Inputs/InputList"; -import InputYaml from "components/Inputs/InputYaml"; -import { getEditor } from "./editorRender"; -import { useStyles } from "./style"; -import { getViewer } from "./viewRender"; -import useWindowSize from "utils/useWindowSize"; -import { useHA } from "haService"; -import { getSubTypeList } from "utils/automations"; - -export const ConditionNode: FC<{ - condition: AutomationCondition; - displayMode: boolean; - showDelete?: boolean; - onDelete?: (which: "root" | number) => void; - onUpdate?: (data: AutomationCondition) => void; - children?: (props: { classes: Classes }) => JSX.Element; -}> = ({ - condition, - showDelete = false, - displayMode = true, - onDelete = () => {}, - onUpdate = () => {}, - children = () => {}, -}) => { - // state - const [internalDisplayMode, setInternalDisplayMode] = useState(displayMode); - const [yamlMode, setYamlMode] = useState(false); - const { isMobile } = useWindowSize(); - const ha = useHA(); - // alias - const effectiveDM = internalDisplayMode || yamlMode; - // effect - useEffect(() => { - setInternalDisplayMode(displayMode); - }, [displayMode]); - useEffect(() => { - if (yamlMode) { - setInternalDisplayMode(true); - } - }, [yamlMode]); - // alias - const onAddChild = () => { - if ( - condition.condition === "and" || - condition.condition === "or" || - condition.condition === "not" - ) { - onUpdate({ - ...condition, - conditions: condition.conditions.concat({ - condition: "or", - conditions: [], - }), - }); - } - }; - // children - let childrenConditions: JSX.Element; - if (effectiveDM) { - const Viewer = getViewer(condition); - childrenConditions = ( - - ); - } else { - const Editor = getEditor(condition); - childrenConditions = ( - - ); - } - // styles - let hasChildren = false; - if (condition.condition === "not") { - hasChildren = true; - } else if (condition.condition === "and") { - hasChildren = true; - } else if (condition.condition === "or") { - hasChildren = true; - } - const { classes } = useStyles({ hasChildren, isMobile }); - - // components - const DeleteButton = (p: { onClick?: () => void; isRoot?: boolean }) => ( - - ); - - return ( -
- <> - {showDelete && !effectiveDM && ( - onDelete("root")} /> - )} -
- - onUpdate({ - ...getConditionDefaultValues(n), - ...condition, - condition: n, - } as any) - } - /> - {effectiveDM && ( - - )} - {!yamlMode && ( - - )} -
-
- {yamlMode && ( - onUpdate(update as any)} - /> - )} -
- {!yamlMode && childrenConditions} -
- {!yamlMode && hasChildren && ( -
- -
- )} -
- {children({ classes })} - -
- ); -}; diff --git a/webapp/src/components/ConditionEditor/ConditionNodeBase.css b/webapp/src/components/ConditionEditor/ConditionNodeBase.css new file mode 100644 index 0000000..6c1b332 --- /dev/null +++ b/webapp/src/components/ConditionEditor/ConditionNodeBase.css @@ -0,0 +1,66 @@ +.condition-node-base { + display: flex; + flex-direction: row; + max-height: 85vh; +} + +.condition-node-base--list { + max-width: 10em; + width: 7em; +} + +.condition-node-base--body { + flex: 1; + min-height: 1.5em; + display: flex; + flex-direction: row; +} + + +.condition-node-base--body--children.view { + display: flex; + flex-direction: column; + justify-content: center; + min-height: calc(100% - 1px); + max-height: calc(100% - 1px); + background-color: var(--secondary); + border-color: var(--secondary-accent); + border-bottom-style: solid; + border-width: 1px; +} + +.condition-node-base--body .input-yaml { + margin: 0; + padding: 0; +} + +.condition-node-base--body { + overflow: auto; + max-width: 100vw; +} + +.condition-node-base--body .condition-node-base--body--children { + flex: 1; + padding-left: 0.5em; + max-width: 100vw; + overflow-x: hidden; +} + +.condition-node-base.is-edited>.condition-node-base--body { + max-height: calc(100%-2px-1em); + max-width: calc(100vw-2px-1em); + border-color: var(--green); + border-style: solid; + border-width: 1px; + margin: 0.25em; + padding: 0.25em; +} + +.condition-node--logic-viewer--add { + display: flex; + flex-direction: row; + justify-content: center; + align-items: center; + padding: 0.5em; + background-color: var(--secondary); +} \ No newline at end of file diff --git a/webapp/src/components/ConditionEditor/ConditionNodeBase.mobile.css b/webapp/src/components/ConditionEditor/ConditionNodeBase.mobile.css new file mode 100644 index 0000000..ca8fab3 --- /dev/null +++ b/webapp/src/components/ConditionEditor/ConditionNodeBase.mobile.css @@ -0,0 +1,19 @@ +.condition-node-base.mobile { + flex-direction: column; + justify-content: center; +} + +.condition-node-base.mobile .condition-node-base--list { + flex-direction: row; + display: flex; + min-width: 100%; +} + +.condition-node-base.mobile .condition-node-base--body { + min-height: 3em; + max-width: 100%; +} + +.condition-node-base.mobile .condition-node-base--body.edit { + max-height: 500px; +} \ No newline at end of file diff --git a/webapp/src/components/ConditionEditor/ConditionNodeBase.stories.tsx b/webapp/src/components/ConditionEditor/ConditionNodeBase.stories.tsx new file mode 100644 index 0000000..074caa2 --- /dev/null +++ b/webapp/src/components/ConditionEditor/ConditionNodeBase.stories.tsx @@ -0,0 +1,65 @@ +import { ComponentMeta, ComponentStory } from "@storybook/react"; +import { Page } from "components/Page"; +import { useState } from "react"; +import { AutomationCondition } from "types/automations/conditions"; +import { ConditionNodeBase } from "./ConditionNodeBase"; + +export default { + title: "ConditionEditor/NodeBase", + component: ConditionNodeBase, + parameters: { actions: { argTypesRegex: "^on.*" } }, +} as ComponentMeta; + +const Template: ComponentStory = ({ + condition, + ...args +}) => { + const [data, setData] = useState(condition); + return ( + + { + setData(data); + }} + /> + + ); +}; + +export const TemplateViewer = Template.bind({}); +TemplateViewer.args = { + condition: { + condition: "template", + value_template: "states('switch.light_kitchen') == 'on'", + } as AutomationCondition, +}; + +export const MultipleThings = Template.bind({}); +MultipleThings.args = { + condition: { + condition: "or", + conditions: [ + { + condition: "and", + conditions: [ + { + condition: "numeric_state", + entity_id: ["sensor.kitchen_humidity"], + above: "40", + }, + { + condition: "template", + value_template: "states('switch.kitchen') == 'on'", + }, + ], + }, + { + condition: "numeric_state", + entity_id: ["sensor.kitchen_temperature"], + above: "51", + }, + ], + } as AutomationCondition, +}; diff --git a/webapp/src/components/ConditionEditor/ConditionNodeBase.tsx b/webapp/src/components/ConditionEditor/ConditionNodeBase.tsx new file mode 100644 index 0000000..e6d3ee8 --- /dev/null +++ b/webapp/src/components/ConditionEditor/ConditionNodeBase.tsx @@ -0,0 +1,130 @@ +import "./ConditionNodeBase.css"; +import "./ConditionNodeBase.mobile.css"; + +import { InputList } from "components/Inputs/InputList"; +import { FC, useState } from "react"; +import { AutomationCondition } from "types/automations/conditions"; +import { getSubTypeList } from "utils/automations"; +import { getConditionDefaultValues } from "utils/defaults"; +import CodeOutlinedIcon from "@mui/icons-material/CodeOutlined"; +import CodeOffOutlinedIcon from "@mui/icons-material/CodeOffOutlined"; +import EditOutlinedIcon from "@mui/icons-material/EditOutlined"; +import SaveIcon from "@mui/icons-material/Save"; +import EditOffIcon from "@mui/icons-material/EditOff"; +import DeleteForeverIcon from "@mui/icons-material/DeleteForever"; +import SettingsApplicationsIcon from "@mui/icons-material/SettingsApplications"; +import { useHA } from "haService"; +import { ButtonIcon } from "components/Icons/ButtonIcons"; +import InputYaml from "components/Inputs/InputYaml"; +import { getViewer } from "./viewRender"; +import { getEditor } from "./editorRender"; +import useWindowSize from "utils/useWindowSize"; +import { ConditionNodeSettings } from "./ConditionNodeSettings"; + +export type ConditionNodeBaseProps = { + condition: AutomationCondition; + onDelete?: () => void; + onUpdate: (data: AutomationCondition) => void; + disableDelete?: boolean; +}; +export type ConditionNodeBaseViewMode = "edit" | "yaml" | "view"; +export const ConditionNodeBase: FC = (props) => { + // state + const ha = useHA(); + const { isMobile } = useWindowSize(); + const [{ isEdited, condition }, setCondition] = useState<{ + isEdited: boolean; + condition: AutomationCondition; + }>({ + isEdited: false, + condition: props.condition, + }); + const [mode, setMode] = useState("view"); + // alias + const updateCondition = (data: any) => + setCondition({ + isEdited: true, + condition: data, + }); + + // children + let childrenConditions: JSX.Element; + if (mode === "view") { + const Viewer = getViewer(condition); + childrenConditions = ( + + ); + } else { + const Editor = getEditor(condition); + childrenConditions = ( + + ); + } + // icons + const icons = ( + { + props.onUpdate(condition); + setCondition({ + isEdited: false, + condition, + }); + }} + mode={mode} + isEdited={isEdited} + disableDelete={props.disableDelete ?? false} + /> + ); + // render + return ( +
+
+ + setCondition({ + isEdited: true, + condition: { + ...getConditionDefaultValues(n), + condition: n, + }, + } as any) + } + /> + {isMobile && icons} +
+
+ {mode === "yaml" ? ( + + ) : ( +
+ {childrenConditions} +
+ )} + {!isMobile && icons} +
+
+ ); +}; diff --git a/webapp/src/components/ConditionEditor/ConditionNodeSettings.css b/webapp/src/components/ConditionEditor/ConditionNodeSettings.css new file mode 100644 index 0000000..63e3dd8 --- /dev/null +++ b/webapp/src/components/ConditionEditor/ConditionNodeSettings.css @@ -0,0 +1,18 @@ +.condition-node--settings--icons { + display: inline-block; + max-width: 5em; + max-height: 5em; +} + +.condition-node--settings--wrap { + display: flex; + flex-direction: row; + align-items: center; + justify-content: space-between; + min-width: 5em; + min-height: 5em; +} + +.condition-node--settings button.Mui-disabled { + cursor: not-allowed; +} \ No newline at end of file diff --git a/webapp/src/components/ConditionEditor/ConditionNodeSettings.mobile.css b/webapp/src/components/ConditionEditor/ConditionNodeSettings.mobile.css new file mode 100644 index 0000000..04e190d --- /dev/null +++ b/webapp/src/components/ConditionEditor/ConditionNodeSettings.mobile.css @@ -0,0 +1,19 @@ +.condition-node--settings.mobile { + width: 3em; +} + +.condition-node--settings.mobile .speed-dial--button { + max-width: 4em; + max-height: 4em; + height: 4em; + width: 4em; +} + +.condition-node--settings.mobile .speed-dial--button:hover button { + background-color: var(--secondary-accent); +} + +.condition-node--settings.mobile .speed-dial--list.open { + top: 3.5em; + /* left: 0.5em; */ +} \ No newline at end of file diff --git a/webapp/src/components/ConditionEditor/ConditionNodeSettings.tsx b/webapp/src/components/ConditionEditor/ConditionNodeSettings.tsx new file mode 100644 index 0000000..ba0a0d4 --- /dev/null +++ b/webapp/src/components/ConditionEditor/ConditionNodeSettings.tsx @@ -0,0 +1,101 @@ +import "./ConditionNodeSettings.css"; +import "./ConditionNodeSettings.mobile.css"; + +import { ButtonIcon, ButtonIconProps } from "components/Icons/ButtonIcons"; +import CodeOutlinedIcon from "@mui/icons-material/CodeOutlined"; +import CodeOffOutlinedIcon from "@mui/icons-material/CodeOffOutlined"; +import EditOutlinedIcon from "@mui/icons-material/EditOutlined"; +import SaveIcon from "@mui/icons-material/Save"; +import EditOffIcon from "@mui/icons-material/EditOff"; +import DeleteForeverIcon from "@mui/icons-material/DeleteForever"; +import SettingsApplicationsIcon from "@mui/icons-material/SettingsApplications"; +import useWindowSize from "utils/useWindowSize"; +import { FC } from "react"; +import { SpeedDial } from "components/SpeedDial"; + +export type ConditionNodeSettingsProps = { + mode: ConditionNodeViewMode; + onModeSwitch: (m: ConditionNodeViewMode) => void; + isEdited: boolean; + disableDelete: boolean; + onDelete?: () => void; + onSave: () => void; +}; +export type ConditionNodeViewMode = "edit" | "yaml" | "view"; +export const ConditionNodeSettings: FC = ( + props +) => { + // state + const { isMobile } = useWindowSize(); + + // alias + const showDelete = !props.disableDelete && !!props.onDelete; + const createModeSwitch = (m: ConditionNodeViewMode) => () => { + if (props.mode === m) { + props.onModeSwitch("view"); + } else { + props.onModeSwitch(m); + } + }; + const buttons: Array = [ + { + color: "success", + onClick: createModeSwitch("edit"), + icon: props.mode === "edit" ? : , + }, + { + icon: + props.mode === "yaml" ? : , + onClick: createModeSwitch("yaml"), + color: "info", + }, + { + color: "success", + icon: , + disabled: !props.isEdited, + onClick: props.onSave, + }, + ]; + if (showDelete) { + buttons.push({ + color: "error", + icon: , + onClick: props.onDelete, + }); + } + // render + if (isMobile) { + return ( +
+ } + color={props.isEdited ? "success" : "default"} + /> + } + direction="column" + > + {buttons.map((opt, i) => ( + + ))} + +
+ ); + } else { + return ( +
+
+ {buttons.map((opt, i) => ( + + ))} +
+
+ ); + } +}; diff --git a/webapp/src/components/ConditionEditor/editorRender.tsx b/webapp/src/components/ConditionEditor/editorRender.tsx index 5fda7b0..7a1e045 100644 --- a/webapp/src/components/ConditionEditor/editorRender.tsx +++ b/webapp/src/components/ConditionEditor/editorRender.tsx @@ -13,12 +13,14 @@ import { import InputNumber from "components/Inputs/InputNumber"; import InputText from "components/Inputs/InputText"; import { InputEntity } from "components/Inputs/InputEntities"; -import { ConditionNode } from "./ConditionNode"; +import { ConditionNodeBase } from "./ConditionNodeBase"; import { genUpdateMethods } from "./nestedUpdater"; import { InputTime } from "components/Inputs/InputTime"; import InputYaml from "components/Inputs/InputYaml"; import { HAService } from "haService"; import { DeviceEditor } from "components/DeviceEditor"; +import { ButtonIcon } from "components/Icons/ButtonIcons"; +import AddIcon from "@mui/icons-material/Add"; interface Editor extends FC<{ @@ -171,15 +173,33 @@ export const LogicViewer: Editor = ({ <> {condition.conditions.map((c, i) => { return ( - ); })} +
+ } + onClick={() => + onChange({ + condition: condition.condition, + conditions: [ + ...(condition.conditions ?? []), + { + condition: "device", + device_id: "", + domain: "", + type: "", + }, + ], + }) + } + /> +
); }; diff --git a/webapp/src/components/ConditionEditor/index.stories.tsx b/webapp/src/components/ConditionEditor/index.stories.tsx index cd7fbc2..c26687d 100644 --- a/webapp/src/components/ConditionEditor/index.stories.tsx +++ b/webapp/src/components/ConditionEditor/index.stories.tsx @@ -6,73 +6,114 @@ import { AutomationCondition } from "types/automations/conditions"; import { ConditionEditor } from "."; export default { - title: 'ConditionEditor', + title: "ConditionEditor", component: ConditionEditor, - parameters: { actions: { argTypesRegex: '^on.*' } }, + parameters: { actions: { argTypesRegex: "^on.*" } }, } as ComponentMeta; - -const Template: ComponentStory = ({ condition, ...args }) => { - +const Template: ComponentStory = ({ + condition, + ...args +}) => { const [data, setData] = useState(condition); - return - { - setData(data) - }} - /> - -} + return ( + + { + setData(data); + }} + /> + + ); +}; -export const TemplateViewer = Template.bind({}) +export const TemplateViewer = Template.bind({}); TemplateViewer.args = { condition: { - condition: 'template', - value_template: "states('switch.light_kitchen') == 'on'" + condition: "template", + value_template: "states('switch.light_kitchen') == 'on'", } as AutomationCondition, -} +}; - -export const NumericStateViewer = Template.bind({}) +export const NumericStateViewer = Template.bind({}); NumericStateViewer.args = { condition: { condition: "numeric_state", entity_id: "sensor.humidity_kitchen", above: "10", } as AutomationCondition, -} +}; -export const LogicCondition = Template.bind({}) +export const LogicCondition = Template.bind({}); LogicCondition.args = { condition: { - condition: 'or', + condition: "or", conditions: [ { - condition: 'numeric_state', - entity_id: 'sensor.humidity_kitchen', - above: '60' + condition: "numeric_state", + entity_id: "sensor.humidity_kitchen", + above: "60", }, { - condition: 'numeric_state', - entity_id: 'sensor.humidity_living_room', - above: '60' + condition: "numeric_state", + entity_id: "sensor.humidity_living_room", + above: "60", }, { - condition: 'and', + condition: "and", conditions: [ { - condition: 'numeric_state', - entity_id: 'sensor.humidity_bedroom', - above: '60' + condition: "numeric_state", + entity_id: "sensor.humidity_bedroom", + above: "60", }, { - condition: 'numeric_state', - entity_id: 'sensor.humidity_bathroom', - above: '60' - } - ] + condition: "numeric_state", + entity_id: "sensor.humidity_bathroom", + above: "60", + }, + ], }, - ] + ], } as AutomationCondition, -} +}; + +export const MultipleConditions: ComponentStory = ( + args +) => { + const [state, setState] = useState({ + condition: "or", + conditions: [ + { + condition: "and", + conditions: [ + { + condition: "numeric_state", + entity_id: ["sensor.kitchen_humidity"], + above: "40", + }, + { + condition: "template", + value_template: "states('switch.kitchen') == 'on'", + }, + ], + }, + { + condition: "numeric_state", + entity_id: ["sensor.kitchen_temperature"], + above: "51", + }, + ], + }); + return ( + + {}} + condition={state} + /> + + ); +}; diff --git a/webapp/src/components/ConditionEditor/index.tsx b/webapp/src/components/ConditionEditor/index.tsx index d47752d..c37cf9c 100644 --- a/webapp/src/components/ConditionEditor/index.tsx +++ b/webapp/src/components/ConditionEditor/index.tsx @@ -1,27 +1,21 @@ import { FC } from "react"; import { AutomationCondition } from "types/automations/conditions"; -import { ConditionNode } from "./ConditionNode"; - - - +import { ConditionNodeBase } from "./ConditionNodeBase"; export const ConditionEditor: FC<{ condition: AutomationCondition; - onDelete: (which: 'root' | number) => void; + onDelete: () => void; onUpdate: (data: AutomationCondition) => void; -}> = ({ - condition, - onDelete, - onUpdate, -}) => { - // state - return = ({ condition, onDelete, onUpdate }) => { + // state + return ( + { - onUpdate(update) + onUpdate={(update) => { + onUpdate(update); }} - displayMode - showDelete={false} + disableDelete={true} /> - } + ); +}; diff --git a/webapp/src/components/ConditionEditor/nestedUpdater.ts b/webapp/src/components/ConditionEditor/nestedUpdater.ts index a81c4f4..edf52b9 100644 --- a/webapp/src/components/ConditionEditor/nestedUpdater.ts +++ b/webapp/src/components/ConditionEditor/nestedUpdater.ts @@ -1,28 +1,26 @@ -import { AutomationCondition, LogicCondition } from "types/automations/conditions"; +import { + AutomationCondition, + LogicCondition, +} from "types/automations/conditions"; - -export const genUpdateMethods = ( - condition: LogicCondition, - onChange: (c: LogicCondition) => void -) => (i: number) => ({ - onUpdate: (update: AutomationCondition) => onChange({ +export const genUpdateMethods = + (condition: LogicCondition, onChange: (c: LogicCondition) => void) => + (i: number) => ({ + onUpdate: (update: AutomationCondition) => + onChange({ ...condition, conditions: [ - ...condition.conditions.slice(0, i), - update, - ...condition.conditions.slice(i + 1) - ] - }), - onDelete: (which: 'root' | number) => { - if (which === 'root') { - onChange({ - ...condition, - conditions: condition.conditions.slice(0, i).concat( - condition.conditions.slice(i + 1) - ) - }) - } else { - throw new Error("Not Implemented") - } - } -}) + ...condition.conditions.slice(0, i), + update, + ...condition.conditions.slice(i + 1), + ], + }), + onDelete: () => { + onChange({ + ...condition, + conditions: condition.conditions + .slice(0, i) + .concat(condition.conditions.slice(i + 1)), + }); + }, + }); diff --git a/webapp/src/components/ConditionEditor/style.ts b/webapp/src/components/ConditionEditor/style.ts deleted file mode 100644 index 6ceebde..0000000 --- a/webapp/src/components/ConditionEditor/style.ts +++ /dev/null @@ -1,142 +0,0 @@ -import { Styles } from "jss"; -import { createAppUseStyles } from "styles/theme"; - -export const useStyles = createAppUseStyles<{ - hasChildren: boolean, - isMobile: boolean, -}>(theme => { - const deleteBtn: Styles = { - borderRadius: '10px', - borderStyle: 'none', - padding: '0', - margin: '0', - background: theme.red, - width: '30px', - height: '15px', - fontSize: '10px', - textAlign: 'center', - cursor: 'pointer', - "&:hover": { - background: theme.redAccent, - } - } - return { - root: ({ hasChildren, isMobile }) => ({ - background: theme.primary, - padding: 0, - position: 'relative', - display: 'flex', - flexDirection: isMobile ? 'column' : hasChildren ? 'column' : 'row', - }), - title: ({ hasChildren }) => ({ - display: 'flex', - border: hasChildren ? `1px solid ${theme.primaryAccent}` : 'none', - borderRadius: 10, - borderBottomRightRadius: 0, - borderBottomLeftRadius: 0, - height: '100%', - }), - titleText: ({ hasChildren }) => ({ - background: theme.condition.primaryColor, - border: `1px solid ${theme.primaryAccent}`, - borderRadius: 10, - borderTopRightRadius: 0, - borderBottomRightRadius: 0, - borderBottomLeftRadius: hasChildren ? 0 : 10, - minWidth: '10em', - maxWidth: '30em', - textOverflow: 'ellipsis', - textAlign: 'center', - cursor: 'pointer', - color: theme.primaryAccent, - }), - deleteBtnRoot: { - ...deleteBtn, - position: 'absolute', - left: -35, - top: 10, - }, - modifyBtn: ({ hasChildren }) => ({ - // styling - backgroundColor: theme.green, - color: theme.primary, - fill: theme.primaryAccent, - borderColor: theme.primaryAccent, - borderWidth: 1, - borderRadius: hasChildren ? 10 : 0, - borderTopLeftRadius: 0, - borderBottomLeftRadius: 0, - cursor: 'pointer', - - // positioning - display: 'flex', - justifyContent: 'center', - alignItems: 'center', - padding: '0px 10px', - right: 1, - top: 10, - - // on hover - "&:hover": { - backgroundColor: theme.greenLight, - fill: theme.primaryAccentLight, - }, - "&:hover $icon": { - transform: "rotate(90deg)" - } - }), - icon: {}, - deleteBtn, - conditionWrap: { - overflow: 'auto', - }, - children: ({ hasChildren }) => ({ - flex: 1, - paddingLeft: hasChildren ? 50 : 10, - paddingRight: hasChildren ? 0 : 10, - display: 'flex', - flexDirection: 'column', - justifyContent: 'center', - border: `1px solid ${theme.secondaryAccent}`, - borderBottomRightRadius: hasChildren ? 10 : 0, - borderBottomLeftRadius: hasChildren ? 10 : 0, - minHeight: hasChildren ? undefined : '100%', - overflow: 'scroll' - }), - addBtnContainer: { - display: 'flex', - justifyContent: 'center', - }, - yamlBtn: { - backgroundColor: theme.secondary, - borderWidth: 1, - borderStyle: 'solid', - borderColor: theme.secondaryAccent, - color: theme.secondaryAccent, - paddingLeft: 20, - paddingRight: 20, - cursor: 'pointer', - "&:hover": { - backgroundColor: theme.primaryLight, - fill: theme.primaryAccentLight, - }, - }, - addBtn: { - backgroundColor: theme.secondary, - borderWidth: 1, - borderStyle: 'solid', - borderColor: theme.secondaryAccent, - color: theme.secondaryAccent, - borderRadius: 5, - marginTop: 5, - marginBottom: 5, - paddingLeft: 20, - paddingRight: 20, - cursor: 'pointer', - "&:hover": { - backgroundColor: theme.primaryLight, - fill: theme.primaryAccentLight, - }, - } - } -}) diff --git a/webapp/src/components/ConditionEditor/viewRender.tsx b/webapp/src/components/ConditionEditor/viewRender.tsx index 3c9a17d..57ae2ef 100644 --- a/webapp/src/components/ConditionEditor/viewRender.tsx +++ b/webapp/src/components/ConditionEditor/viewRender.tsx @@ -4,7 +4,7 @@ import { LogicCondition, } from "types/automations/conditions"; import { getDescriptionFromAutomationNode, Namer } from "utils/formatting"; -import { ConditionNode } from "./ConditionNode"; +import { ConditionNodeBase } from "./ConditionNodeBase"; import { genUpdateMethods } from "./nestedUpdater"; interface Viewer @@ -40,10 +40,10 @@ export const LogicViewer: Viewer = ({ <> {condition.conditions.map((c, i) => { return ( - ); diff --git a/webapp/src/components/Icons/ButtonIcons.tsx b/webapp/src/components/Icons/ButtonIcons.tsx index 4f3cf45..193b708 100644 --- a/webapp/src/components/Icons/ButtonIcons.tsx +++ b/webapp/src/components/Icons/ButtonIcons.tsx @@ -2,14 +2,15 @@ import "./ButtonIcons.css"; import { FC, ReactNode } from "react"; import MuiIconButton, { IconButtonTypeMap } from "@mui/material/IconButton"; -export const ButtonIcon: FC<{ +export type ButtonIconProps = { icon: ReactNode; onClick?: () => void; className?: string; title?: string; disabled?: boolean; color?: IconButtonTypeMap["props"]["color"]; -}> = (props) => { +}; +export const ButtonIcon: FC = (props) => { return ( + {/* */} {children} diff --git a/webapp/src/components/SpeedDial/index.css b/webapp/src/components/SpeedDial/index.css index 3a38991..db7de7a 100644 --- a/webapp/src/components/SpeedDial/index.css +++ b/webapp/src/components/SpeedDial/index.css @@ -24,9 +24,21 @@ bottom: -3em; left: 0em; background: var(--secondary); + z-index: 10; + height: fit-content; + padding: 0.1em; + border-radius: 10px; } .speed-dial--list.open.row { display: flex; flex-direction: row; +} + +.speed-dial--list.open.column { + display: flex; + top: 2em; + flex-direction: column; + gap: 0.25em; + left: 0.25em; } \ No newline at end of file