ported parts of node editor
This commit is contained in:
1 parent
0764feb432
commit
59542abad7
11 files changed
+227
-75
No files matched your search
@@ -0,0 +1,53 @@
|
||||
import { AutomationNodeSubtype, AutomationNodeTypes } from "types/automations";
|
||||
|
||||
|
||||
const actionTypes = [
|
||||
'choose',
|
||||
'device',
|
||||
'event',
|
||||
'repeat',
|
||||
'service',
|
||||
'wait',
|
||||
] as AutomationNodeSubtype<'action'>[];
|
||||
|
||||
const conditionTypes = [
|
||||
'and',
|
||||
'not',
|
||||
'numeric_state',
|
||||
'or',
|
||||
'state',
|
||||
'template',
|
||||
'time',
|
||||
'trigger',
|
||||
'zone',
|
||||
] as AutomationNodeSubtype<'condition'>[];
|
||||
|
||||
const triggerTypes = [
|
||||
'device',
|
||||
'event',
|
||||
'homeassistant',
|
||||
'mqtt',
|
||||
'numeric_state',
|
||||
'state',
|
||||
'tag',
|
||||
'template',
|
||||
'time',
|
||||
'time_pattern',
|
||||
'webhook',
|
||||
'zone',
|
||||
] as AutomationNodeSubtype<'trigger'>[];
|
||||
|
||||
export const getSubTypeList = <T extends AutomationNodeTypes>(
|
||||
nodeType: T
|
||||
): AutomationNodeSubtype<T>[] => {
|
||||
if (nodeType === 'action') {
|
||||
return actionTypes as any;
|
||||
} else if (nodeType === 'condition') {
|
||||
return conditionTypes as any;
|
||||
} else if (nodeType === 'trigger') {
|
||||
return triggerTypes as any;
|
||||
} else if (nodeType === 'sequence') {
|
||||
return actionTypes.concat(conditionTypes) as any;
|
||||
}
|
||||
return [];
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import React from "react";
|
||||
import { ComponentMeta, ComponentStory } from '@storybook/react';
|
||||
import { NodeEditor } from ".";
|
||||
import { usePageTheme } from "styles/page";
|
||||
|
||||
|
||||
export default {
|
||||
title: 'NodeEditor',
|
||||
component: NodeEditor,
|
||||
parameters: { actions: { argTypesRegex: '^on.*' } },
|
||||
args: {
|
||||
nodeType: 'sequence',
|
||||
subType: 'and',
|
||||
}
|
||||
} as ComponentMeta<typeof NodeEditor>
|
||||
|
||||
export const Basic: ComponentStory<typeof NodeEditor> = props => {
|
||||
const { classes } = usePageTheme({});
|
||||
return <div className={classes.page}>
|
||||
<NodeEditor {...props} />
|
||||
</div>
|
||||
};
|
||||
@@ -0,0 +1,57 @@
|
||||
import { Button } from "components/Inputs/Button";
|
||||
import { useState, useEffect } from "react";
|
||||
import { AutomationNodeTypes, AutomationNode, AutomationNodeSubtype } from "types/automations";
|
||||
import { useNodeEditorStyles } from './styles';
|
||||
import { getSubTypeList } from './constants';
|
||||
import InputList from "components/Inputs/InputList";
|
||||
|
||||
export interface Props<T extends AutomationNodeTypes> {
|
||||
nodeType: T,
|
||||
subType: AutomationNodeSubtype<T>,
|
||||
onClose: () => void,
|
||||
onUpdate: (node: AutomationNode[T]) => void,
|
||||
}
|
||||
export function NodeEditor<T extends AutomationNodeTypes>({
|
||||
nodeType,
|
||||
subType,
|
||||
onClose,
|
||||
onUpdate,
|
||||
}: Props<T>) {
|
||||
const { classes } = useNodeEditorStyles({});
|
||||
const currentSubTypeList = getSubTypeList(nodeType);
|
||||
const [selectedSubType, setSubType] = useState<AutomationNodeSubtype>(subType);
|
||||
// const stateManager = new StateManager(node_type, selectedSubType);
|
||||
|
||||
// useEffect(() => {
|
||||
// if (stateManager.nodeType !== node_type || stateManager.nodeSubtype !== selectedSubType) {
|
||||
// stateManager.swapBaseState(node_type, selectedSubType)
|
||||
// }
|
||||
// }, [node_type, selectedSubType]);
|
||||
|
||||
return <div className={classes.root}>
|
||||
<div className={classes.background} onClick={() => onClose()}></div>
|
||||
<div className={classes.inner} onClick={e => e.preventDefault()}>
|
||||
<div className={classes.title}>
|
||||
Create {nodeType[0].toUpperCase()}{nodeType.slice(1)}
|
||||
</div>
|
||||
<div className={classes.body}>
|
||||
<InputList
|
||||
label="Type:"
|
||||
options={currentSubTypeList}
|
||||
current={selectedSubType}
|
||||
onChange={setSubType}
|
||||
/>
|
||||
{/*{stateManager.renderOptionList()} */}
|
||||
</div>
|
||||
<div className={classes.footer}>
|
||||
<Button onClick={() => onClose()}>Close</Button>
|
||||
<Button
|
||||
// onClick={() => onUpdate(stateManager.state)}
|
||||
// disabled={!stateManager.isReady}
|
||||
>
|
||||
Save
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
import Color from "chroma-js";
|
||||
import { createAppUseStyles } from "styles/theme";
|
||||
|
||||
export const useNodeEditorStyles = createAppUseStyles<{
|
||||
|
||||
}>(theme => ({
|
||||
root: {
|
||||
position: 'absolute',
|
||||
display: 'flex',
|
||||
justifyContent: 'center',
|
||||
alignItems: 'center',
|
||||
width: '100vw',
|
||||
height: '100vh',
|
||||
left: '0',
|
||||
top: '0',
|
||||
},
|
||||
background: {
|
||||
position: 'absolute',
|
||||
zIndex: 0,
|
||||
width: '100vw',
|
||||
height: '100vw',
|
||||
backgroundColor: Color(theme.secondary).alpha(0.5).hex(),
|
||||
},
|
||||
inner: {
|
||||
zIndex: 1,
|
||||
maxWidth: '80%',
|
||||
maxHeight: '60%',
|
||||
minHeight: '200px',
|
||||
minWidth: '200px',
|
||||
borderRadius: '20px',
|
||||
padding: '15px',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
backgroundColor: theme.primary,
|
||||
borderSize: '1px',
|
||||
borderStyle: 'solid',
|
||||
borderColor: theme.primaryAccent,
|
||||
},
|
||||
title: {
|
||||
textAlign: 'center',
|
||||
padding: 10,
|
||||
fontWeight: 'bold',
|
||||
color: theme.secondaryAccent,
|
||||
},
|
||||
body: {
|
||||
flexGrow: 1
|
||||
},
|
||||
footer: {
|
||||
display: 'flex',
|
||||
flexDirection: 'row',
|
||||
justifyContent: 'space-between',
|
||||
alignItems: 'center',
|
||||
}
|
||||
}))
|
||||
Reference in new issue
Block a user