From 59542abad74b5f0c4c06c1cf13ba0ee3f75d0b91 Mon Sep 17 00:00:00 2001 From: Ari Sosnovsky Date: Wed, 1 Dec 2021 17:07:43 -0500 Subject: [PATCH] ported parts of node editor --- webapp/src/components/Inputs/Button.tsx | 19 ------- webapp/src/components/Inputs/InputList.tsx | 44 +++++++------- webapp/src/components/Inputs/styles.ts | 7 ++- webapp/src/components/NodeEditor/constants.ts | 53 +++++++++++++++++ .../components/NodeEditor/index.stories.tsx | 22 +++++++ webapp/src/components/NodeEditor/index.tsx | 57 +++++++++++++++++++ webapp/src/components/NodeEditor/styles.ts | 54 ++++++++++++++++++ webapp/src/types/automations/actions.ts | 10 +--- webapp/src/types/automations/conditions.ts | 1 + webapp/src/types/automations/index.ts | 14 +++-- webapp/src/types/automations/triggers.ts | 21 +------ 11 files changed, 227 insertions(+), 75 deletions(-) create mode 100644 webapp/src/components/NodeEditor/constants.ts create mode 100644 webapp/src/components/NodeEditor/index.stories.tsx create mode 100644 webapp/src/components/NodeEditor/index.tsx create mode 100644 webapp/src/components/NodeEditor/styles.ts diff --git a/webapp/src/components/Inputs/Button.tsx b/webapp/src/components/Inputs/Button.tsx index d23e157..eb3aa53 100644 --- a/webapp/src/components/Inputs/Button.tsx +++ b/webapp/src/components/Inputs/Button.tsx @@ -1,25 +1,6 @@ import { ButtonHTMLAttributes, FC } from "react"; -import { createAppUseStyles } from "styles/theme"; import { useButtonStyles } from "./styles"; -// const useButtonStyles = createAppUseStyles(theme => ({ -// button: { -// backgroundColor: theme.secondary, -// color: theme.primaryAccent, -// borderColor: theme.primaryAccent, -// borderStyle: 'solid', -// borderWidth: 1, -// padding: '2.5%', -// marginLeft: '5%', -// marginRight: '5%', -// borderRadius: '5px', -// cursor: 'pointer', -// '&:hover': { -// backgroundColor: theme.primary, -// borderColor: theme.secondaryAccent, -// } -// } -// })) export const Button: FC> = props => { const { classes } = useButtonStyles({}); return + + + + +} diff --git a/webapp/src/components/NodeEditor/styles.ts b/webapp/src/components/NodeEditor/styles.ts new file mode 100644 index 0000000..0b00026 --- /dev/null +++ b/webapp/src/components/NodeEditor/styles.ts @@ -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', + } +})) diff --git a/webapp/src/types/automations/actions.ts b/webapp/src/types/automations/actions.ts index c9f5e3d..30ffadc 100644 --- a/webapp/src/types/automations/actions.ts +++ b/webapp/src/types/automations/actions.ts @@ -52,12 +52,4 @@ export type AutomationAction = | DeviceAction | ChooseAction ; -export const ActionTypes = [ - 'Service', - 'Repeat', - 'Wait', - 'Event', - 'Device', - 'Choose' -] as const; -export type ActionType = typeof ActionTypes[number]; +export type ActionType = AutomationAction['action']; diff --git a/webapp/src/types/automations/conditions.ts b/webapp/src/types/automations/conditions.ts index 26b7e5c..f4c86a0 100644 --- a/webapp/src/types/automations/conditions.ts +++ b/webapp/src/types/automations/conditions.ts @@ -48,3 +48,4 @@ export type AutomationCondition = | TriggerCondition | ZoneCondition ; +export type ConditionType = AutomationCondition['condition']; diff --git a/webapp/src/types/automations/index.ts b/webapp/src/types/automations/index.ts index f804c44..be2c5bf 100644 --- a/webapp/src/types/automations/index.ts +++ b/webapp/src/types/automations/index.ts @@ -1,6 +1,6 @@ -import { AutomationAction } from "./actions"; -import { AutomationCondition } from "./conditions"; -import { AutomationTrigger } from "./triggers"; +import { ActionType, AutomationAction } from "./actions"; +import { AutomationCondition, ConditionType } from "./conditions"; +import { AutomationTrigger, TriggerType } from "./triggers"; export interface AutomationMetadata { @@ -23,4 +23,10 @@ type AutomationNodeMapping = { "sequence": AutomationSequenceNode; } export type AutomationNodeTypes = keyof AutomationNodeMapping; -export type AutomationNode = AutomationNodeMapping[N]; \ No newline at end of file +export type AutomationNode = AutomationNodeMapping[N]; +export type AutomationNodeSubtype = + T extends 'trigger' ? TriggerType : + T extends 'action' ? ActionType : + T extends 'condtion' ? ConditionType : + T extends 'sequence' ? ConditionType | ActionType : + never; diff --git a/webapp/src/types/automations/triggers.ts b/webapp/src/types/automations/triggers.ts index 9ab5ccf..47c9440 100644 --- a/webapp/src/types/automations/triggers.ts +++ b/webapp/src/types/automations/triggers.ts @@ -74,9 +74,6 @@ export interface AutomationTriggerDevice extends AutomationTriggerBase { type: string; subtype: string; } -export interface AutomationTriggerGeneric extends AutomationTriggerBase { - platform: string; -} export type AutomationTrigger = | AutomationTriggerEvent | AutomationTriggerHA @@ -90,21 +87,5 @@ export type AutomationTrigger = | AutomationTriggerWebhook | AutomationTriggerZone | AutomationTriggerDevice - | AutomationTriggerGeneric ; -export const triggerTypes = [ - 'Event', - 'Home Assistant', - 'MQTT', - 'Numeric State', - 'State', - 'Tag', - 'Template', - 'Time', - 'Time Pattern', - 'Webhook', - 'Zone', - 'Device', - 'Generic', -] as const; -export type TriggerType = typeof triggerTypes[number]; \ No newline at end of file +export type TriggerType = AutomationTrigger['platform'];