yaml mode
This commit is contained in:
1 parent
eb12ecc5d6
commit
fe1b66d2d9
9 files changed
+92
-100
No files matched your search
@@ -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<{
|
||||
<div className={classes.title}>
|
||||
{/* <span className={classes.titleText}>{condition.condition.replace('_', ' ')}</span> */}
|
||||
<InputList
|
||||
label=""
|
||||
className={classes.titleText}
|
||||
current={condition.condition}
|
||||
options={[
|
||||
@@ -105,13 +107,25 @@ export const ConditionNode: FC<{
|
||||
}
|
||||
} as any)}
|
||||
/>
|
||||
<button className={classes.modifyBtn} onClick={() => setInternalDisplayMode(!effectiveDM)}>
|
||||
{effectiveDM && <button className={classes.yamlBtn} onClick={() => setYamlMode(!yamlMode)}>
|
||||
{yamlMode ? 'visual' : 'yaml'}
|
||||
</button>}
|
||||
{!yamlMode && <button className={classes.modifyBtn} onClick={() => setInternalDisplayMode(!effectiveDM)}>
|
||||
{effectiveDM ? <PencilIcon className={classes.icon}/> : <CheckMarkIcon className={classes.icon}/>}
|
||||
</button>
|
||||
</button>}
|
||||
</div>
|
||||
<div className={classes.children}>
|
||||
{childrenConditions}
|
||||
{hasChildren && <div className={classes.addBtnContainer}>
|
||||
{yamlMode && <InputYaml
|
||||
label=""
|
||||
value={condition.condition_data}
|
||||
onChange={update => onUpdate({
|
||||
...condition,
|
||||
condition_data: update as any
|
||||
})}
|
||||
resizable
|
||||
/>}
|
||||
{!yamlMode && childrenConditions}
|
||||
{!yamlMode && hasChildren && <div className={classes.addBtnContainer}>
|
||||
<button className={classes.addBtn} onClick={() => onAddChild()}>Add</button>
|
||||
</div>}
|
||||
</div>
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import { useState } from "react";
|
||||
import InputWrapper from "./InputWrapper";
|
||||
import { useInputTextStyles } from "./styles";
|
||||
import { useInputListStyles } from "./styles";
|
||||
|
||||
|
||||
export interface Props<T extends string> {
|
||||
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<T extends string>({
|
||||
current, options, onChange, label,
|
||||
...selattr
|
||||
}: Props<T>) {
|
||||
const {classes} = useInputTextStyles({});
|
||||
return <InputWrapper label={label} labelSize={'small'}>
|
||||
const {classes} = useInputListStyles({});
|
||||
return <InputWrapper label={label} labelSize={'small'} noMargin>
|
||||
<select
|
||||
className={classes.input}
|
||||
{...selattr} value={current}
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
import { useRef, useState, useEffect, HTMLProps } from "react";
|
||||
import {CheckMarkIcon, PencilIcon} from "~/icons/icons";
|
||||
import { useToolTip } from "~/tooltip/context";
|
||||
import InputWrapper from "./InputWrapper";
|
||||
import { useInputViewEditStyles } from "./styles";
|
||||
|
||||
export interface Props {
|
||||
textBoxFor?: string;
|
||||
label: string;
|
||||
value: string;
|
||||
onChange: (v: string) => void;
|
||||
additionalTooltipFilters?: Record<string, string>;
|
||||
useTextArea?: boolean;
|
||||
}
|
||||
export default function InputViewEdit({
|
||||
label,
|
||||
textBoxFor,
|
||||
value="",
|
||||
onChange,
|
||||
additionalTooltipFilters={},
|
||||
}: Props) {
|
||||
// state
|
||||
const tooltip = useToolTip();
|
||||
const [isEditing, setIsEditing] = useState(false);
|
||||
// alias for on calls
|
||||
const onChangeWrapped = (t: string) => {
|
||||
onChange(t);
|
||||
setIsEditing(false);
|
||||
}
|
||||
// ref to grab focus when editing
|
||||
const inputRef = useRef<HTMLInputElement | null>(null);
|
||||
useEffect(() => {
|
||||
if (isEditing && inputRef.current) {
|
||||
inputRef.current.focus()
|
||||
}
|
||||
}, [inputRef.current, isEditing]);
|
||||
|
||||
// styles
|
||||
const {classes} = useInputViewEditStyles({ isEditing });
|
||||
return <InputWrapper label={label}>
|
||||
{isEditing ? <input
|
||||
ref={inputRef}
|
||||
value={value}
|
||||
onChange={(e:any) => {
|
||||
onChange(e.target.value)
|
||||
}}
|
||||
onFocus={(e: any) => textBoxFor && tooltip.setFocus(
|
||||
e.target.getBoundingClientRect(),
|
||||
{
|
||||
searchObject: textBoxFor,
|
||||
searchText: value,
|
||||
filterObjects: additionalTooltipFilters,
|
||||
},
|
||||
onChangeWrapped
|
||||
)}
|
||||
/>:<div className={classes.inputView}>
|
||||
{value}
|
||||
</div>}
|
||||
<PencilIcon onClick={() => setIsEditing(!isEditing)} className={classes.pencil}/>
|
||||
<CheckMarkIcon onClick={() => setIsEditing(!isEditing)} className={classes.checkmark}/>
|
||||
</InputWrapper>
|
||||
}
|
||||
@@ -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<Props>) {
|
||||
const {classes} = useInputWrapperStyles({labelSize})
|
||||
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}
|
||||
|
||||
+10
-8
@@ -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<typeof InputViewEdit>;
|
||||
} as ComponentMeta<typeof InputYaml>;
|
||||
|
||||
|
||||
const Template: ComponentStory<typeof InputViewEdit> = args => {
|
||||
const Template: ComponentStory<typeof InputYaml> = args => {
|
||||
const {classes} = usePageTheme({});
|
||||
const [value, setValue] = useState('')
|
||||
const [value, setValue] = useState({
|
||||
"test": "data"
|
||||
})
|
||||
return <div className={classes.page}>
|
||||
<InputViewEdit {...args} value={value} onChange={setValue}/>
|
||||
<InputYaml {...args} value={value} onChange={setValue}/>
|
||||
</div>
|
||||
}
|
||||
|
||||
export const SimpleText = Template.bind({})
|
||||
SimpleText.args = {
|
||||
label: "Entity ID",
|
||||
label: "Template",
|
||||
}
|
||||
@@ -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<T> {
|
||||
export interface Props<T extends {}> {
|
||||
label: string;
|
||||
value: T;
|
||||
onChange: (v: T) => void;
|
||||
resizable?: boolean;
|
||||
}
|
||||
export default function InputYaml<T>({
|
||||
label,
|
||||
value={} as any,
|
||||
onChange,
|
||||
resizable,
|
||||
}: Props<T>) {
|
||||
const [text, setText] = useState("");
|
||||
useEffect(() => {
|
||||
@@ -18,6 +21,7 @@ export default function InputYaml<T>({
|
||||
}, [value]);
|
||||
const delayId = useRef<null | number>(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<T>({
|
||||
onChange(yaml.load(update) as any)
|
||||
}, 1000);
|
||||
}
|
||||
return <InputWrapper label={label}>
|
||||
<textarea
|
||||
value={text}
|
||||
onChange={e => {
|
||||
e.preventDefault();
|
||||
setText(e.target.value);
|
||||
delayedUpdate(e.target.value);
|
||||
}}
|
||||
/>
|
||||
</InputWrapper>
|
||||
return <InputTextArea
|
||||
label={label}
|
||||
value={text}
|
||||
onChange={delayedUpdate}
|
||||
resizable={resizable}
|
||||
/>
|
||||
}
|
||||
@@ -29,15 +29,16 @@ const commonInputStyle = (theme: AppTheme) => ({
|
||||
|
||||
export const useInputWrapperStyles = createAppUseStyles<{
|
||||
labelSize: 'normal' | 'small',
|
||||
noMargin: boolean,
|
||||
}>(theme => {
|
||||
return {
|
||||
wrapper: {
|
||||
wrapper: ({ noMargin }) => ({
|
||||
position: 'relative',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
marginTop: 10,
|
||||
marginBottom: '0.25em',
|
||||
},
|
||||
marginTop: noMargin ? 0 : 10,
|
||||
marginBottom: noMargin ? 0 : '0.25em',
|
||||
}),
|
||||
label: ({ labelSize }) => ({
|
||||
fontSize: labelSize === 'normal' ? 16 : 10,
|
||||
position: 'absolute',
|
||||
@@ -79,6 +80,16 @@ export const useInputNumberStyles = createAppUseStyles<{}>(theme => {
|
||||
}
|
||||
});
|
||||
|
||||
export const useInputListStyles = createAppUseStyles<{}>(theme => {
|
||||
const styles = commonInputStyle(theme);
|
||||
return {
|
||||
input: {
|
||||
...styles.input,
|
||||
cursor: 'pointer'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
export const useInputTextAreaStyles = createAppUseStyles<{ resizable: boolean }>(theme => {
|
||||
const styles = commonInputStyle(theme);
|
||||
return {
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import { FC } from "react";
|
||||
import { AutomationSequenceNode } from "~/automations/types";
|
||||
|
||||
|
||||
export const SequenceEditor: FC<{
|
||||
node: AutomationSequenceNode
|
||||
}> = ({}) => {
|
||||
|
||||
return <div>
|
||||
<div>
|
||||
<span></span>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
Reference in new issue
Block a user