From 93fe26e787fe620e155692d7138e849cd02865de Mon Sep 17 00:00:00 2001 From: Ari Date: Wed, 13 Apr 2022 16:20:12 -0400 Subject: [PATCH 1/6] proper zoom level --- .../src/components/AutomationEditor/index.tsx | 11 +++++++++- .../src/components/AutomationEditor/styles.ts | 13 +++++++++--- webapp/src/components/DAGSvgs/Board.tsx | 9 +++++---- .../components/DAGSvgs/DAGBoard.stories.tsx | 2 +- webapp/src/components/Inputs/InputNumber.tsx | 20 +++++++++++++++++-- .../SequenceNodes/index.stories.tsx | 2 +- 6 files changed, 45 insertions(+), 12 deletions(-) diff --git a/webapp/src/components/AutomationEditor/index.tsx b/webapp/src/components/AutomationEditor/index.tsx index 8ad09c6..c8d4510 100644 --- a/webapp/src/components/AutomationEditor/index.tsx +++ b/webapp/src/components/AutomationEditor/index.tsx @@ -13,6 +13,7 @@ import { AutomationTrigger } from 'types/automations/triggers'; import { Modal } from "components/Modal"; import { NodeEditor } from "components/NodeEditor"; import { ButtonIcon } from "components/Icons/ButtonIcons"; +import InputNumber from "components/Inputs/InputNumber"; interface TriggerEditorModalState { trigger: AutomationTrigger; @@ -29,6 +30,7 @@ export const AutomationEditor: FC = ({ onUpdate, }) => { // state + const [zoomLevel, setZoomLevel] = useState(40); const { ratioWbh } = useWindowSize(); const [closeInfo, setCloseInfo] = useState(false); const [modalState, setModalState] = useState(null); @@ -49,6 +51,13 @@ export const AutomationEditor: FC = ({ // render return
+ setZoomLevel(z ?? 40)} + /> {!!modalState && = ({ (theme => ({ - root: ({horizontalMode}) => ({ + root: ({ horizontalMode }) => ({ height: '100%', width: '100%', color: theme.primaryAccent, @@ -18,7 +18,14 @@ export const useEditorStyles = createAppUseStyles<{ borderColor: theme.secondaryAccent, width: '100%', }, - infoIcon: ({horizontalMode}) => ({ + infoIcon: ({ horizontalMode }) => ({ bottom: horizontalMode ? '90%' : 10 - }) + }), + zoom: { + position: 'absolute !important', + right: 0, + bottom: 0, + width: "100%", + // maxWidth: "10em", + } })) diff --git a/webapp/src/components/DAGSvgs/Board.tsx b/webapp/src/components/DAGSvgs/Board.tsx index e7037dd..267239c 100644 --- a/webapp/src/components/DAGSvgs/Board.tsx +++ b/webapp/src/components/DAGSvgs/Board.tsx @@ -16,25 +16,26 @@ export const SVGBoard: FC<{ minGraphWidth = 300, nodeHeight = NODE_HEIGHT, nodeWidth = NODE_WIDTH, - zoomLevel = 1, + zoomLevel = 100, }) => { // state const { ratioWbh } = useWindowSize(); // alias + const paddedZoomLevel = zoomLevel / 100; const graphWidth = Math.max( Math.round(graphHeight * ratioWbh), minGraphWidth ); const { classes, theme } = useBoardStyles({ - boardHeight: Math.max(nodeHeight, graphHeight) * zoomLevel, - boardWidth: Math.max(4 * nodeWidth, graphWidth) * zoomLevel, + boardHeight: Math.max(nodeHeight, graphHeight) * paddedZoomLevel, + boardWidth: Math.max(4 * nodeWidth, graphWidth) * paddedZoomLevel, }); // render return
diff --git a/webapp/src/components/DAGSvgs/DAGBoard.stories.tsx b/webapp/src/components/DAGSvgs/DAGBoard.stories.tsx index 97735ac..189e01f 100644 --- a/webapp/src/components/DAGSvgs/DAGBoard.stories.tsx +++ b/webapp/src/components/DAGSvgs/DAGBoard.stories.tsx @@ -10,7 +10,7 @@ export default { component: DAGBoard, parameters: { actions: { argTypesRegex: '^on.*' } }, args: { - zoomLevel: 1, + zoomLevel: 100, settings: { nodeHeight: NODE_HEIGHT, nodeWidth: NODE_WIDTH, diff --git a/webapp/src/components/Inputs/InputNumber.tsx b/webapp/src/components/Inputs/InputNumber.tsx index 1b88ff4..5cc8c45 100644 --- a/webapp/src/components/Inputs/InputNumber.tsx +++ b/webapp/src/components/Inputs/InputNumber.tsx @@ -6,22 +6,38 @@ export interface Props { label: string; value: number | undefined; onChange: (v: number | undefined) => void; + className?: string; + min?: number, + max?: number, + step?: number, } export default function InputNumber({ label, value = undefined, onChange, + className = "", + min, max, step, }: Props) { const { classes } = useInputNumberStyles({}); - return + return diff --git a/webapp/src/components/SequenceNodes/index.stories.tsx b/webapp/src/components/SequenceNodes/index.stories.tsx index f121268..e974cdf 100644 --- a/webapp/src/components/SequenceNodes/index.stories.tsx +++ b/webapp/src/components/SequenceNodes/index.stories.tsx @@ -11,7 +11,7 @@ export default { component: SequenceNodes, parameters: { actions: { argTypesRegex: '^on.*' } }, args: { - zoomLevel: 1.5, + zoomLevel: 100, startPoint: [0.5, 0.5], dims: { nodeHeight: NODE_HEIGHT, From 967508c29e928664c0875aeea78d459fd9a3c99c Mon Sep 17 00:00:00 2001 From: Ari Date: Wed, 13 Apr 2022 16:53:04 -0400 Subject: [PATCH 2/6] added zoomability --- .../src/components/AutomationEditor/index.tsx | 88 ++++++++++--------- .../src/components/AutomationEditor/styles.ts | 26 +++++- webapp/src/components/Icons/index.stories.tsx | 4 +- webapp/src/components/Icons/index.tsx | 13 ++- webapp/src/components/Inputs/styles.ts | 4 +- 5 files changed, 84 insertions(+), 51 deletions(-) diff --git a/webapp/src/components/AutomationEditor/index.tsx b/webapp/src/components/AutomationEditor/index.tsx index c8d4510..bde36ee 100644 --- a/webapp/src/components/AutomationEditor/index.tsx +++ b/webapp/src/components/AutomationEditor/index.tsx @@ -1,6 +1,6 @@ import "./index.css"; import { DAGBoardElmDims } from "components/DAGSvgs/DAGBoard"; -import { ArrowIcon } from "components/Icons"; +import { ArrowIcon, ZoomIcon } from "components/Icons"; import { SequenceNodes } from "components/SequenceNodes"; import { FC, useState } from "react"; import { AutomationData, AutomationSequenceNode } from "types/automations"; @@ -13,7 +13,6 @@ import { AutomationTrigger } from 'types/automations/triggers'; import { Modal } from "components/Modal"; import { NodeEditor } from "components/NodeEditor"; import { ButtonIcon } from "components/Icons/ButtonIcons"; -import InputNumber from "components/Inputs/InputNumber"; interface TriggerEditorModalState { trigger: AutomationTrigger; @@ -51,13 +50,6 @@ export const AutomationEditor: FC = ({ // render return
- setZoomLevel(z ?? 40)} - /> {!!modalState && = ({ >{ArrowIcon} - chain([ - computeExtraField([1, 0.5], [2, 0.5]), - computeTriggerPos( - [0.5, 0.5], - automation.trigger, - [1.5, 0.5], - updateTriggers, - () => { - setModalState({ - trigger: { - $smType: "trigger", - platform: "device", - device_id: "", - domain: "", - type: "", - subtype: "" - }, - onSave: (t) => updateTriggers([...automation.trigger, t]) - }); - }, - (trigger, onSave) => setModalState({ - trigger, - onSave, - }) - ), - ])} - /> +
+
+ + setZoomLevel(z.target.valueAsNumber ?? 40)} + /> +
+ chain([ + computeExtraField([1, 0.5], [2, 0.5]), + computeTriggerPos( + [0.5, 0.5], + automation.trigger, + [1.5, 0.5], + updateTriggers, + () => { + setModalState({ + trigger: { + $smType: "trigger", + platform: "device", + device_id: "", + domain: "", + type: "", + subtype: "" + }, + onSave: (t) => updateTriggers([...automation.trigger, t]) + }); + }, + (trigger, onSave) => setModalState({ + trigger, + onSave, + }) + ), + ])} + /> +
} diff --git a/webapp/src/components/AutomationEditor/styles.ts b/webapp/src/components/AutomationEditor/styles.ts index 4cffbbf..33bcdb3 100644 --- a/webapp/src/components/AutomationEditor/styles.ts +++ b/webapp/src/components/AutomationEditor/styles.ts @@ -5,6 +5,14 @@ export const useEditorStyles = createAppUseStyles<{ closeInfo: boolean; horizontalMode: boolean; }>(theme => ({ + wrapper: { + display: 'flex', + flexDirection: 'column', + alignItems: "flex-end", + height: '100%', + width: '100%', + overflow: 'hidden', + }, root: ({ horizontalMode }) => ({ height: '100%', width: '100%', @@ -22,10 +30,20 @@ export const useEditorStyles = createAppUseStyles<{ bottom: horizontalMode ? '90%' : 10 }), zoom: { - position: 'absolute !important', - right: 0, - bottom: 0, + backgroundColor: theme.secondary, + color: theme.secondaryAccent, + textAlign: 'center', + maxWidth: "3em", + }, + zoomImg: { + // width: "1em", + + }, + toolbar: { width: "100%", - // maxWidth: "10em", + display: "flex", + flexDirection: "row", + justifyContent: 'start', + alignItems: "center", } })) diff --git a/webapp/src/components/Icons/index.stories.tsx b/webapp/src/components/Icons/index.stories.tsx index acb14e1..e0197ec 100644 --- a/webapp/src/components/Icons/index.stories.tsx +++ b/webapp/src/components/Icons/index.stories.tsx @@ -1,8 +1,7 @@ import { ComponentStory } from "@storybook/react"; import { IconBase } from "./base"; -import { PencilIcon, CheckMarkIcon, TrashIcon, InfoIcon, ArrowIcon } from "."; -import { AddIcon } from './index'; +import { PencilIcon, CheckMarkIcon, TrashIcon, InfoIcon, ArrowIcon, AddIcon, ZoomIcon } from "."; import { ButtonIcon } from "./ButtonIcons"; export default { @@ -19,6 +18,7 @@ export const IconList: ComponentStory = (args) => { +
} IconList.args = { diff --git a/webapp/src/components/Icons/index.tsx b/webapp/src/components/Icons/index.tsx index 22ed499..ef08526 100644 --- a/webapp/src/components/Icons/index.tsx +++ b/webapp/src/components/Icons/index.tsx @@ -1,5 +1,5 @@ import { FC } from "react"; -import { IconBase, IconBaseProps } from "./base"; +import { IconBase, IconBaseProps } from './base'; export const PencilIcon: FC = props => = props => + + +export const ZoomIcon: FC = props => + + \ No newline at end of file diff --git a/webapp/src/components/Inputs/styles.ts b/webapp/src/components/Inputs/styles.ts index 53ba6a9..4ec4967 100644 --- a/webapp/src/components/Inputs/styles.ts +++ b/webapp/src/components/Inputs/styles.ts @@ -97,8 +97,8 @@ export const useInputNumberStyles = createAppUseStyles<{}>(theme => { }, deleteIcon: { position: "absolute", - left: 30, - top: 17, + left: "1em", + top: "1.5em", color: theme.secondaryAccent, backgroundColor: theme.secondary, borderWidth: 1, From 77c338eb90c31cb1528e1d53a21009b71015ca79 Mon Sep 17 00:00:00 2001 From: Ari Date: Wed, 13 Apr 2022 16:54:37 -0400 Subject: [PATCH 3/6] v0.0.10 --- CHANGELOG.md | 12 ++++++++---- config.yaml | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d932816..2b00be1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,14 @@ # Changelog -All notable changes to this project will be documented in this file. -The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), -and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.0.10] - Zoom + +- Introducing Zoom! ## [0.0.9] - First Working Version - Instalable verion via github -- Initial POC done \ No newline at end of file +- Initial POC done + + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). diff --git a/config.yaml b/config.yaml index b77ada8..4cb489b 100644 --- a/config.yaml +++ b/config.yaml @@ -1,5 +1,5 @@ name: Shortumation -version: 0.0.9 +version: 0.0.10 slug: shortumation url: "https://github.com/asosnovsky/Shortumation" description: "A homeassitant addon which provides better UI for automations & scripts." From fedc6c889a4acbd873bdcc119777416d8ad5b2f2 Mon Sep 17 00:00:00 2001 From: Ari Date: Wed, 13 Apr 2022 22:06:38 -0400 Subject: [PATCH 4/6] added lazy saving --- .../AutomationEditor/index.stories.tsx | 4 +- .../src/components/AutomationEditor/index.tsx | 48 ++++++++++++++----- .../src/components/AutomationEditor/styles.ts | 10 +++- webapp/src/components/Inputs/styles.ts | 4 +- 4 files changed, 49 insertions(+), 17 deletions(-) diff --git a/webapp/src/components/AutomationEditor/index.stories.tsx b/webapp/src/components/AutomationEditor/index.stories.tsx index 659a0c1..e36363d 100644 --- a/webapp/src/components/AutomationEditor/index.stories.tsx +++ b/webapp/src/components/AutomationEditor/index.stories.tsx @@ -27,7 +27,9 @@ const Template: ComponentStory = args => { { + window.setTimeout(() => setState(s), 3000) + }} />
} diff --git a/webapp/src/components/AutomationEditor/index.tsx b/webapp/src/components/AutomationEditor/index.tsx index bde36ee..ba31e98 100644 --- a/webapp/src/components/AutomationEditor/index.tsx +++ b/webapp/src/components/AutomationEditor/index.tsx @@ -1,8 +1,8 @@ import "./index.css"; import { DAGBoardElmDims } from "components/DAGSvgs/DAGBoard"; -import { ArrowIcon, ZoomIcon } from "components/Icons"; +import { ArrowIcon, CheckMarkIcon, ZoomIcon } from "components/Icons"; import { SequenceNodes } from "components/SequenceNodes"; -import { FC, useState } from "react"; +import { FC, useEffect, useState } from "react"; import { AutomationData, AutomationSequenceNode } from "types/automations"; import useWindowSize from "utils/useWindowSize"; import { AutoInfoBox } from "./AutoInfoBox"; @@ -13,6 +13,7 @@ import { AutomationTrigger } from 'types/automations/triggers'; import { Modal } from "components/Modal"; import { NodeEditor } from "components/NodeEditor"; import { ButtonIcon } from "components/Icons/ButtonIcons"; +import { Button } from "components/Inputs/Button"; interface TriggerEditorModalState { trigger: AutomationTrigger; @@ -25,10 +26,13 @@ interface Props { } export const AutomationEditor: FC = ({ dims, - automation, - onUpdate, + automation: propsAutos, + onUpdate: propsOnUpdate, }) => { // state + const [[autoChanged, automation], setAutomation] = useState<[ + 'unchanged' | 'changed' | 'loading', AutomationData] + >(['unchanged', propsAutos]); const [zoomLevel, setZoomLevel] = useState(40); const { ratioWbh } = useWindowSize(); const [closeInfo, setCloseInfo] = useState(false); @@ -47,6 +51,12 @@ export const AutomationEditor: FC = ({ ...automation, trigger, }); + const onUpdate = (a: AutomationData) => setAutomation(['changed', a]); + + // effects + useEffect(() => { + setAutomation(['unchanged', propsAutos]); + }, [propsAutos]) // render return
@@ -75,14 +85,28 @@ export const AutomationEditor: FC = ({
- - setZoomLevel(z.target.valueAsNumber ?? 40)} - /> +
+ + setZoomLevel(z.target.valueAsNumber ?? 40)} + /> +
+ {autoChanged !== 'unchanged' && }
({ export const useButtonStyles = createAppUseStyles<{}>(theme => ({ input: { ...commonInputStyle(theme).input, - paddingTop: '2%', - paddingBottom: '2%', + paddingTop: '1em', + paddingBottom: '1em', cursor: 'pointer', }, })); From 95af6392ba01281be87256c0f3151ce7ed0c0fda Mon Sep 17 00:00:00 2001 From: Ari Date: Wed, 13 Apr 2022 22:14:24 -0400 Subject: [PATCH 5/6] fixed styling --- webapp/src/components/AutomationList/styles.css | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/webapp/src/components/AutomationList/styles.css b/webapp/src/components/AutomationList/styles.css index e72f1af..35c63f4 100644 --- a/webapp/src/components/AutomationList/styles.css +++ b/webapp/src/components/AutomationList/styles.css @@ -15,9 +15,7 @@ } .automation-list--viewer { - /* flex: 6; */ - min-width: 100%; - max-width: 100%; + overflow: hidden; } /* list children: on hide */ From d250018c9af27afe0e2a3238b829143e187c8177 Mon Sep 17 00:00:00 2001 From: Ari Date: Wed, 13 Apr 2022 22:15:03 -0400 Subject: [PATCH 6/6] v0.0.11 --- CHANGELOG.md | 4 ++++ config.yaml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b00be1..b44a8f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## [0.0.11] - Zoom + +- Added lazy saving + ## [0.0.10] - Zoom - Introducing Zoom! diff --git a/config.yaml b/config.yaml index 4cb489b..4a01809 100644 --- a/config.yaml +++ b/config.yaml @@ -1,5 +1,5 @@ name: Shortumation -version: 0.0.10 +version: 0.0.11 slug: shortumation url: "https://github.com/asosnovsky/Shortumation" description: "A homeassitant addon which provides better UI for automations & scripts."