clean up styling

This commit is contained in:
ari committed 2021-12-25 17:06:49 -05:00
1 parent 0aff219645
commit 9d8cc9ed3e
14 files changed
+144 -68

No files matched your search

@@ -101,3 +101,23 @@ Simple.args = {
] ]
} }
} }
export const EmptyStart = Template.bind({})
EmptyStart.args = {
...EmptyStart.args,
automation: {
metadata: {
id: "random",
alias: "Random",
description: "Example Metadata",
trigger_variables: {
'wowo': '!'
},
mode: 'single',
},
trigger: [
],
sequence: []
}
}
@@ -82,6 +82,19 @@ export const AutomationEditor: FC<Props> = ({
automation.trigger, automation.trigger,
[1.5, 0.5], [1.5, 0.5],
updateTriggers, updateTriggers,
() => {
setModalState({
trigger: {
$smType: "trigger",
platform: "device",
device_id: "",
domain: "",
type: "",
subtype: ""
},
onSave: (t) => updateTriggers([...automation.trigger, t])
});
},
(trigger, onSave) => setModalState({ (trigger, onSave) => setModalState({
trigger, trigger,
onSave, onSave,
@@ -9,6 +9,7 @@ export function* computeTriggerPos(
triggers: AutomationTrigger[], triggers: AutomationTrigger[],
toPath: Point, toPath: Point,
onUpdate: (ts: AutomationTrigger[]) => void, onUpdate: (ts: AutomationTrigger[]) => void,
onAdd: () => void,
onEdit: (nt: AutomationTrigger, onSave: (ts: AutomationTrigger) => void) => void, onEdit: (nt: AutomationTrigger, onSave: (ts: AutomationTrigger) => void) => void,
): Generator<DAGElement> { ): Generator<DAGElement> {
// functions // functions
@@ -40,15 +41,21 @@ export function* computeTriggerPos(
direction: "1->2", direction: "1->2",
} }
} }
// if we had nothing to loop on
if (triggers.length === 0) {
yield {
type: "edge",
p1: [startPoint[0] - 0.25, startPoint[1] + triggers.length],
p2: toPath,
direction: "1->2",
}
}
// add circle
yield { yield {
type: 'circle', type: 'circle',
icon: 'add', icon: 'add',
loc: [startPoint[0] + 0.25, startPoint[1] + triggers.length], loc: [startPoint[0] + 0.25, startPoint[1] + triggers.length],
onAdd: () => onUpdate(triggers.concat({ onAdd
$smType: 'trigger',
platform: 'state',
entity_id: "",
}))
} }
} }
@@ -40,7 +40,7 @@
.automation-list--list-hide { .automation-list--list-hide {
position: absolute; position: absolute;
top : 0; bottom : 10px;
right : 5px; right : 5px;
} }
+5 -3
View File
@@ -31,9 +31,9 @@ const useModalStyle = createAppUseStyles<ModalStyleProps>(theme => ({
inner: { inner: {
zIndex: 10, zIndex: 10,
maxWidth: '80%', maxWidth: '80%',
maxHeight: '60%', maxHeight: '90%',
minHeight: '200px', minHeight: 'fit-content',
minWidth: '200px', minWidth: 'fit-content',
padding: '15px', padding: '15px',
display: 'flex', display: 'flex',
flexDirection: 'column', flexDirection: 'column',
@@ -43,6 +43,8 @@ const useModalStyle = createAppUseStyles<ModalStyleProps>(theme => ({
borderColor: theme.primaryAccent, borderColor: theme.primaryAccent,
borderRadius: '10px', borderRadius: '10px',
color: theme.primaryAccent, color: theme.primaryAccent,
overflow: "auto",
resize: "auto",
} }
})); }));
export const Modal: FC<Props> = ({ export const Modal: FC<Props> = ({
@@ -25,7 +25,7 @@ export const ActionChooseState: OptionManager<ChooseAction> = {
value={state.action_data.alias ?? ""} value={state.action_data.alias ?? ""}
onChange={alias => update({ alias })} onChange={alias => update({ alias })}
/> />
<InputYaml {/* <InputYaml
label="Choose Sequence" label="Choose Sequence"
value={state.action_data.choose} value={state.action_data.choose}
onChange={choose => update({ choose })} onChange={choose => update({ choose })}
@@ -36,7 +36,7 @@ export const ActionChooseState: OptionManager<ChooseAction> = {
value={state.action_data.default} value={state.action_data.default}
onChange={d => update({ default: d })} onChange={d => update({ default: d })}
resizable resizable
/> /> */}
</> </>
} }
} }
@@ -0,0 +1,37 @@
.node-editor--root {
display : flex;
flex-direction : column;
justify-content: center;
align-items : center;
height : 100%;
}
.node-editor--body-title {
display : flex;
flex-direction : row;
justify-content: space-between;
}
.node-editor--body {
flex : 1;
overflow : overlay;
width : 100%;
min-width : fit-content;
padding-left : 1%;
padding-right: 1%;
/* resize : auto;
min-width : fit-content;
max-height : 100%;
min-height : fit-content; */
}
.node-editor--footer {
bottom : 0;
left : 0;
display : flex;
flex-direction : row;
justify-content: space-between;
align-items : center;
width : 100%;
min-height : 50px;
}
+9 -12
View File
@@ -1,19 +1,17 @@
import "./index.css";
import { FC } from "react"; import { FC } from "react";
import { useNodeEditorStyles } from "./styles";
import { AutomationNode, AutomationNodeMapping } from 'types/automations/index'; import { AutomationNode, AutomationNodeMapping } from 'types/automations/index';
import { useEditorNodeState } from "./OptionManager"; import { useEditorNodeState } from "./OptionManager";
import InputList from "components/Inputs/InputList"; import InputList from "components/Inputs/InputList";
import { Button } from "components/Inputs/Button"; import { Button } from "components/Inputs/Button";
export interface Props { export interface Props {
node: AutomationNode node: AutomationNode
allowedTypes?: Array<keyof AutomationNodeMapping>; allowedTypes?: Array<keyof AutomationNodeMapping>;
onClose?: () => void; onClose?: () => void;
onSave?: (n: AutomationNode) => void; onSave?: (n: AutomationNode) => void;
saveBtnCreateText?: boolean;
} }
export const NodeEditor: FC<Props> = ({ export const NodeEditor: FC<Props> = ({
@@ -21,15 +19,13 @@ export const NodeEditor: FC<Props> = ({
allowedTypes = ["action", "condition", "trigger"], allowedTypes = ["action", "condition", "trigger"],
onClose = () => { }, onClose = () => { },
onSave = () => { }, onSave = () => { },
saveBtnCreateText = false,
}) => { }) => {
const { classes } = useNodeEditorStyles({});
const state = useEditorNodeState(node); const state = useEditorNodeState(node);
return <div className={classes.root}> return <div className="node-editor--root">
<div className={classes.title}> <div className="node-editor--body">
<div className="node-editor--body-title">
</div>
<div className={classes.body}>
{allowedTypes.length > 1 ? <InputList {allowedTypes.length > 1 ? <InputList
label="Type" label="Type"
current={state.nodeType} current={state.nodeType}
@@ -42,13 +38,14 @@ export const NodeEditor: FC<Props> = ({
options={state.subTypes} options={state.subTypes}
onChange={state.setSubType} onChange={state.setSubType}
/> : <></>} /> : <></>}
</div>
{state.renderOptionList()} {state.renderOptionList()}
</div> </div>
<div className={classes.footer}> <div className="node-editor--footer">
<Button onClick={onClose}>Close</Button> <Button onClick={onClose}>Close</Button>
<Button onClick={() => { <Button onClick={() => {
state.isReady() && onSave(state.data) state.isReady() && onSave(state.data)
}} disabled={!state.isReady()}>Save</Button> }} disabled={!state.isReady()}>{saveBtnCreateText ? "Create" : "Save"}</Button>
</div> </div>
</div> </div>
} }
@@ -1,31 +0,0 @@
import Color from "chroma-js";
import { createAppUseStyles } from "styles/theme";
export const useNodeEditorStyles = createAppUseStyles<{
}>(theme => ({
root: {
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
},
title: {
textAlign: 'center',
padding: 10,
fontWeight: 'bold',
color: theme.secondaryAccent,
},
body: {
overflow: 'auto',
resize: 'auto',
flexGrow: 1
},
footer: {
display: 'flex',
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
width: '100%',
}
}))
@@ -78,6 +78,13 @@ Simple.args = {
] ]
} }
export const EmptyStart = Template.bind({})
EmptyStart.args = {
...EmptyStart.args,
sequence: [
]
}
export const AdditionalElemets = Template.bind({}) export const AdditionalElemets = Template.bind({})
AdditionalElemets.args = { AdditionalElemets.args = {
@@ -23,6 +23,7 @@ export const SequenceNodes: FC<SequenceNodeProps & { zoomLevel: number }> = (pro
onClose={() => setModalState(null)} onClose={() => setModalState(null)}
onSave={n => { modalState.update(n as any); setModalState(null) }} onSave={n => { modalState.update(n as any); setModalState(null) }}
allowedTypes={modalState.onlyConditions ? ['condition'] : ['action', 'condition']} allowedTypes={modalState.onlyConditions ? ['condition'] : ['action', 'condition']}
saveBtnCreateText={modalState.saveBtnCreateText}
/> />
} else { } else {
modalBody = <MultiNodeEditor modalBody = <MultiNodeEditor
@@ -4,12 +4,9 @@ import { Point } from "types/graphs";
import { makeUpdater, Updater } from './updater'; import { makeUpdater, Updater } from './updater';
import { ChooseAction } from 'types/automations/actions'; import { ChooseAction } from 'types/automations/actions';
import { AutomationCondition } from "types/automations/conditions"; import { AutomationCondition } from "types/automations/conditions";
import { ModalState } from "./types"; import { UpdateModalState } from "./types";
import { offsetPoint, makeOffsetMaintainer} from "utils/graph"; import { offsetPoint, makeOffsetMaintainer} from "utils/graph";
export type UpdateModalState = (
s: ModalState
) => void;
@@ -146,8 +143,19 @@ export function* computeNodesEdgesPos(
onChange: (s: AutomationSequenceNode[]) => void, onChange: (s: AutomationSequenceNode[]) => void,
openModal: UpdateModalState, openModal: UpdateModalState,
): Generator<DAGElement> { ): Generator<DAGElement> {
const rootUpdater = makeUpdater(sequence, onChange); const rootUpdater = makeUpdater(sequence, onChange, openModal);
const offset = makeOffsetMaintainer(startPoint) const offset = makeOffsetMaintainer(startPoint);
if (sequence.length === 0) {
yield {
type: "circle",
icon: 'add',
loc: offsetPoint(startPoint, [offset.x, 0]),
onAdd: rootUpdater.addNode,
}
return
}
let lastNodeLoc: Point | null = null; let lastNodeLoc: Point | null = null;
for (let i = 0; i < sequence.length; i++) { for (let i = 0; i < sequence.length; i++) {
offset.setI(i) offset.setI(i)
@@ -2,6 +2,10 @@ import { DAGBoardElmDims, DAGElement } from "components/DAGSvgs/DAGBoard";
import { AutomationSequenceNode } from "types/automations"; import { AutomationSequenceNode } from "types/automations";
import { Point } from "types/graphs"; import { Point } from "types/graphs";
export type UpdateModalState = (
s: ModalState
) => void;
export interface SequenceNodeProps { export interface SequenceNodeProps {
startPoint: Point; startPoint: Point;
dims: DAGBoardElmDims; dims: DAGBoardElmDims;
@@ -14,6 +18,7 @@ export type ModalState = {
single: true, single: true,
node: AutomationSequenceNode node: AutomationSequenceNode
update: (n: AutomationSequenceNode) => void; update: (n: AutomationSequenceNode) => void;
saveBtnCreateText?: boolean;
onlyConditions: boolean; onlyConditions: boolean;
} | { } | {
single: false, single: false,
+18 -8
View File
@@ -1,11 +1,13 @@
import { AutomationSequenceNode } from "types/automations"; import { AutomationSequenceNode } from "types/automations";
import { ChooseAction } from "types/automations/actions"; import { ChooseAction } from "types/automations/actions";
import { UpdateModalState } from "./types";
export type Updater = ReturnType<typeof makeUpdater>; export type Updater = ReturnType<typeof makeUpdater>;
export const makeUpdater = ( export const makeUpdater = (
sequence: AutomationSequenceNode[], sequence: AutomationSequenceNode[],
onChange: (s: AutomationSequenceNode[]) => void onChange: (s: AutomationSequenceNode[]) => void,
openModal: UpdateModalState,
) => ({ ) => ({
sequence, sequence,
onChange, onChange,
@@ -16,17 +18,23 @@ export const makeUpdater = (
]) ])
}, },
addNode() { addNode() {
return onChange([ return openModal({
...sequence, single: true,
{ saveBtnCreateText: true,
node: {
$smType: 'action', $smType: 'action',
action: 'choose', action: 'choose',
action_data: { action_data: {
choose: [], choose: [],
default: [], default: [],
} }
} },
]) update: n => onChange([
...sequence,
n,
]),
onlyConditions: false,
})
}, },
updateNode(i: number, node: AutomationSequenceNode) { updateNode(i: number, node: AutomationSequenceNode) {
return onChange([ return onChange([
@@ -61,7 +69,8 @@ export const makeUpdater = (
...node.action_data.choose.slice(j+1), ...node.action_data.choose.slice(j+1),
] ]
} }
}) }),
openModal,
) )
} else { } else {
return makeUpdater( return makeUpdater(
@@ -72,7 +81,8 @@ export const makeUpdater = (
...node.action_data, ...node.action_data,
default: seq default: seq
} }
}) }),
openModal,
) )
} }
} }