moved old state handler code
This commit is contained in:
1 parent
d0bc01d2f1
commit
54e628481c
19 files changed
+642
-55
No files matched your search
@@ -21,7 +21,6 @@ const commonInputStyle = (theme: AppTheme) => ({
|
||||
"&:disabled": {
|
||||
backgroundColor: '#403f3f',
|
||||
borderColor: '#403f3f',
|
||||
color: '#403f3faa',
|
||||
cursor: 'not-allowed',
|
||||
},
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import InputYaml from "components/Inputs/InputYaml";
|
||||
import InputText from "components/Inputs/InputText";
|
||||
import { ChooseAction } from "types/automations/actions";
|
||||
import { BaseOptionManager, updateActionData } from './BaseOptionManager';
|
||||
|
||||
|
||||
export default class ActionChooseState extends BaseOptionManager<ChooseAction> {
|
||||
defaultState = () => ({
|
||||
$smType: 'action',
|
||||
action: 'choose',
|
||||
action_data: {
|
||||
alias: "Choose",
|
||||
default: [],
|
||||
choose: [],
|
||||
}
|
||||
} as ChooseAction)
|
||||
isReady(state: ChooseAction): boolean {
|
||||
return state.action_data.alias !== ''
|
||||
}
|
||||
renderOptionList(state: ChooseAction): JSX.Element {
|
||||
const update = updateActionData(state, this.setState);
|
||||
return <div className="state-manager-options">
|
||||
<InputText
|
||||
label="Description"
|
||||
value={state.action_data.alias ?? ""}
|
||||
onChange={alias => update({ alias })}
|
||||
/>
|
||||
<InputYaml
|
||||
label="Choose Sequence"
|
||||
value={state.action_data.choose}
|
||||
onChange={choose => update({ choose })}
|
||||
/>
|
||||
<InputYaml
|
||||
label="Default Sequence"
|
||||
value={state.action_data.default}
|
||||
onChange={d => update({ default: d })}
|
||||
/>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
import InputText from "components/Inputs/InputText";
|
||||
import { DeviceAction } from "types/automations/actions";
|
||||
import { BaseOptionManager, updateActionData } from './BaseOptionManager';
|
||||
|
||||
|
||||
export default class ActionDeviceState extends BaseOptionManager<DeviceAction> {
|
||||
defaultState = () => ({
|
||||
$smType: 'action',
|
||||
action: 'device',
|
||||
action_data: {
|
||||
alias: "Device",
|
||||
type: "",
|
||||
entity_id: "",
|
||||
device_id: "",
|
||||
domain: "",
|
||||
}
|
||||
} as DeviceAction)
|
||||
isReady(state: DeviceAction): boolean {
|
||||
return state.action_data.alias !== '' &&
|
||||
state.action_data.type !== "" &&
|
||||
state.action_data.entity_id !== "" &&
|
||||
state.action_data.device_id !== "" &&
|
||||
state.action_data.domain !== ""
|
||||
}
|
||||
renderOptionList(state: DeviceAction): JSX.Element {
|
||||
const update = updateActionData(state, this.setState);
|
||||
return <div className="state-manager-options">
|
||||
<InputText
|
||||
label="Description"
|
||||
value={state.action_data.alias ?? ""}
|
||||
onChange={alias => update({ alias })}
|
||||
/>
|
||||
<InputText
|
||||
textBoxFor="device_id"
|
||||
label="Device"
|
||||
value={state.action_data.device_id}
|
||||
onChange={device_id => update({ device_id })}
|
||||
/>
|
||||
<InputText
|
||||
textBoxFor="type"
|
||||
label="Action"
|
||||
value={state.action_data.type}
|
||||
onChange={type => update({ type })}
|
||||
/>
|
||||
<InputText
|
||||
textBoxFor="entity_id"
|
||||
label="Entity ID"
|
||||
value={state.action_data.entity_id ?? ""}
|
||||
onChange={entity_id => update({ entity_id, domain: entity_id.split('.')[0] })}
|
||||
/>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import InputText from "components/Inputs/InputText";
|
||||
import { ServiceAction } from "types/automations/actions";
|
||||
import { BaseOptionManager, updateActionData } from './BaseOptionManager';
|
||||
|
||||
|
||||
export default class ActionCallServiceState extends BaseOptionManager<ServiceAction> {
|
||||
defaultState = () => ({
|
||||
$smType: 'action',
|
||||
action: 'service',
|
||||
action_data: {
|
||||
service: "",
|
||||
target: "",
|
||||
data: {},
|
||||
}
|
||||
} as ServiceAction)
|
||||
isReady(state: ServiceAction): boolean {
|
||||
const { service, alias, target } = state.action_data;
|
||||
return service !== '' &&
|
||||
alias !== '' &&
|
||||
target !== ''
|
||||
}
|
||||
renderOptionList(state: ServiceAction): JSX.Element {
|
||||
const { service, alias = "", target } = state.action_data;
|
||||
const update = updateActionData(state, this.setState);
|
||||
return <div className="state-manager-options">
|
||||
<InputText
|
||||
label="Description"
|
||||
value={alias}
|
||||
onChange={alias => update({ alias })}
|
||||
/>
|
||||
<InputText
|
||||
textBoxFor="service"
|
||||
label="Service"
|
||||
value={service}
|
||||
onChange={service => update({ service })}
|
||||
/>
|
||||
<InputText
|
||||
label="Target"
|
||||
value={target}
|
||||
onChange={target => update({ target })}
|
||||
/>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
import { AutomationAction } from 'types/automations/actions';
|
||||
import { AutomationCondition } from 'types/automations/conditions';
|
||||
export abstract class BaseOptionManager<T> {
|
||||
abstract defaultState(): T ;
|
||||
abstract isReady(s: T): boolean;
|
||||
abstract renderOptionList(s: T): JSX.Element;
|
||||
|
||||
constructor(public setState: (s: T) => void) { }
|
||||
}
|
||||
|
||||
|
||||
export const updateConditionData = <T extends AutomationCondition>(
|
||||
setState: (s: T) => void
|
||||
) => (
|
||||
state: T,
|
||||
data: Partial<T['condition_data']>,
|
||||
) => setState({
|
||||
...state,
|
||||
condition_data: {
|
||||
...state.condition_data,
|
||||
...data,
|
||||
},
|
||||
})
|
||||
|
||||
export const updateActionData = <T extends AutomationAction>(
|
||||
state: T,
|
||||
setState: (s: T) => void
|
||||
) => (
|
||||
data: Partial<T['action_data']>,
|
||||
) => setState({
|
||||
...state,
|
||||
action_data: {
|
||||
...state.action_data,
|
||||
...data,
|
||||
},
|
||||
})
|
||||
@@ -0,0 +1,51 @@
|
||||
import InputYaml from "components/Inputs/InputYaml";
|
||||
import InputText from "components/Inputs/InputText";
|
||||
import { BaseOptionManager } from "./BaseOptionManager";
|
||||
import { LogicCondition } from "types/automations/conditions";
|
||||
import InputList from "components/Inputs/InputList";
|
||||
|
||||
|
||||
export default class ConditionLogicState extends BaseOptionManager<LogicCondition> {
|
||||
defaultState = () => ({
|
||||
$smType: 'condition',
|
||||
condition: 'and',
|
||||
condition_data: {
|
||||
alias: "",
|
||||
conditions: [],
|
||||
}
|
||||
} as LogicCondition)
|
||||
isReady(state: LogicCondition): boolean {
|
||||
const { alias, conditions } = state.condition_data;
|
||||
return alias !== '' &&
|
||||
conditions?.length > 0;
|
||||
}
|
||||
renderOptionList(state: LogicCondition): JSX.Element {
|
||||
const { alias = "", conditions } = state.condition_data;
|
||||
return <div className="state-manager-options">
|
||||
<InputText
|
||||
label="Description"
|
||||
value={alias}
|
||||
onChange={a => this.setState({
|
||||
...state, condition_data: {
|
||||
alias: a, conditions
|
||||
}
|
||||
})}
|
||||
/>
|
||||
<InputList
|
||||
label="Condition"
|
||||
current={state.condition}
|
||||
options={['and', 'or', 'not']}
|
||||
onChange={(condition: any) => this.setState({ ...state, condition })}
|
||||
/>
|
||||
<InputYaml
|
||||
label="Sequence"
|
||||
value={conditions}
|
||||
onChange={c => this.setState({
|
||||
...state, condition_data: {
|
||||
alias, conditions: c
|
||||
}
|
||||
})}
|
||||
/>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
import InputText from "components/Inputs/InputText";
|
||||
import { BaseOptionManager, updateConditionData } from './BaseOptionManager';
|
||||
import { NumericCondition } from "types/automations/conditions";
|
||||
|
||||
|
||||
export default class ConditionNumStateState extends BaseOptionManager<NumericCondition> {
|
||||
defaultState = () => ({
|
||||
$smType: 'condition',
|
||||
condition_data: {
|
||||
alias: "",
|
||||
entity_id: '',
|
||||
// above: '',
|
||||
// below: '',
|
||||
// attribute: '',
|
||||
value_template: '',
|
||||
},
|
||||
condition: 'numeric_state',
|
||||
} as NumericCondition)
|
||||
isReady(state: NumericCondition): boolean {
|
||||
const { alias, entity_id, value_template } = state.condition_data;
|
||||
return alias !== '' &&
|
||||
entity_id !== '' &&
|
||||
value_template !== '';
|
||||
}
|
||||
renderOptionList(state: NumericCondition): JSX.Element {
|
||||
const { alias = "", entity_id, value_template } = state.condition_data;
|
||||
return <div className="state-manager-options">
|
||||
<InputText
|
||||
label="Description"
|
||||
value={alias}
|
||||
onChange={alias => updateConditionData(this.setState)(state, {
|
||||
alias
|
||||
})}
|
||||
/>
|
||||
<InputText
|
||||
textBoxFor="entity_id"
|
||||
label="Entity ID"
|
||||
value={entity_id}
|
||||
onChange={entity_id => updateConditionData(this.setState)(state, {
|
||||
entity_id
|
||||
})}
|
||||
/>
|
||||
<InputText
|
||||
label="Template"
|
||||
value={value_template ?? ""}
|
||||
onChange={value_template => updateConditionData(this.setState)(state, {
|
||||
value_template
|
||||
})}
|
||||
/>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { BaseOptionManager } from "./BaseOptionManager";
|
||||
|
||||
|
||||
export default class Generic extends BaseOptionManager<any> {
|
||||
defaultState = () => ({})
|
||||
isReady(state: any): boolean {
|
||||
return true;
|
||||
}
|
||||
renderOptionList(state: any): JSX.Element {
|
||||
return <div className="state-manager-options">
|
||||
<b>THIS IS NOT SUPPORTED YET!</b>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import InputBoolean from "../../components/InputBoolean";
|
||||
import InputYaml from "../../components/InputYaml";
|
||||
import InputNumber from "../../components/InputNumber";
|
||||
import InputText from "../../components/InputText";
|
||||
import { FireEventScript } from "../types/script";
|
||||
import { BaseOptionManager } from "./BaseOptionManager";
|
||||
|
||||
|
||||
export default class ScriptEventState extends BaseOptionManager<FireEventScript> {
|
||||
defaultState = () => ({
|
||||
alias: "Fire Event",
|
||||
event: "",
|
||||
event_data: {},
|
||||
})
|
||||
isReady(state: FireEventScript): boolean {
|
||||
return state.alias !== '' &&
|
||||
state.event !== ""
|
||||
}
|
||||
renderOptionList(state: FireEventScript): JSX.Element {
|
||||
return <div className="state-manager-options">
|
||||
<InputText
|
||||
label="Description"
|
||||
value={state.alias}
|
||||
onChange={alias => this.setState({ ...state, alias })}
|
||||
/>
|
||||
<InputText
|
||||
textBoxFor="event"
|
||||
label="Event"
|
||||
value={state.event}
|
||||
onChange={event => this.setState({ ...state, event })}
|
||||
/>
|
||||
<InputYaml
|
||||
label="Event Data"
|
||||
value={state.event_data}
|
||||
onChange={event_data => this.setState({ ...state, event_data })}
|
||||
/>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import InputNumber from "../../components/InputNumber";
|
||||
import InputText from "../../components/InputText";
|
||||
import InputYaml from "../../components/InputYaml";
|
||||
import { RepeatScript } from "../types/script";
|
||||
import { BaseOptionManager } from "./BaseOptionManager";
|
||||
|
||||
|
||||
export default class ScriptRepeatState extends BaseOptionManager<RepeatScript> {
|
||||
defaultState = () => ({
|
||||
alias: "Repeat",
|
||||
repeat: {
|
||||
count: 1,
|
||||
sequence: [],
|
||||
}
|
||||
})
|
||||
isReady(state: RepeatScript): boolean {
|
||||
return state.alias !== '' &&
|
||||
state?.repeat?.sequence.length > 0
|
||||
}
|
||||
renderOptionList(state: RepeatScript): JSX.Element {
|
||||
return <div className="state-manager-options">
|
||||
<InputText
|
||||
label="Description"
|
||||
value={state.alias}
|
||||
onChange={alias => this.setState({ ...state, alias })}
|
||||
/>
|
||||
<InputNumber
|
||||
label="How many times?"
|
||||
value={state?.repeat?.count}
|
||||
onChange={count => this.setState({ ...state, repeat: { ...state.repeat, count } })}
|
||||
/>
|
||||
<InputYaml
|
||||
label="Sequence"
|
||||
value={state?.repeat?.sequence ?? {}}
|
||||
onChange={sequence => this.setState({ ...state, repeat: { ...state.repeat, sequence } })}
|
||||
/>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import InputBoolean from "../../components/InputBoolean";
|
||||
import InputNumber from "../../components/InputNumber";
|
||||
import InputText from "../../components/InputText";
|
||||
import { WaitScript } from "../types/script";
|
||||
import { BaseOptionManager } from "./BaseOptionManager";
|
||||
|
||||
|
||||
export default class ScriptWaitState extends BaseOptionManager<WaitScript> {
|
||||
defaultState = () => ({
|
||||
alias: "Wait",
|
||||
wait_template: "",
|
||||
timeout: 0,
|
||||
continue_on_timeout: false,
|
||||
})
|
||||
isReady(state: WaitScript): boolean {
|
||||
return state.alias !== '' &&
|
||||
state.wait_template !== ""
|
||||
}
|
||||
renderOptionList(state: WaitScript): JSX.Element {
|
||||
return <div className="state-manager-options">
|
||||
<InputText
|
||||
label="Description"
|
||||
value={state.alias}
|
||||
onChange={alias => this.setState({ ...state, alias })}
|
||||
/>
|
||||
<InputText
|
||||
textBoxFor="template"
|
||||
label="Template"
|
||||
value={state.wait_template}
|
||||
onChange={wait_template => this.setState({ ...state, wait_template })}
|
||||
/>
|
||||
<InputNumber
|
||||
label="Timeout"
|
||||
value={state.timeout ?? 0}
|
||||
onChange={timeout => this.setState({ ...state, timeout })}
|
||||
/>
|
||||
<InputBoolean
|
||||
label="Continue on Timeout"
|
||||
value={state.continue_on_timeout ?? false}
|
||||
onChange={continue_on_timeout => this.setState({ ...state, continue_on_timeout })}
|
||||
/>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
import { AutomationNodeTypes, AutomationNodeSubtype, AutomationNode } from "types/automations"
|
||||
import ActionChooseState from "./ActionChoose";
|
||||
import ActionDeviceState from "./ActionDevice";
|
||||
import ActionCallServiceState from "./ActionService"
|
||||
import { BaseOptionManager } from "./BaseOptionManager";
|
||||
import Generic from "./Generic";
|
||||
|
||||
|
||||
export const getOptionManager = <T extends AutomationNodeTypes>(
|
||||
nodeType: T,
|
||||
nodeSubtype: AutomationNodeSubtype<T>,
|
||||
) : any => {
|
||||
if ( nodeType === 'action') {
|
||||
switch (nodeSubtype) {
|
||||
case 'service':
|
||||
return ActionCallServiceState;
|
||||
// case "Repeat":
|
||||
// return ScriptRepeatState;
|
||||
// case "Wait":
|
||||
// return ScriptWaitState;
|
||||
// case "Event":
|
||||
// return ScriptEventState;
|
||||
case "device":
|
||||
return ActionDeviceState;
|
||||
case "choose":
|
||||
return ActionChooseState;
|
||||
}
|
||||
}
|
||||
// if (nodeType === 'condition') {
|
||||
// switch (nodeSubtype) {
|
||||
// case 'Logic':
|
||||
// return ConditionLogicState
|
||||
// }
|
||||
// }
|
||||
return Generic
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
import { useState } from 'react';
|
||||
import { AutomationNode, AutomationNodeTypes } from 'types/automations';
|
||||
import { AutomationNodeSubtype } from 'types/automations';
|
||||
import { BaseOptionManager } from './BaseOptionManager';
|
||||
import { getOptionManager } from './getOptionManager';
|
||||
|
||||
|
||||
export const useEditorNodeState = (node: AutomationNode) => {
|
||||
const [state, setState] = useState(node);
|
||||
const nodeType: AutomationNodeTypes = state.$smType ?? 'trigger';
|
||||
const subType: AutomationNodeSubtype =
|
||||
state.$smType === 'action' ? state.action :
|
||||
state.$smType === 'condition' ? state.condition :
|
||||
state.platform;
|
||||
const optionManager: BaseOptionManager<any> = new (getOptionManager(nodeType, subType as any))(setState);
|
||||
return {
|
||||
nodeType,
|
||||
subType,
|
||||
renderOptionList() {
|
||||
return optionManager.renderOptionList(state);
|
||||
},
|
||||
isReady() {
|
||||
return optionManager.isReady(state);
|
||||
},
|
||||
get subTypes(): AutomationNodeSubtype<typeof nodeType>[] {
|
||||
switch (nodeType) {
|
||||
case 'action':
|
||||
return [
|
||||
"service",
|
||||
"repeat",
|
||||
"wait",
|
||||
"device",
|
||||
"choose",
|
||||
]
|
||||
case "condition":
|
||||
return [
|
||||
'or',
|
||||
'and',
|
||||
'not',
|
||||
'numeric_state',
|
||||
'state',
|
||||
'template',
|
||||
'time',
|
||||
'trigger',
|
||||
'zone',
|
||||
]
|
||||
case 'trigger':
|
||||
return [
|
||||
'event',
|
||||
'homeassistant',
|
||||
'mqtt',
|
||||
'numeric_state',
|
||||
'state',
|
||||
'tag',
|
||||
'template',
|
||||
'time',
|
||||
'time_pattern',
|
||||
'webhook',
|
||||
'zone',
|
||||
'device',
|
||||
]
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
},
|
||||
|
||||
setNodeType(newType: AutomationNodeTypes) {
|
||||
if (newType === (node.$smType ?? 'trigger')) {
|
||||
if (node.$smType === 'action') {
|
||||
setState({
|
||||
...state,
|
||||
$smType: 'action',
|
||||
action: node.action
|
||||
} as any)
|
||||
} else if (node.$smType === 'condition') {
|
||||
setState({
|
||||
...state,
|
||||
$smType: 'condition',
|
||||
condition: node.condition
|
||||
} as any)
|
||||
} else {
|
||||
setState({
|
||||
...state,
|
||||
$smType: undefined,
|
||||
platform: node.platform
|
||||
} as any)
|
||||
}
|
||||
} else {
|
||||
setState({
|
||||
...state,
|
||||
$smType: newType === 'trigger' ? undefined : newType,
|
||||
} as any)
|
||||
}
|
||||
},
|
||||
setSubType(newSubType: AutomationNodeSubtype<typeof nodeType>) {
|
||||
if (state.$smType === 'action') {
|
||||
setState({
|
||||
...state,
|
||||
action: newSubType,
|
||||
} as any)
|
||||
} else if (state.$smType === 'condition') {
|
||||
setState({
|
||||
...state,
|
||||
condition: newSubType,
|
||||
} as any)
|
||||
} else {
|
||||
setState({
|
||||
...state,
|
||||
platform: newSubType,
|
||||
} as any)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import { AutomationNodeSubtype, AutomationNodeTypes } from "types/automations";
|
||||
import { AutomationNode } from '../../types/automations/index';
|
||||
|
||||
|
||||
const actionTypes = [
|
||||
@@ -39,15 +40,25 @@ const triggerTypes = [
|
||||
|
||||
export const getSubTypeList = <T extends AutomationNodeTypes>(
|
||||
nodeType: T
|
||||
): AutomationNodeSubtype<T>[] => {
|
||||
): Array<AutomationNodeSubtype<T>| 'condition'> => {
|
||||
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 [];
|
||||
}
|
||||
|
||||
export const getNodeSubType = <T extends AutomationNodeTypes>(
|
||||
node: AutomationNode<T>
|
||||
): AutomationNodeSubtype<T> => {
|
||||
if (node.$smType === 'action') {
|
||||
return node.action as any;
|
||||
} else if(node.$smType === 'condition') {
|
||||
return node.condition as any;
|
||||
} else {
|
||||
return node.platform as any;
|
||||
}
|
||||
}
|
||||
@@ -8,15 +8,30 @@ export default {
|
||||
title: 'NodeEditor',
|
||||
component: NodeEditor,
|
||||
parameters: { actions: { argTypesRegex: '^on.*' } },
|
||||
args: {
|
||||
nodeType: 'sequence',
|
||||
subType: 'and',
|
||||
}
|
||||
args: {}
|
||||
} as ComponentMeta<typeof NodeEditor>
|
||||
|
||||
export const Basic: ComponentStory<typeof NodeEditor> = props => {
|
||||
const Base: ComponentStory<typeof NodeEditor> = props => {
|
||||
const { classes } = usePageTheme({});
|
||||
return <div className={classes.page}>
|
||||
<NodeEditor {...props} />
|
||||
</div>
|
||||
};
|
||||
export const Action = Base.bind({})
|
||||
Action.args = {
|
||||
...Action.args,
|
||||
node: {
|
||||
$smType: 'action',
|
||||
action: 'service',
|
||||
action_data: {
|
||||
'data': {},
|
||||
'service': '',
|
||||
'target': '',
|
||||
}
|
||||
}
|
||||
}
|
||||
export const SingleOption = Action.bind({})
|
||||
SingleOption.args = {
|
||||
...Action.args,
|
||||
allowedTypes: ['action'],
|
||||
}
|
||||
@@ -1,56 +1,50 @@
|
||||
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 { 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<T extends AutomationNodeTypes> {
|
||||
nodeType: T,
|
||||
subType: AutomationNodeSubtype<T>,
|
||||
onClose: () => void,
|
||||
onUpdate: (node: AutomationNode[T]) => void,
|
||||
|
||||
|
||||
|
||||
export interface Props {
|
||||
node: AutomationNode
|
||||
allowedTypes?: Array<keyof AutomationNodeMapping>;
|
||||
}
|
||||
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]);
|
||||
export const NodeEditor: FC<Props> = ({
|
||||
node,
|
||||
allowedTypes = ["action", "condition", "trigger"]
|
||||
}) => {
|
||||
const { classes } = useNodeEditorStyles({});
|
||||
const state = useEditorNodeState(node);
|
||||
|
||||
return <div className={classes.root}>
|
||||
<div className={classes.background} onClick={() => onClose()}></div>
|
||||
<div className={classes.inner} onClick={e => e.preventDefault()}>
|
||||
<div className={classes.background} />
|
||||
<div className={classes.inner}>
|
||||
<div className={classes.title}>
|
||||
Create {nodeType[0].toUpperCase()}{nodeType.slice(1)}
|
||||
|
||||
</div>
|
||||
<div className={classes.body}>
|
||||
{allowedTypes.length > 1 ? <InputList
|
||||
label="Type"
|
||||
current={state.nodeType}
|
||||
options={allowedTypes}
|
||||
onChange={state.setNodeType}
|
||||
/> : <span>{state.nodeType}</span>}
|
||||
<InputList
|
||||
label="Type:"
|
||||
options={currentSubTypeList}
|
||||
current={selectedSubType}
|
||||
onChange={setSubType}
|
||||
label={`${state.nodeType} type`}
|
||||
current={state.subType as any}
|
||||
options={state.subTypes}
|
||||
onChange={state.setSubType}
|
||||
/>
|
||||
{/*{stateManager.renderOptionList()} */}
|
||||
{state.renderOptionList()}
|
||||
</div>
|
||||
<div className={classes.footer}>
|
||||
<Button onClick={() => onClose()}>Close</Button>
|
||||
<Button
|
||||
// onClick={() => onUpdate(stateManager.state)}
|
||||
// disabled={!stateManager.isReady}
|
||||
>
|
||||
Save
|
||||
</Button>
|
||||
<Button>Close</Button>
|
||||
<Button disabled={!state.isReady()}>Save</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -43,6 +43,7 @@ export const useNodeEditorStyles = createAppUseStyles<{
|
||||
color: theme.secondaryAccent,
|
||||
},
|
||||
body: {
|
||||
overflow: 'auto',
|
||||
flexGrow: 1
|
||||
},
|
||||
footer: {
|
||||
|
||||
Reference in new issue
Block a user