This commit is contained in:
ari committed 2021-12-28 21:53:41 -05:00
1 parent 9d8cc9ed3e
commit 8058e314db
27 files changed
+87608 -11878

No files matched your search

@@ -7,6 +7,7 @@ import { DAGBoardElmDims } from 'components/DAGSvgs/DAGBoard';
import { defaultAutomation } from '../../utils/defaults';
import { ArrowIcon, TrashIcon } from "components/Icons";
import { ButtonIcon } from "components/Icons/ButtonIcons";
import { useSearchParams } from "react-router-dom";
interface Props {
@@ -25,9 +26,12 @@ export const AutomationList: FC<Props> = ({
dims,
}) => {
// state
const [current, setCurrent] = useState(0);
const [searchParams, setSearchParams] = useSearchParams();
// const [current, setCurrent] = useState(0);
const [hideList, setHideList] = useState(false);
// alias
const current = Number(searchParams.get("current") ?? "0");
const setCurrent = (i: number) => setSearchParams({ current: String(i) });
const currentAuto = automations.length > 0 ? automations[current] : null;
const automationListListCls = "automation-list--list" + (hideList ? " hide" : " show")
// render
@@ -1,7 +1,10 @@
import { AutomationCondition, LogicCondition } from "types/automations/conditions";
export const genUpdateMethods = (condition: LogicCondition, onChange: (c: LogicCondition) => void) => (i: number) => ({
export const genUpdateMethods = (
condition: LogicCondition,
onChange: (c: LogicCondition) => void
) => (i: number) => ({
onUpdate: (update: AutomationCondition) => onChange({
...condition,
condition_data: {
@@ -24,26 +27,8 @@ export const genUpdateMethods = (condition: LogicCondition, onChange: (c: LogicC
)
}
})
} else {
const data = (c as LogicCondition).condition_data;
const update = {
...condition.condition_data,
conditions: [
...condition.condition_data.conditions.slice(0, i),
{
...c,
condition_data: {
...data,
conditions: data.conditions.slice(0, which).concat(data.conditions.concat(which+1))
}
},
...condition.condition_data.conditions.slice(i+1)
]
}
onChange({
...condition,
condition_data: update as any
})
} else {
throw new Error("Not Implemented")
}
}
})
+106 -102
View File
@@ -2,6 +2,8 @@ import React from "react";
import { ComponentMeta, ComponentStory } from '@storybook/react';
import { DAGBoard, DAGElement, DAGNodeElm } from "./DAGBoard";
import { NODE_HEIGHT, NODE_WIDTH, ADD_HEIGHT, ADD_WIDTH, DISTANCE_FACTOR, CIRCLE_SIZE } from './constants';
import { AutomationAction } from 'types/automations/actions';
import { arrayToIter } from "utils/iter";
export default {
@@ -26,124 +28,126 @@ export default {
const nodeFromPoint = ([x, y, add = true]: any): DAGNodeElm => ({
type: 'node',
key: `${x},${y}`,
loc: [x, y],
onRemove() { },
onAdd: add ? () => { } : undefined,
node: {
$smType: 'action',
node: ({
alias: `${x},${y}`,
action: 'template',
action_data: {
value_template: ""
"$smType": "action",
"action": "wait",
"action_data": {
"wait_template": "",
}
} as AutomationAction)
});
function* makeDummyData(pts: Array<any>, extras: DAGElement[]): Generator<DAGElement> {
for (const p of pts) {
yield nodeFromPoint(p);
};
for (const e of extras) {
yield e;
}
})
}
export const Simple: ComponentStory<typeof DAGBoard> = args => <DAGBoard {...args} />
Simple.args = {
...Simple.args,
elements: [
[0, 0, false],
[1, 0, false],
[2, 1, false],
].map<DAGElement>(nodeFromPoint).concat([
{
type: 'edge',
key: 'e1',
p1: [0, 0],
p2: [1, 0],
direction: '1->2'
},
{
type: 'edge',
key: 'e2',
p1: [2, 1],
p2: [2, 3],
direction: '1->2'
},
{
type: 'circle',
key: 'c1',
loc: [2, 3]
},
{
type: 'edge',
key: 'e2',
p1: [2, 1],
p2: [2, 2],
direction: '1->2'
},
{
type: 'circle',
key: 'c1',
loc: [2, 2],
onClick: () => { }
}
])
elements: makeDummyData(
[
[0, 0, false],
[1, 0, false],
[2, 1, false],
],
[
{
type: 'edge',
p1: [0, 0],
p2: [1, 0],
direction: '1->2'
},
{
type: 'edge',
p1: [2, 1],
p2: [2, 3],
direction: '1->2'
},
{
type: 'circle',
icon: 'blank',
loc: [2, 3]
},
{
type: 'edge',
p1: [2, 1],
p2: [2, 2],
direction: '1->2'
},
{
type: 'circle',
loc: [2, 2],
icon: 'color',
color: 'red',
}
])
}
export const Complex: ComponentStory<typeof DAGBoard> = args => <DAGBoard {...args} />
Complex.args = {
...Complex.args,
elements: [
[0, 0, false],
[1, 0, false],
[2, 1, false],
[4, 1],
[3, 2],
[2, 3],
[5, 0, false],
[6, 0],
[0, 6],
].map<DAGElement>(nodeFromPoint).concat([
{
type: 'edge',
key: 'e1',
p1: [0, 0],
p2: [1, 0],
direction: '1->2'
},
{
type: 'edge',
key: 'e2',
p1: [2, 1],
p2: [4, 1],
direction: '1->2',
},
{
type: 'edge',
key: 'e3',
p1: [1, 0],
p2: [2, 1],
direction: '1->2',
toChild: true,
},
{
type: 'edge',
key: 'e4',
p1: [2, 1],
p2: [3, 2],
direction: '1->2',
toChild: true,
},
{
type: 'edge',
key: 'e5',
p1: [1, 0],
p2: [2, 3],
direction: '1->2',
toChild: true,
},
{
type: 'edge',
key: 'e6',
p1: [1, 0],
p2: [5, 0],
direction: '1->2'
},
])
elements: makeDummyData(
[
[0, 0, false],
[1, 0, false],
[2, 1, false],
[4, 1],
[3, 2],
[2, 3],
[5, 0, false],
[6, 0],
[0, 6],
],
[
{
type: 'edge',
p1: [0, 0],
p2: [1, 0],
direction: '1->2'
},
{
type: 'edge',
p1: [2, 1],
p2: [4, 1],
direction: '1->2',
},
{
type: 'edge',
p1: [1, 0],
p2: [2, 1],
direction: '1->2',
},
{
type: 'edge',
p1: [2, 1],
p2: [3, 2],
direction: '1->2',
},
{
type: 'edge',
p1: [1, 0],
p2: [2, 3],
direction: '1->2',
},
{
type: 'edge',
p1: [1, 0],
p2: [5, 0],
direction: '1->2'
},
]
)
}
+1 -1
View File
@@ -65,7 +65,7 @@ export interface DAGBoardElmDims {
}
export interface Props {
elements: Generator<DAGElement>;
elements: Generator<DAGElement> | Array<DAGElement>;
settings: DAGBoardSettings;
}
@@ -1,3 +1,4 @@
import { DAGBoardElmDims } from 'components/DAGSvgs/DAGBoard';
@@ -7,3 +8,12 @@ export const ADD_HEIGHT = 10 as const;
export const ADD_WIDTH = 10 as const;
export const CIRCLE_SIZE = 30 as const;
export const DISTANCE_FACTOR = 1.5 as const;
export const DEFAULT_DIMS: DAGBoardElmDims = {
nodeHeight: NODE_HEIGHT,
nodeWidth: NODE_WIDTH,
addHeight: ADD_HEIGHT,
addWidth: ADD_WIDTH,
circleSize: CIRCLE_SIZE,
distanceFactor: DISTANCE_FACTOR,
};
+14 -19
View File
@@ -1,26 +1,21 @@
import InputWrapper from "./InputWrapper";
export interface Props {
label: string;
value: boolean;
onChange: (v: boolean) => void;
label: string;
value: boolean;
onChange: (v: boolean) => void;
}
export default function InputBoolean({
label,
value=false,
onChange,
label,
value = false,
onChange,
}: Props) {
return <InputWrapper label={label} style={{
flexDirection: 'row',
justifyContent: 'space-between',
marginTop: '3%',
marginBottom: '3%'
return <InputWrapper label={label}>
<span className="checkbox" onClick={e => {
e.preventDefault()
onChange(!value)
}}>
<span className="checkbox" onClick={e => {
e.preventDefault()
onChange(!value)
}}>
{value ? '✔️' : ' '}
</span>
</InputWrapper>
}
{value ? '✔️' : ' '}
</span>
</InputWrapper>
}
@@ -1,8 +1,6 @@
import { FC, useState } from "react";
import { useToolTip } from "tooltip/context";
import InputText from "./InputText";
import InputWrapper from "./InputWrapper";
import { useInputBubblesStyles, useInputTextStyles } from "./styles";
import { useInputBubblesStyles } from "./styles";
export interface Props {
label: string;
+12 -11
View File
@@ -1,16 +1,17 @@
import { PropsWithChildren } from "react";
import { FC } from "react";
import { useInputWrapperStyles } from "./styles";
export interface Props {
label: string;
labelSize?: 'normal' | 'small';
noMargin?: boolean;
label: string;
labelSize?: 'normal' | 'small';
noMargin?: boolean;
}
export default function InputWrapper({label, children, labelSize='normal', noMargin=false}: PropsWithChildren<Props>) {
const {classes} = useInputWrapperStyles({labelSize, noMargin})
return <div className={classes.wrapper}>
<label className={classes.label}>{label}</label>
{children}
</div>
}
const InputWrapper: FC<Props> = ({ label, children, labelSize = 'normal', noMargin = false }) => {
const { classes } = useInputWrapperStyles({ labelSize, noMargin })
return <div className={classes.wrapper}>
<label className={classes.label}>{label}</label>
{children}
</div>
}
export default InputWrapper;
+29 -30
View File
@@ -1,39 +1,38 @@
import InputWrapper from "./InputWrapper";
import * as yaml from "js-yaml";
import { useEffect, useRef, useState } from "react";
import InputTextArea from "./InputTextArea";
export interface Props<T extends {}> {
label: string;
value: T;
onChange: (v: T) => void;
resizable?: boolean;
label: string;
value: T;
onChange: (v: T) => void;
resizable?: boolean;
}
export default function InputYaml<T>({
label,
value={} as any,
onChange,
resizable,
label,
value = {} as any,
onChange,
resizable,
}: Props<T>) {
const [text, setText] = useState("");
useEffect(() => {
setText(yaml.dump(value));
}, [value]);
const delayId = useRef<null | number>(null);
const delayedUpdate = (update: string) => {
setText(update)
if (delayId.current) {
window.clearTimeout(delayId.current);
delayId.current = null;
}
delayId.current = window.setTimeout(() => {
onChange(yaml.load(update) as any)
}, 1000);
const [text, setText] = useState("");
useEffect(() => {
setText(yaml.dump(value));
}, [value]);
const delayId = useRef<null | number>(null);
const delayedUpdate = (update: string) => {
setText(update)
if (delayId.current) {
window.clearTimeout(delayId.current);
delayId.current = null;
}
return <InputTextArea
label={label}
value={text}
onChange={delayedUpdate}
resizable={resizable}
/>
}
delayId.current = window.setTimeout(() => {
onChange(yaml.load(update) as any)
}, 1000);
}
return <InputTextArea
label={label}
value={text}
onChange={delayedUpdate}
resizable={resizable}
/>
}
@@ -1,4 +1,3 @@
import InputYaml from "components/Inputs/InputYaml";
import InputText from "components/Inputs/InputText";
import { ChooseAction } from "types/automations/actions";
import { OptionManager, updateActionData } from './OptionManager';
@@ -1,4 +1,4 @@
import { useEffect, useState } from 'react';
import { useState } from 'react';
import { AutomationNode, AutomationNodeTypes } from 'types/automations';
import { AutomationNodeSubtype } from 'types/automations';
import { getOptionManager } from './getOptionManager';
@@ -206,7 +206,7 @@ Multinode.args = {
entity_id: "light.kitchen"
}
}
}
} as any
]
}