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
+156 -80

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,
[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,
@@ -9,6 +9,7 @@ export function* computeTriggerPos(
triggers: AutomationTrigger[],
toPath: Point,
onUpdate: (ts: AutomationTrigger[]) => void,
onAdd: () => void,
onEdit: (nt: AutomationTrigger, onSave: (ts: AutomationTrigger) => void) => void,
): Generator<DAGElement> {
// functions
@@ -40,15 +41,21 @@ export function* computeTriggerPos(
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 {
type: 'circle',
icon: 'add',
loc: [startPoint[0] + 0.25, startPoint[1] + triggers.length],
onAdd: () => onUpdate(triggers.concat({
$smType: 'trigger',
platform: 'state',
entity_id: "",
}))
onAdd
}
}
@@ -40,7 +40,7 @@
.automation-list--list-hide {
position: absolute;
top : 0;
bottom : 10px;
right : 5px;
}
+5 -3
View File
@@ -31,9 +31,9 @@ const useModalStyle = createAppUseStyles<ModalStyleProps>(theme => ({
inner: {
zIndex: 10,
maxWidth: '80%',
maxHeight: '60%',
minHeight: '200px',
minWidth: '200px',
maxHeight: '90%',
minHeight: 'fit-content',
minWidth: 'fit-content',
padding: '15px',
display: 'flex',
flexDirection: 'column',
@@ -43,6 +43,8 @@ const useModalStyle = createAppUseStyles<ModalStyleProps>(theme => ({
borderColor: theme.primaryAccent,
borderRadius: '10px',
color: theme.primaryAccent,
overflow: "auto",
resize: "auto",
}
}));
export const Modal: FC<Props> = ({
@@ -25,7 +25,7 @@ export const ActionChooseState: OptionManager<ChooseAction> = {
value={state.action_data.alias ?? ""}
onChange={alias => update({ alias })}
/>
<InputYaml
{/* <InputYaml
label="Choose Sequence"
value={state.action_data.choose}
onChange={choose => update({ choose })}
@@ -36,7 +36,7 @@ export const ActionChooseState: OptionManager<ChooseAction> = {
value={state.action_data.default}
onChange={d => update({ default: d })}
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;
}
+21 -24
View File
@@ -1,19 +1,17 @@
import "./index.css";
import { FC } from "react";
import { useNodeEditorStyles } from "./styles";
import { AutomationNode, AutomationNodeMapping } from 'types/automations/index';
import { useEditorNodeState } from "./OptionManager";
import InputList from "components/Inputs/InputList";
import { Button } from "components/Inputs/Button";
export interface Props {
node: AutomationNode
allowedTypes?: Array<keyof AutomationNodeMapping>;
onClose?: () => void;
onSave?: (n: AutomationNode) => void;
saveBtnCreateText?: boolean;
}
export const NodeEditor: FC<Props> = ({
@@ -21,34 +19,33 @@ export const NodeEditor: FC<Props> = ({
allowedTypes = ["action", "condition", "trigger"],
onClose = () => { },
onSave = () => { },
saveBtnCreateText = false,
}) => {
const { classes } = useNodeEditorStyles({});
const state = useEditorNodeState(node);
return <div className={classes.root}>
<div className={classes.title}>
</div>
<div className={classes.body}>
{allowedTypes.length > 1 ? <InputList
label="Type"
current={state.nodeType}
options={allowedTypes}
onChange={state.setNodeType}
/> : <span>{state.nodeType}</span>}
{state.nodeType !== 'condition' ? <InputList
label={`${state.nodeType} type`}
current={state.subType as any}
options={state.subTypes}
onChange={state.setSubType}
/> : <></>}
return <div className="node-editor--root">
<div className="node-editor--body">
<div className="node-editor--body-title">
{allowedTypes.length > 1 ? <InputList
label="Type"
current={state.nodeType}
options={allowedTypes}
onChange={state.setNodeType}
/> : <span>{state.nodeType}</span>}
{state.nodeType !== 'condition' ? <InputList
label={`${state.nodeType} type`}
current={state.subType as any}
options={state.subTypes}
onChange={state.setSubType}
/> : <></>}
</div>
{state.renderOptionList()}
</div>
<div className={classes.footer}>
<div className="node-editor--footer">
<Button onClick={onClose}>Close</Button>
<Button onClick={() => {
state.isReady() && onSave(state.data)
}} disabled={!state.isReady()}>Save</Button>
}} disabled={!state.isReady()}>{saveBtnCreateText ? "Create" : "Save"}</Button>
</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({})
AdditionalElemets.args = {
@@ -23,6 +23,7 @@ export const SequenceNodes: FC<SequenceNodeProps & { zoomLevel: number }> = (pro
onClose={() => setModalState(null)}
onSave={n => { modalState.update(n as any); setModalState(null) }}
allowedTypes={modalState.onlyConditions ? ['condition'] : ['action', 'condition']}
saveBtnCreateText={modalState.saveBtnCreateText}
/>
} else {
modalBody = <MultiNodeEditor
@@ -4,12 +4,9 @@ import { Point } from "types/graphs";
import { makeUpdater, Updater } from './updater';
import { ChooseAction } from 'types/automations/actions';
import { AutomationCondition } from "types/automations/conditions";
import { ModalState } from "./types";
import { UpdateModalState } from "./types";
import { offsetPoint, makeOffsetMaintainer} from "utils/graph";
export type UpdateModalState = (
s: ModalState
) => void;
@@ -146,8 +143,19 @@ export function* computeNodesEdgesPos(
onChange: (s: AutomationSequenceNode[]) => void,
openModal: UpdateModalState,
): Generator<DAGElement> {
const rootUpdater = makeUpdater(sequence, onChange);
const offset = makeOffsetMaintainer(startPoint)
const rootUpdater = makeUpdater(sequence, onChange, openModal);
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;
for (let i = 0; i < sequence.length; i++) {
offset.setI(i)
@@ -2,6 +2,10 @@ import { DAGBoardElmDims, DAGElement } from "components/DAGSvgs/DAGBoard";
import { AutomationSequenceNode } from "types/automations";
import { Point } from "types/graphs";
export type UpdateModalState = (
s: ModalState
) => void;
export interface SequenceNodeProps {
startPoint: Point;
dims: DAGBoardElmDims;
@@ -14,6 +18,7 @@ export type ModalState = {
single: true,
node: AutomationSequenceNode
update: (n: AutomationSequenceNode) => void;
saveBtnCreateText?: boolean;
onlyConditions: boolean;
} | {
single: false,
+18 -8
View File
@@ -1,11 +1,13 @@
import { AutomationSequenceNode } from "types/automations";
import { ChooseAction } from "types/automations/actions";
import { UpdateModalState } from "./types";
export type Updater = ReturnType<typeof makeUpdater>;
export const makeUpdater = (
sequence: AutomationSequenceNode[],
onChange: (s: AutomationSequenceNode[]) => void
onChange: (s: AutomationSequenceNode[]) => void,
openModal: UpdateModalState,
) => ({
sequence,
onChange,
@@ -16,17 +18,23 @@ export const makeUpdater = (
])
},
addNode() {
return onChange([
...sequence,
{
return openModal({
single: true,
saveBtnCreateText: true,
node: {
$smType: 'action',
action: 'choose',
action_data: {
choose: [],
default: [],
}
}
])
},
update: n => onChange([
...sequence,
n,
]),
onlyConditions: false,
})
},
updateNode(i: number, node: AutomationSequenceNode) {
return onChange([
@@ -61,7 +69,8 @@ export const makeUpdater = (
...node.action_data.choose.slice(j+1),
]
}
})
}),
openModal,
)
} else {
return makeUpdater(
@@ -72,7 +81,8 @@ export const makeUpdater = (
...node.action_data,
default: seq
}
})
}),
openModal,
)
}
}