[200~latest changes to web~

This commit is contained in:
ari committed 2021-11-24 11:30:00 -05:00
1 parent f11d060ed2
commit 22bc5dfcf6
11 files changed
+636 -560

No files matched your search

+34 -34
View File
@@ -7,42 +7,42 @@ import { Node } from "./types"
export interface NodeProp extends Node {
height?: number;
width?: number;
isOpen?: boolean;
onXClick?: () => void;
onOpenClick?: () => void;
height?: number;
width?: number;
onXClick?: () => void;
onOpenClick?: () => void;
}
export default ({
loc: [x,y],
text,
height=NODE_HEIGHT,
width=NODE_WIDTH,
onXClick=() => {},
onOpenClick=() => {},
isOpen=false,
color,
loc: [x, y],
text,
height = NODE_HEIGHT,
width = NODE_WIDTH,
onXClick = () => { },
onOpenClick = () => { },
color,
}: NodeProp) => {
const {classes, theme} = useNodeStyles({
color,
nodeHeight: height,
nodeWidth: width,
});
return <foreignObject x={x} y={y} width={width} height={height}>
<div className={classes.root}>
<div className={classes.inner}>
<div className={classes.leftEdge} onClick={onXClick}>
<button className={classes.buttonDelete}>X</button>
</div>
<div className={classes.text}>
{text}
</div>
<div className={classes.rightEdge} onClick={onOpenClick}>
<button className={classes.buttonEdit}>
<PencilIcon size={1.1} color={Color(theme.primary).set('rgb.g', 200).hex()}/>
</button>
</div>
</div>
const { classes, theme } = useNodeStyles({
color,
nodeHeight: height,
nodeWidth: width,
});
return <foreignObject x={x} y={y} width={width} height={height}>
<div className={classes.root}>
<div className={classes.inner}>
<div className={classes.leftEdge} onClick={onXClick}>
<button className={classes.buttonDelete}>X</button>
</div>
</foreignObject>
<div className={classes.textWrap}>
<span className={classes.text}>
{text}
</span>
</div>
<div className={classes.rightEdge} onClick={onOpenClick}>
<button className={classes.buttonEdit}>
<PencilIcon size={1.1} color={Color(theme.primary).set('rgb.g', 200).hex()} />
</button>
</div>
</div>
</div>
</foreignObject>
}
@@ -7,54 +7,147 @@ import { useNodeStyles } from "./styles";
import { Point } from "./types";
export const SequenceNodes: FC<{
styles: ReturnType<typeof useNodeStyles>,
sequence: AutomationSequenceNode[],
onUpdate: (s: AutomationSequenceNode[]) => void,
nodeWidth: number,
nodeHeight: number,
triggerPoint: Point,
nHDF: number,
}> = ({
styles: { classes, theme },
sequence,
onUpdate,
nodeWidth,
nodeHeight,
triggerPoint,
nHDF,
interface Props extends RenderSequenceProps {
styles: ReturnType<typeof useNodeStyles>,
sequence: AutomationSequenceNode[],
triggerPoint: Point,
}
export const SequenceNodes: FC<Props> = ({
sequence,
triggerPoint,
...renderSequenceProps
}) => {
const renderSequence = (node: AutomationSequenceNode, i: number) => {
const nodeLoc: Point = [triggerPoint[0] + nodeWidth/2 , 0];
let lastNodeLoc = triggerPoint;
if (i > 0) {
lastNodeLoc = [nodeLoc[0] + nodeWidth*((i - 1)*nHDF+1), nodeLoc[1] + nodeHeight/2];
nodeLoc[0] += nodeWidth*i*nHDF
}
return <>
<DAGNode
key={`node.${i}`}
loc={nodeLoc}
text={getDescriptionFromAutomationNode(node)}
color={node.$smType === 'action' ? 'green' : 'blue'}
onXClick={() => {
onUpdate([
...sequence.slice(0, i),
...sequence.slice(i+1),
])
}}
/>
<DAGEdge
key={`edge.${i}`}
p1={lastNodeLoc}
p2={[nodeLoc[0], nodeLoc[1] + nodeHeight/2]}
direction="1->2"
className={classes.dagEdge}
/>
</>
const renderSequence = makeRenderSequence(renderSequenceProps);
return <g id="sequence">
{sequence.map((n, i) => renderSequence(triggerPoint, n, i))}
</g>
}
interface RenderSequenceProps {
styles: ReturnType<typeof useNodeStyles>,
onUpdate: (i: number, s: AutomationSequenceNode | null) => void,
nodeWidth: number,
nodeHeight: number,
nHDF: number,
}
const makeRenderSequence = ({
onUpdate,
nodeHeight,
nodeWidth,
nHDF,
styles: { classes }
}: RenderSequenceProps) => (
startPoint: Point,
node: AutomationSequenceNode,
i: number
) => {
const nodeLoc: Point = [startPoint[0] + nodeWidth / 2, 0];
let lastNodeLoc = startPoint;
if (i > 0) {
lastNodeLoc = [nodeLoc[0] + nodeWidth * ((i - 1) * nHDF + 1), nodeLoc[1] + nodeHeight / 2];
nodeLoc[0] += nodeWidth * i * nHDF
}
return <g id="sequence">
{sequence.map(renderSequence)}
</g>
}
const curretEdgeLoc: Point = [nodeLoc[0], nodeLoc[1] + nodeHeight / 2];
const nextAddLoc: Point = [nodeLoc[0] + nodeWidth * nHDF, nodeLoc[1] + nodeHeight / 2];
return <>
<DAGEdge
key={`edge.${i}`}
p1={lastNodeLoc}
p2={curretEdgeLoc}
direction="1->2"
className={classes.dagEdge}
/>
<DAGNode
height={nodeHeight}
width={nodeWidth}
key={`node.${i}`}
loc={nodeLoc}
text={getDescriptionFromAutomationNode(node)}
color={node.$smType === 'action' ? 'green' : 'blue'}
onXClick={() => onUpdate(i, null)}
/>
<DAGEdge
key={`edge.${i}`}
p1={curretEdgeLoc}
p2={nextAddLoc}
direction="1->2"
className={classes.dagEdge}
/>
</>
}
export function* getJSXNodes(
{ classes }: ReturnType<typeof useNodeStyles>,
onUpdate: (i: number, s: AutomationSequenceNode | null) => void, it: Generator<NodeEdgeLocation, Point, never>
) {
let next = it.next();
while (!next.done) {
const { node, nodeLoc, curretEdgeLoc, nextAddLoc, lastStartPoint, nodeHeight, nodeWidth } = next.value;
yield <>
<DAGEdge
key={`edge.${i}`}
p1={nodeLoc}
p2={curretEdgeLoc}
direction="1->2"
className={classes.dagEdge}
/>
<DAGNode
height={nodeHeight}
width={nodeWidth}
key={`node.${i}`}
loc={nodeLoc}
text={getDescriptionFromAutomationNode(node)}
color={node.$smType === 'action' ? 'green' : 'blue'}
onXClick={() => onUpdate(i, null)}
/>
<DAGEdge
key={`edge.${i}`}
p1={curretEdgeLoc}
p2={nextAddLoc}
direction="1->2"
className={classes.dagEdge}
/>
</>
}
}
type NodeEdgeLocation = {
nodeId: string;
node: AutomationSequenceNode;
nodeLoc: Point;
lastStartPoint: Point;
curretEdgeLoc: Point;
nextAddLoc: Point | null;
nodeWidth: number;
nodeHeight: number;
}
export function* computeNodeEdgeLocation(
startPoint: Point,
nodeWidth: number,
nodeHeight: number,
distanceFactor: number,
sequence: AutomationSequenceNode[]
): Generator<NodeEdgeLocation, Point, never> {
let lastStartPoint: Point = [...startPoint];
for (let i = 0; i < sequence.length; i++) {
const node = sequence[i];
const nodeLoc: Point = lastStartPoint = [lastStartPoint[0], lastStartPoint[1] + nodeWidth * distanceFactor];
const curretEdgeLoc: Point = [nodeLoc[0], nodeLoc[1] + nodeHeight / 2];
const nextAddLoc: Point | null = i < sequence.length ? null : [nodeLoc[0] + nodeWidth * distanceFactor, nodeLoc[1] + nodeHeight / 2];
// if ((node.$smType === 'action') && (node.action === 'choose')) {
// for (let { sequence } of node.action_data.choose) {
// for (let parsedChild of computeNodeEdgeLocation(
// nodeLoc,
// nodeWidth,
// nodeHeight,
// distanceFactor,
// sequence
// )) {
// yield parsedChild;
// }
// }
// }
yield { node, nodeLoc, lastStartPoint, curretEdgeLoc, nextAddLoc, nodeHeight, nodeWidth }
}
return lastStartPoint
}
@@ -1,5 +1,5 @@
export const NODE_WIDTH = 90 as const;
export const NODE_HEIGHT = 40 as const;
export const NODE_WIDTH = 100 as const;
export const NODE_HEIGHT = 40 as const;
@@ -5,197 +5,207 @@ import { usePageTheme } from "~/styles/page";
import AutomationEditor from ".";
export default {
title: 'AutomationEditor',
component: AutomationEditor,
parameters: { actions: { argTypesRegex: '^on.*' } },
} as ComponentMeta<typeof AutomationEditor>;
title: 'AutomationEditor',
component: AutomationEditor,
parameters: { actions: { argTypesRegex: '^on.*' } },
} as ComponentMeta<typeof AutomationEditor>;
const Template: ComponentStory<typeof AutomationEditor> = ({automation, ...args}) => {
const {classes} = usePageTheme({});
const [data, setData] = useState(automation);
return <div className={classes.page}>
<AutomationEditor {...args}
automation={data}
onUpdate={data => {
setData(data)
}}
const Template: ComponentStory<typeof AutomationEditor> = ({ automation, ...args }) => {
const { classes } = usePageTheme({});
const [data, setData] = useState(automation);
return <div className={classes.page}>
<AutomationEditor {...args}
automation={data}
onUpdate={data => {
setData(data)
}}
/>
</div>
</div>
}
export const ServiceAction = Template.bind({})
ServiceAction.args = {
automation: {
metadata: {
id: "X12314akx",
alias: "root",
description: 'Really Long Description',
mode: 'single',
},
trigger: [
{
platform: 'time',
at: '10:00:00'
},
{
platform: "device",
device_id: "34749",
domain: "zha",
type: "remote_button_double_press",
subtype: "remote_button_double_press"
}
],
sequence: [
{
$smType: "condition",
condition: 'and',
automation: {
metadata: {
id: "X12314akx",
alias: "root",
description: 'Really Long Description',
mode: 'single',
},
trigger: [
{
platform: 'time',
at: '10:00:00'
},
{
platform: "device",
device_id: "34749",
domain: "zha",
type: "remote_button_double_press",
subtype: "remote_button_double_press"
}
],
sequence: [
{
$smType: "condition",
condition: 'and',
condition_data: {
conditions: [
{
$smType: 'condition',
condition: 'numeric_state',
condition_data: {
conditions: [
{
$smType: 'condition',
condition: 'numeric_state',
condition_data: {
entity_id: 'sensor.temperature_kitchen',
below: '15',
}
},
{
$smType: "condition",
condition: 'template',
condition_data: {
value_template: 'states(switch.kitchen_light) == "on"'
}
}
]
entity_id: 'sensor.temperature_kitchen',
below: '15',
}
},
{
$smType: "condition",
condition: 'template',
condition_data: {
value_template: 'states(switch.kitchen_light) == "on"'
}
}
]
}
},
{
$smType: "action",
action: "service",
action_data: {
alias: "Start Music In Kitchen",
service: 'media_player.play_media',
target: {
entity_id: "media_player.kitchen_dot"
},
{
$smType: "action",
action: "service",
action_data: {
alias: "Start Music In Kitchen",
service: 'media_player.play_media',
target: {
entity_id: "media_player.kitchen_dot"
},
data: {
media_content_id: "Good Morning",
media_content_type: "SPOTIFY",
}
}
data: {
media_content_id: "Good Morning",
media_content_type: "SPOTIFY",
}
],
} as AutomationData
}
}
],
} as AutomationData
}
export const ChooseAction = Template.bind({})
ChooseAction.args = {
automation: {
metadata: {
id: "X12314akx",
alias: "root",
description: 'Really Long Description',
mode: 'single',
},
trigger: [
{
platform: 'time',
at: '10:00:00'
},
{
platform: "device",
device_id: "34749",
domain: "zha",
type: "remote_button_double_press",
subtype: "remote_button_double_press"
}
],
sequence: [
{
$smType: "condition",
condition: 'and',
automation: {
metadata: {
id: "X12314akx",
alias: "root",
description: 'Really Long Description',
mode: 'single',
},
trigger: [
{
platform: 'time',
at: '10:00:00'
},
{
platform: "device",
device_id: "34749",
domain: "zha",
type: "remote_button_double_press",
subtype: "remote_button_double_press"
}
],
sequence: [
{
$smType: "condition",
condition: 'and',
condition_data: {
conditions: [
{
$smType: 'condition',
condition: 'numeric_state',
condition_data: {
conditions: [
{
$smType: 'condition',
condition: 'numeric_state',
condition_data: {
entity_id: 'sensor.temperature_kitchen',
below: '15',
}
},
{
$smType: "condition",
condition: 'template',
condition_data: {
value_template: 'states(switch.kitchen_light) == "on"'
entity_id: 'sensor.temperature_kitchen',
below: '15',
}
},
{
$smType: "condition",
condition: 'template',
condition_data: {
value_template: 'states(switch.kitchen_light) == "on"'
}
}
]
}
},
{
$smType: "action",
action: "choose",
action_data: {
choose: [
{
conditions: [
{
$smType: "condition",
condition: 'time',
condition_data: {
after: {
hours: 16,
minutes: 30
}
}
]
}
},
{
$smType: "action",
action: "choose",
action_data: {
choose: [
{
conditions: [
{
$smType: "condition",
condition: 'time',
condition_data: {
after: {
hours: 16,
minutes: 30
}
}
}
],
sequence: [
{
$smType: 'action',
action: 'event',
action_data: {
event: "superImportant_time",
event_data: {
time: '4:30PM'
}
}
}
]
},
{
conditions: [
{
$smType: "condition",
condition: 'time',
condition_data: {
after: {
hours: 18,
minutes: 45
}
}
}
],
sequence: [
{
$smType: 'action',
action: 'event',
action_data: {
event: "superImportant_time",
event_data: {
time: '6:45PM'
}
}
}
]
}
],
sequence: [
{
$smType: 'action',
action: 'event',
action_data: {
event: "superImportant_time",
event_data: {
time: '4:30PM'
}
}
]
}
}
]
},
{
conditions: [
{
$smType: "condition",
condition: 'time',
condition_data: {
after: {
hours: 18,
minutes: 45
}
}
}
],
sequence: [
{
$smType: 'action',
action: 'event',
action_data: {
event: "superImportant_time",
event_data: {
time: '6:45PM'
}
}
}
]
}
]
}
},
{
$smType: 'action',
action: "service",
action_data: {
service: "light.turn_on",
data: {
entity_id: "light.kitchen"
}
],
} as AutomationData
}
}
}
],
} as AutomationData
}
+99 -84
View File
@@ -1,5 +1,4 @@
import { AutomationData, AutomationSequenceNode } from "~/automations/types";
import { AutomationCondition } from "~/automations/types/conditions";
import { AutomationData } from "~/automations/types";
import { AutomationTrigger } from "~/automations/types/triggers";
import { getDescriptionFromAutomationNode } from "~/automations/utils";
import useWindowSize from "~/utils/useWindowSize";
@@ -10,95 +9,111 @@ import DAGNode from "./DAGNode";
import { SequenceNodes } from "./SequenceNodes";
import { useEditorStyles } from "./styles";
import { Point } from "./types";
import { AutomationSequenceNode } from '../../automations/types/index';
interface Props {
automation: AutomationData;
onUpdate: (auto: AutomationData) => void;
automation: AutomationData;
onUpdate: (auto: AutomationData) => void;
}
export default function AutomationEditor({
automation,
onUpdate,
automation,
onUpdate,
}: Props) {
// state
const {ratioWbh} = useWindowSize();
const {classes, theme} = useEditorStyles({});
// state
const { ratioWbh } = useWindowSize();
const { classes, theme } = useEditorStyles({});
// alias
const nHDF = 1.5 // node horizontal distance factor
const graphHeight = 300;
const graphWidth = Math.round(graphHeight * ratioWbh);
const pointTrigToCond: Point = [NODE_WIDTH*nHDF, NODE_HEIGHT/2]
// render funcs
const renderTrigger = (trigger: AutomationTrigger, i: number) => {
const nodeLoc: Point = [0 ,i*NODE_HEIGHT*1.25];
return <>
<DAGNode key={`node.${i}`}
loc={nodeLoc}
text={getDescriptionFromAutomationNode(trigger)}
color="red"
onXClick={() => {
onUpdate({
...automation,
trigger: [
...automation.trigger.slice(0, i),
...automation.trigger.slice(i+1),
]
})
}}
/>
<DAGEdge
key={`edge.${i}`}
p1={[NODE_WIDTH , nodeLoc[1] + 0.5 * NODE_HEIGHT]}
p2={pointTrigToCond}
className={classes.dagEdge}
direction="1->2"
/>
</>
// alias
const nHDF = 1.5 // node horizontal distance factor (aspect ratio)
const graphHeight = 300;
const graphWidth = Math.round(graphHeight * ratioWbh);
const pointTrigToCond: Point = [NODE_WIDTH * nHDF, NODE_HEIGHT / 2]
const updateSequence = (i: number, node: AutomationSequenceNode | null) => {
const update = (sequence: AutomationSequenceNode[]) => onUpdate({
...automation,
sequence,
})
if (node === null) {
update([
...automation.sequence.slice(0, i),
...automation.sequence.slice(i + 1),
])
} else {
update([
...automation.sequence.slice(0, i),
node,
...automation.sequence.slice(i + 1),
])
}
};
// render
return <div className={classes.root} style={{
flexDirection: ratioWbh >= 0.75 ? 'row' : 'column'
}}>
<AutoInfoBox
className={classes.infoBox}
metadata={automation.metadata}
onUpdate={metadata => onUpdate({...automation, metadata})}
// render funcs
const renderTrigger = (trigger: AutomationTrigger, i: number) => {
const nodeLoc: Point = [0, i * NODE_HEIGHT];
return <>
<DAGNode key={`node.${i}`}
loc={nodeLoc}
text={getDescriptionFromAutomationNode(trigger)}
color="red"
onXClick={() => {
onUpdate({
...automation,
trigger: [
...automation.trigger.slice(0, i),
...automation.trigger.slice(i + 1),
]
})
}}
/>
<DAGEdge
key={`edge.${i}`}
p1={[NODE_WIDTH, nodeLoc[1] + 0.5 * NODE_HEIGHT]}
p2={pointTrigToCond}
className={classes.dagEdge}
direction="1->2"
/>
</>
}
// render
return <div className={classes.root} style={{
flexDirection: ratioWbh >= 0.75 ? 'row' : 'column'
}}>
<AutoInfoBox
className={classes.infoBox}
metadata={automation.metadata}
onUpdate={metadata => onUpdate({ ...automation, metadata })}
/>
<div className={classes.dag}>
<svg
className={classes.svg}
viewBox={[0, 0, graphWidth, graphHeight].join(" ")}
xmlns="http://www.w3.org/2000/svg"
>
<defs>
<marker id="arrow" viewBox="0 0 10 10" refX="10" refY="5"
markerWidth="6" markerHeight="6"
orient="auto-start-reverse">
<path d="M 0 0 L 10 5 L 0 10 z" fill={theme.secondaryAccent} />
</marker>
</defs>
<g className="triggers">
{automation.trigger.map(renderTrigger)}
</g>
<SequenceNodes
styles={{ classes, theme }}
sequence={automation.sequence}
onUpdate={updateSequence}
nHDF={nHDF}
nodeHeight={NODE_HEIGHT}
nodeWidth={NODE_WIDTH}
triggerPoint={pointTrigToCond}
/>
<div className={classes.dag}>
<svg
className={classes.svg}
viewBox={[0,0,graphWidth, graphHeight].join(" ")}
xmlns="http://www.w3.org/2000/svg"
>
<defs>
<marker id="arrow" viewBox="0 0 10 10" refX="10" refY="5"
markerWidth="6" markerHeight="6"
orient="auto-start-reverse">
<path d="M 0 0 L 10 5 L 0 10 z" fill={theme.secondaryAccent} />
</marker>
</defs>
<g className="triggers">
{automation.trigger.map(renderTrigger)}
</g>
<SequenceNodes
styles={{classes, theme}}
sequence={automation.sequence}
onUpdate={sequence => onUpdate({
...automation,
sequence,
})}
nHDF={nHDF}
nodeHeight={NODE_HEIGHT}
nodeWidth={NODE_WIDTH}
triggerPoint={pointTrigToCond}
/>
<circle className={classes.circle} cx={pointTrigToCond[0]} cy={pointTrigToCond[1]} r={2}/>
<g className="actions">
</g>
</svg>
</div>
</div>
}
<circle className={classes.circle} cx={pointTrigToCond[0]} cy={pointTrigToCond[1]} r={2} />
<g className="actions">
</g>
</svg>
</div>
</div>
}
+131 -123
View File
@@ -5,131 +5,139 @@ import { Node } from "./types";
export const useEditorStyles = createAppUseStyles(theme => ({
root: {
height: '99%',
width: '99%',
color: theme.primaryAccent,
display: 'flex',
flexDirection: 'row',
},
dag: {
borderWidth: 1,
borderStyle: 'solid',
borderColor: theme.secondaryAccent,
width: '100%',
},
svg: {
height: '99%',
width: '99%',
padding: 0,
margin: 0,
},
circle: {
fill: Color(theme.secondary).set('rgb.b', 125).hex(),
},
infoBox: {
paddingLeft: '10px',
paddingRight: '10px',
display: 'flex',
flexDirection: 'column',
justifyContent: 'flex-start',
overflow: 'auto',
},
dagEdge: {
stroke: theme.secondaryAccent,
},
root: {
height: '99%',
width: '99%',
color: theme.primaryAccent,
display: 'flex',
flexDirection: 'row',
},
dag: {
borderWidth: 1,
borderStyle: 'solid',
borderColor: theme.secondaryAccent,
width: '100%',
},
svg: {
height: '99%',
width: '99%',
padding: 0,
margin: 0,
},
circle: {
fill: Color(theme.secondary).set('rgb.b', 125).hex(),
},
infoBox: {
paddingLeft: '10px',
paddingRight: '10px',
display: 'flex',
flexDirection: 'column',
justifyContent: 'flex-start',
overflow: 'auto',
},
dagEdge: {
stroke: theme.secondaryAccent,
},
}))
export const useNodeStyles = createAppUseStyles<{
color: Node['color'],
nodeHeight: number,
nodeWidth: number,
color: Node['color'],
nodeHeight: number,
nodeWidth: number,
}>(theme => {
const edgeStyle: Styles = {
flex: '1',
display: 'flex',
flexDirection: 'column',
flexWrap: 'nowrap',
borderRadius: '1em',
justifyContent: 'space-around',
alignItems: 'center',
'&:hover': {
backgroundColor: theme.primaryAccent,
cursor: 'pointer',
}
const edgeStyle: Styles = {
flex: '1',
display: 'flex',
flexDirection: 'column',
flexWrap: 'nowrap',
borderRadius: '1em',
justifyContent: 'space-around',
alignItems: 'center',
'&:hover': {
backgroundColor: theme.primaryAccent,
cursor: 'pointer',
}
const buttonStyle: Styles = {
fontSize: '8px',
backgroundColor: "rgba(0,0,0,0)",
color: theme.primaryAccent,
borderStyle: 'none',
height: '15px',
width: '15px',
cursor: 'pointer',
transition: "500ms east-out",
}
return {
root: {
display: 'flex',
flexDirection: 'column',
justifyContent: 'flex-end',
height: `100%`,
maxHeight: `100%`,
maxWidth: '100%',
width: '100%',
fontSize: 10,
},
inner: ({color}) => ({
position: 'relative',
display: 'flex',
flexDirection: 'row',
backgroundColor: theme.secondary,
borderRadius: '1em',
flex: 1,
height: `calc(100% - 10px)`,
maxHeight: `calc(100% - 10px)`,
maxWidth: '100%',
borderTopWidth: '1px',
borderTopStyle: 'solid',
borderTopLeftRadius: '10px',
borderTopRightRadius: '10px',
borderTopColor: color === 'red' ? Color(theme.secondary).set('rgb.r', 125).hex() :
color === 'blue' ? Color(theme.secondary).set('rgb.b', 125).hex() :
color === 'green' ? Color(theme.secondary).set('rgb.g', 125).hex() :
'none'
}),
text: {
flex: 4,
display: 'flex',
textAlign: 'center',
justifyContent: 'center',
alignItems: 'center',
height: '100%',
maxHeight: '100%',
},
buttonDelete: {
...buttonStyle,
"&:hover": {
color: theme.primary,
}
},
buttonEdit: {
...buttonStyle,
"&:hover": {
transform: "rotate(45deg)"
}
},
leftEdge: {
...edgeStyle,
borderLeft: `1px ${theme.secondaryAccent} solid`,
borderTopRightRadius: 0,
borderBottomRightRadius: 0,
},
rightEdge: {
...edgeStyle,
borderRight: `1px ${theme.secondaryAccent} solid`,
borderTopLeftRadius: 0,
borderBottomLeftRadius: 0,
},
}
})
}
const buttonStyle: Styles = {
fontSize: '8px',
backgroundColor: "rgba(0,0,0,0)",
color: theme.primaryAccent,
borderStyle: 'none',
height: '15px',
width: '15px',
cursor: 'pointer',
transition: "500ms east-out",
}
return {
root: {
display: 'flex',
flexDirection: 'column',
justifyContent: 'flex-end',
height: `100%`,
maxHeight: `100%`,
maxWidth: '100%',
width: '100%',
fontSize: 10,
},
inner: ({ color }) => ({
position: 'relative',
display: 'flex',
flexDirection: 'row',
backgroundColor: theme.secondary,
borderRadius: '1em',
flex: 1,
height: `100%`,
maxHeight: `100%`,
maxWidth: '100%',
marginTop: '2.5px',
marginBottom: '2.5px',
borderTopWidth: '1px',
borderTopStyle: 'solid',
borderTopLeftRadius: '10px',
borderTopRightRadius: '10px',
borderTopColor: color === 'red' ? Color(theme.secondary).set('rgb.r', 125).hex() :
color === 'blue' ? Color(theme.secondary).set('rgb.b', 125).hex() :
color === 'green' ? Color(theme.secondary).set('rgb.g', 125).hex() :
'none'
}),
textWrap: {
display: 'flex',
flex: 4,
textAlign: 'center',
justifyContent: 'center',
alignItems: 'center',
height: '100%',
maxHeight: '100%',
maxWidth: "50%",
},
text: {
textOverflow: 'ellipsis',
overflow: "hidden",
whiteSpace: "nowrap",
},
buttonDelete: {
...buttonStyle,
"&:hover": {
color: theme.primary,
}
},
buttonEdit: {
...buttonStyle,
"&:hover": {
transform: "rotate(45deg)"
}
},
leftEdge: {
...edgeStyle,
borderLef: `1px ${theme.secondaryAccent} solid`,
borderTopRightRadius: 0,
borderBottomRightRadius: 0,
},
rightEdge: {
...edgeStyle,
borderRight: `1px ${theme.secondaryAccent} solid`,
borderTopLeftRadius: 0,
borderBottomLeftRadius: 0,
},
}
})
+8 -8
View File
@@ -1,16 +1,16 @@
export type Point = [number, number];
export interface Node {
loc: Point;
text: JSX.Element | string;
color: 'red' | 'blue' | 'green';
loc: Point;
text: string;
color: 'red' | 'blue' | 'green';
}
export interface Edge {
from: string;
to: string;
direction: '1->2' | '1<->2' | '1<-2';
from: string;
to: string;
direction: '1->2' | '1<->2' | '1<-2';
}
export type EdgeDirection = Edge['direction'];
export interface DAG {
nodes: Record<string,Node>;
edges: Array<Edge>;
nodes: Record<string, Node>;
edges: Array<Edge>;
}
@@ -1,38 +0,0 @@
import { ComponentMeta, ComponentStory } from "@storybook/react";
import { useState } from "react";
import { AutomationAction } from "~/automations/types/actions";
import { usePageTheme } from "~/styles/page";
import { SequenceEditor } from ".";
export default {
title: 'SequenceEditor',
component: SequenceEditor,
parameters: { actions: { argTypesRegex: '^on.*' } },
} as ComponentMeta<typeof SequenceEditor>;
const Template: ComponentStory<typeof SequenceEditor> = ({node, ...args}) => {
const {classes} = usePageTheme({});
const [data, setData] = useState(node);
return <div className={classes.page}>
<SequenceEditor {...args}
node={data}
onUpdate={data => {
setData(data)
}}
/>
</div>
}
export const ServiceAction = Template.bind({})
ServiceAction.args = {
node: {
$smType: 'action',
action: 'service',
action_data: {
service: 'switch.toggle',
data: {},
target: {},
}
} as AutomationAction
}
-30
View File
@@ -1,30 +0,0 @@
import { FC } from "react";
import { ChooseAction } from "~/automations/types/actions";
export const ChooseEditor: FC<{
node: ChooseAction,
onUpdate: (u: ChooseAction) => void,
}> = ({
node,
onUpdate,
}) => {
return <div>
<div>
<span>{node.action}</span>
</div>
<div>
<div>
{node.action_data.choose.map( ({conditions, sequence}, i) => <div>
<button>X</button>
<div>{i > 0 ? "else if" : 'if'}</div>
<div>Condition</div>
<div>
{sequence.map( s => s.$smType)}
</div>
</div>)}
</div>
</div>
</div>
}