diff --git a/web/src/components/ConditionEditor/ConditionNode.tsx b/web/src/components/ConditionEditor/ConditionNode.tsx index 9679d06..59f6000 100644 --- a/web/src/components/ConditionEditor/ConditionNode.tsx +++ b/web/src/components/ConditionEditor/ConditionNode.tsx @@ -4,6 +4,7 @@ import { getConditionDefaultValues } from "~/automations/defaults"; import { AutomationCondition } from "~/automations/types/conditions"; import { CheckMarkIcon, PencilIcon } from "~/icons/icons"; import InputList from "../Inputs/InputList"; +import InputYaml from "../Inputs/InputYaml"; import { getEditor } from "./editorRender"; import { useStyles } from "./style"; import { getViewer } from "./viewRender"; @@ -29,6 +30,7 @@ export const ConditionNode: FC<{ }) => { // state const [internalDisplayMode, setInternalDisplayMode] = useState(true); + const [yamlMode, setYamlMode] = useState(false); // alias const effectiveDM = displayMode && internalDisplayMode; const onAddChild = () => { @@ -74,7 +76,6 @@ export const ConditionNode: FC<{ } else if (condition.condition ==='or') { hasChildren = true } - console.log({condition: condition.condition, hasChildren}) const {classes} = useStyles({ hasChildren }); // components @@ -86,6 +87,7 @@ export const ConditionNode: FC<{
{/* {condition.condition.replace('_', ' ')} */} - } + {!yamlMode && + }
- {childrenConditions} - {hasChildren &&
+ {yamlMode && onUpdate({ + ...condition, + condition_data: update as any + })} + resizable + />} + {!yamlMode && childrenConditions} + {!yamlMode && hasChildren &&
}
diff --git a/web/src/components/ConditionEditor/style.ts b/web/src/components/ConditionEditor/style.ts index 08f1d0b..529eaf4 100644 --- a/web/src/components/ConditionEditor/style.ts +++ b/web/src/components/ConditionEditor/style.ts @@ -27,8 +27,7 @@ export const useStyles = createAppUseStyles<{ position: 'relative', display: 'flex', flexDirection: hasChildren? 'column' : 'row', - // width: hasChildren? '100%' : undefined, - // height: hasChildren? '100%' : undefined, + alignItems: hasChildren ? undefined : 'flex-start', }), title: ({hasChildren}) => ({ display: 'flex', @@ -101,11 +100,26 @@ export const useStyles = createAppUseStyles<{ border: `1px solid ${theme.primaryAccent}`, borderBottomRightRadius: hasChildren ? 10 : 0, borderBottomLeftRadius: hasChildren ? 10 : 0, + minHeight: hasChildren ? undefined : '100%' }), addBtnContainer: { display: 'flex', justifyContent: 'center', }, + yamlBtn: { + backgroundColor: theme.secondary, + borderWidth: 1, + borderStyle: 'solid', + borderColor: theme.secondaryAccent, + color: theme.secondaryAccent, + paddingLeft: 20, + paddingRight: 20, + cursor: 'pointer', + "&:hover": { + backgroundColor: Color(theme.primary).brighten().hex(), + fill: Color(theme.primaryAccent).brighten().hex(), + }, + }, addBtn: { backgroundColor: theme.secondary, borderWidth: 1, @@ -115,7 +129,6 @@ export const useStyles = createAppUseStyles<{ borderRadius: 5, marginTop: 5, marginBottom: 5, - marginRight: 5, paddingLeft: 20, paddingRight: 20, cursor: 'pointer', diff --git a/web/src/components/Inputs/InputList.tsx b/web/src/components/Inputs/InputList.tsx index f0e9f33..e52307a 100644 --- a/web/src/components/Inputs/InputList.tsx +++ b/web/src/components/Inputs/InputList.tsx @@ -1,12 +1,11 @@ -import { useState } from "react"; import InputWrapper from "./InputWrapper"; -import { useInputTextStyles } from "./styles"; +import { useInputListStyles } from "./styles"; export interface Props { current: T; options: readonly T[]; - onChange: (n: string) => void; + onChange: (n: T) => void; id?: string; className?: string; label: string; @@ -15,8 +14,8 @@ export default function InputList({ current, options, onChange, label, ...selattr }: Props) { - const {classes} = useInputTextStyles({}); - return + const {classes} = useInputListStyles({}); + return { - onChange(e.target.value) - }} - onFocus={(e: any) => textBoxFor && tooltip.setFocus( - e.target.getBoundingClientRect(), - { - searchObject: textBoxFor, - searchText: value, - filterObjects: additionalTooltipFilters, - }, - onChangeWrapped - )} - />:
- {value} -
} - setIsEditing(!isEditing)} className={classes.pencil}/> - setIsEditing(!isEditing)} className={classes.checkmark}/> -
-} \ No newline at end of file diff --git a/web/src/components/Inputs/InputWrapper.tsx b/web/src/components/Inputs/InputWrapper.tsx index 1aa4476..fa1be39 100644 --- a/web/src/components/Inputs/InputWrapper.tsx +++ b/web/src/components/Inputs/InputWrapper.tsx @@ -5,9 +5,10 @@ import { useInputWrapperStyles } from "./styles"; export interface Props { label: string; labelSize?: 'normal' | 'small'; + noMargin?: boolean; } -export default function InputWrapper({label, children, labelSize='normal'}: PropsWithChildren) { - const {classes} = useInputWrapperStyles({labelSize}) +export default function InputWrapper({label, children, labelSize='normal', noMargin=false}: PropsWithChildren) { + const {classes} = useInputWrapperStyles({labelSize, noMargin}) return
{children} diff --git a/web/src/components/Inputs/InputViewEdit.stories.tsx b/web/src/components/Inputs/InputYaml.stories.tsx similarity index 52% rename from web/src/components/Inputs/InputViewEdit.stories.tsx rename to web/src/components/Inputs/InputYaml.stories.tsx index d055d86..79938c0 100644 --- a/web/src/components/Inputs/InputViewEdit.stories.tsx +++ b/web/src/components/Inputs/InputYaml.stories.tsx @@ -1,24 +1,26 @@ import { ComponentMeta, ComponentStory } from "@storybook/react"; import { useState } from "react"; import { usePageTheme } from "~/styles/page"; -import InputViewEdit from "./InputViewEdit"; +import InputYaml from "./InputYaml"; export default { - title: 'Inputs/InputViewEdit', - component: InputViewEdit, + title: 'Inputs/InputYaml', + component: InputYaml, parameters: { actions: { argTypesRegex: '^on.*' } }, - } as ComponentMeta; + } as ComponentMeta; -const Template: ComponentStory = args => { +const Template: ComponentStory = args => { const {classes} = usePageTheme({}); - const [value, setValue] = useState('') + const [value, setValue] = useState({ + "test": "data" + }) return
- +
} export const SimpleText = Template.bind({}) SimpleText.args = { - label: "Entity ID", + label: "Template", } \ No newline at end of file diff --git a/web/src/components/Inputs/InputYaml.tsx b/web/src/components/Inputs/InputYaml.tsx index 81c8005..5d70791 100644 --- a/web/src/components/Inputs/InputYaml.tsx +++ b/web/src/components/Inputs/InputYaml.tsx @@ -1,16 +1,19 @@ import InputWrapper from "./InputWrapper"; import * as yaml from "js-yaml"; import { useEffect, useRef, useState } from "react"; +import InputTextArea from "./InputTextArea"; -export interface Props { +export interface Props { label: string; value: T; onChange: (v: T) => void; + resizable?: boolean; } export default function InputYaml({ label, value={} as any, onChange, + resizable, }: Props) { const [text, setText] = useState(""); useEffect(() => { @@ -18,6 +21,7 @@ export default function InputYaml({ }, [value]); const delayId = useRef(null); const delayedUpdate = (update: string) => { + setText(update) if (delayId.current) { window.clearTimeout(delayId.current); delayId.current = null; @@ -26,14 +30,10 @@ export default function InputYaml({ onChange(yaml.load(update) as any) }, 1000); } - return -