+ added bubble editor
+ initial numeric editor + entity id input
This commit is contained in:
1 parent
6be9f1ba12
commit
60ec7c3f29
7 files changed
+237
-8
No files matched your search
@@ -48,7 +48,7 @@ export const getDescriptionFromAutomationNode = <N extends AutomationNodeTypes>(
|
|||||||
switch(node.condition) {
|
switch(node.condition) {
|
||||||
case "numeric_state":
|
case "numeric_state":
|
||||||
if(node.condition_data.entity_id) {
|
if(node.condition_data.entity_id) {
|
||||||
const center = typeof node.condition_data.entity_id === 'string' ? node.condition_data.entity_id : '...'
|
const center = prettyEntityId(node.condition_data.entity_id);
|
||||||
if(node.condition_data.above) {
|
if(node.condition_data.above) {
|
||||||
if(node.condition_data.below) {
|
if(node.condition_data.below) {
|
||||||
return `${node.condition_data.above} < ${center} < ${node.condition_data.below}`
|
return `${node.condition_data.above} < ${center} < ${node.condition_data.below}`
|
||||||
@@ -77,6 +77,16 @@ export const getDescriptionFromAutomationNode = <N extends AutomationNodeTypes>(
|
|||||||
return 'n/a'
|
return 'n/a'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const prettyEntityId = (entityId: string| string[]) => {
|
||||||
|
if (typeof entityId === 'string') {
|
||||||
|
return entityId
|
||||||
|
} else if(entityId.length === 1) {
|
||||||
|
return entityId[0]
|
||||||
|
} else {
|
||||||
|
return "..."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// export const determineNodeTypes = (action: AutomationNode<any>) : [AutomationNodeType, NodeSubType] => {
|
// export const determineNodeTypes = (action: AutomationNode<any>) : [AutomationNodeType, NodeSubType] => {
|
||||||
// if ('condition' in action) {
|
// if ('condition' in action) {
|
||||||
// switch (action.condition) {
|
// switch (action.condition) {
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import { FC } from "react";
|
import { FC } from "react";
|
||||||
import { AutomationCondition, LogicCondition, TemplateCondition } from "~/automations/types/conditions";
|
import { AutomationCondition, LogicCondition, NumericCondition, TemplateCondition } from "~/automations/types/conditions";
|
||||||
import { getDescriptionFromAutomationNode } from "~/automations/utils";
|
import { getDescriptionFromAutomationNode } from "~/automations/utils";
|
||||||
import InputText from "../Inputs/InputText";
|
import InputText from "../Inputs/InputText";
|
||||||
import InputTextArea from "../Inputs/InputTextArea";
|
import InputTextArea from "../Inputs/InputTextArea";
|
||||||
|
import { InputEntity } from "../Inputs/InputTextBubble";
|
||||||
import { ConditionNode } from "./ConditionNode";
|
import { ConditionNode } from "./ConditionNode";
|
||||||
|
|
||||||
|
|
||||||
@@ -22,6 +23,8 @@ export const getEditor = (condition: AutomationCondition): Editor<any> => {
|
|||||||
return LogicViewer;
|
return LogicViewer;
|
||||||
case 'not':
|
case 'not':
|
||||||
return LogicViewer;
|
return LogicViewer;
|
||||||
|
case 'numeric_state':
|
||||||
|
return NumericStateEditor;
|
||||||
default:
|
default:
|
||||||
return () => <div>Not Ready</div>
|
return () => <div>Not Ready</div>
|
||||||
}
|
}
|
||||||
@@ -50,6 +53,39 @@ export const TemplateEditor: Editor<TemplateCondition> = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export const NumericStateEditor: Editor<NumericCondition> = ({
|
||||||
|
onChange,
|
||||||
|
condition,
|
||||||
|
}) => {
|
||||||
|
return <div>
|
||||||
|
<InputText label="Alias" value={condition.condition_data.alias ?? getDescriptionFromAutomationNode(condition)} onChange={alias => onChange({
|
||||||
|
...condition,
|
||||||
|
condition_data: {
|
||||||
|
...condition.condition_data,
|
||||||
|
alias
|
||||||
|
}
|
||||||
|
})}/>
|
||||||
|
<InputEntity
|
||||||
|
value={condition.condition_data.entity_id}
|
||||||
|
onChange={entity_id => onChange({
|
||||||
|
...condition,
|
||||||
|
condition_data: {
|
||||||
|
...condition.condition_data,
|
||||||
|
entity_id
|
||||||
|
}
|
||||||
|
})}
|
||||||
|
/>
|
||||||
|
<InputTextArea label="Template" value={condition.condition_data.value_template ?? ""} onChange={value_template => onChange({
|
||||||
|
...condition,
|
||||||
|
condition_data: {
|
||||||
|
...condition.condition_data,
|
||||||
|
value_template
|
||||||
|
}
|
||||||
|
})} resizable/>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export const LogicViewer: Editor<LogicCondition> = ({
|
export const LogicViewer: Editor<LogicCondition> = ({
|
||||||
condition,
|
condition,
|
||||||
onChange,
|
onChange,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useState } from "react";
|
import { PropsWithChildren, useState } from "react";
|
||||||
import { useToolTip } from "~/tooltip/context";
|
import { useToolTip } from "~/tooltip/context";
|
||||||
import InputWrapper from "./InputWrapper";
|
import InputWrapper from "./InputWrapper";
|
||||||
import { useInputTextStyles } from "./styles";
|
import { useInputTextStyles } from "./styles";
|
||||||
@@ -8,6 +8,7 @@ export interface Props {
|
|||||||
label: string;
|
label: string;
|
||||||
value: string;
|
value: string;
|
||||||
onChange: (v: string) => void;
|
onChange: (v: string) => void;
|
||||||
|
onEnter?: () => void;
|
||||||
additionalTooltipFilters?: Record<string, string>;
|
additionalTooltipFilters?: Record<string, string>;
|
||||||
}
|
}
|
||||||
export default function InputText({
|
export default function InputText({
|
||||||
@@ -15,8 +16,10 @@ export default function InputText({
|
|||||||
textBoxFor,
|
textBoxFor,
|
||||||
value="",
|
value="",
|
||||||
onChange,
|
onChange,
|
||||||
|
onEnter=()=>{},
|
||||||
additionalTooltipFilters={},
|
additionalTooltipFilters={},
|
||||||
}: Props) {
|
children,
|
||||||
|
}: PropsWithChildren<Props>) {
|
||||||
const {classes} = useInputTextStyles({});
|
const {classes} = useInputTextStyles({});
|
||||||
const tooltip = useToolTip();
|
const tooltip = useToolTip();
|
||||||
const [isFocused, setIsFocused] = useState(false)
|
const [isFocused, setIsFocused] = useState(false)
|
||||||
@@ -24,6 +27,11 @@ export default function InputText({
|
|||||||
<input
|
<input
|
||||||
className={classes.input}
|
className={classes.input}
|
||||||
value={value}
|
value={value}
|
||||||
|
onKeyDown={e => {
|
||||||
|
if (e.key === 'Enter') {
|
||||||
|
onEnter();
|
||||||
|
}
|
||||||
|
}}
|
||||||
onChange={e => {
|
onChange={e => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
onChange(e.target.value)
|
onChange(e.target.value)
|
||||||
@@ -46,5 +54,6 @@ export default function InputText({
|
|||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
{children}
|
||||||
</InputWrapper>
|
</InputWrapper>
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
||||||
|
import { useState } from "react";
|
||||||
|
import { usePageTheme } from "~/styles/page";
|
||||||
|
import InputTextBubble, { InputEntity } from "./InputTextBubble";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
title: 'Inputs/InputTextBubble',
|
||||||
|
component: InputTextBubble,
|
||||||
|
parameters: { actions: { argTypesRegex: '^on.*' } },
|
||||||
|
argTypes: {
|
||||||
|
label: {
|
||||||
|
defaultValue: 'Sample Title'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} as ComponentMeta<typeof InputTextBubble>;
|
||||||
|
|
||||||
|
|
||||||
|
export const ArrayText: ComponentStory<typeof InputTextBubble> = args => {
|
||||||
|
const {classes} = usePageTheme({});
|
||||||
|
const [value, setValue] = useState<string | string[]>(['wow','lots of bubbles', 'itchen', 'bathroom'])
|
||||||
|
return <div className={classes.page}>
|
||||||
|
<div style={{maxWidth: '200px', overflow: 'hidden'}}>
|
||||||
|
<InputTextBubble {...args} value={value} onChange={setValue}/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
export const JustText: ComponentStory<typeof InputTextBubble> = args => {
|
||||||
|
const {classes} = usePageTheme({});
|
||||||
|
const [value, setValue] = useState<string | string[]>('hello')
|
||||||
|
return <div className={classes.page}>
|
||||||
|
<InputTextBubble {...args} value={value} onChange={setValue}/>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export const EntityId: ComponentStory<typeof InputTextBubble> = args => {
|
||||||
|
const {classes} = usePageTheme({});
|
||||||
|
const [value, setValue] = useState<string | string[]>(['sensor.bathroom'])
|
||||||
|
return <div className={classes.page}>
|
||||||
|
<InputEntity value={value} onChange={setValue}/>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
import { FC, useState } from "react";
|
||||||
|
import { useToolTip } from "~/tooltip/context";
|
||||||
|
import InputText from "./InputText";
|
||||||
|
import InputWrapper from "./InputWrapper";
|
||||||
|
import { useInputBubblesStyles, useInputTextStyles } from "./styles";
|
||||||
|
|
||||||
|
export interface Props {
|
||||||
|
label: string;
|
||||||
|
textBoxFor?: string;
|
||||||
|
value: string | string[];
|
||||||
|
onChange: (v: string[]) => void;
|
||||||
|
additionalTooltipFilters?: Record<string, string>;
|
||||||
|
}
|
||||||
|
export default function InputTextBubble({
|
||||||
|
value="",
|
||||||
|
label,
|
||||||
|
textBoxFor,
|
||||||
|
onChange,
|
||||||
|
additionalTooltipFilters={},
|
||||||
|
}: Props) {
|
||||||
|
const {classes} = useInputBubblesStyles({});
|
||||||
|
let selected: string[];
|
||||||
|
if (typeof value === 'string') {
|
||||||
|
selected = [value]
|
||||||
|
} else {
|
||||||
|
selected = value
|
||||||
|
}
|
||||||
|
const [text, setText] = useState('');
|
||||||
|
const addNew = () => {
|
||||||
|
if(text) {
|
||||||
|
onChange([text].concat(selected))
|
||||||
|
setText("")
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return <InputText
|
||||||
|
label={label}
|
||||||
|
value={text}
|
||||||
|
textBoxFor={textBoxFor}
|
||||||
|
onChange={t => setText(t)}
|
||||||
|
onEnter={() => addNew()}
|
||||||
|
additionalTooltipFilters={additionalTooltipFilters}
|
||||||
|
>
|
||||||
|
<div className={classes.bubbles}>
|
||||||
|
{selected.map((s, i) => <div className={classes.bubble} onClick={() => onChange([
|
||||||
|
...selected.slice(0, i),
|
||||||
|
...selected.slice(i+1),
|
||||||
|
])}>
|
||||||
|
{s}
|
||||||
|
<span className={classes.deleteIcon}>X</span>
|
||||||
|
</div>)}
|
||||||
|
</div>
|
||||||
|
<button className={classes.addBtn} onClick={() => addNew()}>+</button>
|
||||||
|
</InputText>
|
||||||
|
}
|
||||||
|
|
||||||
|
export const InputEntity: FC<{
|
||||||
|
value: string | string[];
|
||||||
|
onChange: (v: string[]) => void;
|
||||||
|
}> = ({
|
||||||
|
value,
|
||||||
|
onChange,
|
||||||
|
}) => <InputTextBubble
|
||||||
|
value={value}
|
||||||
|
onChange={onChange}
|
||||||
|
label="Entity ID"
|
||||||
|
textBoxFor="entity_id"
|
||||||
|
/>
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Styles } from "jss";
|
|
||||||
import { createAppUseStyles, AppTheme } from "~/styles/theme";
|
import { createAppUseStyles, AppTheme } from "~/styles/theme";
|
||||||
|
import Color from 'chroma-js';
|
||||||
|
|
||||||
const commonInputStyle = (theme: AppTheme) => ({
|
const commonInputStyle = (theme: AppTheme) => ({
|
||||||
input: {
|
input: {
|
||||||
@@ -76,4 +76,67 @@ export const useInputViewEditStyles = createAppUseStyles<{
|
|||||||
pencil: {
|
pencil: {
|
||||||
|
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
|
export const useInputBubblesStyles = createAppUseStyles<{}>(theme => ({
|
||||||
|
bubbles: {
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'row',
|
||||||
|
maxHeight: 50,
|
||||||
|
maxWidth: '100%',
|
||||||
|
overflowX: 'auto',
|
||||||
|
overflowY: 'hidden',
|
||||||
|
scrollbarWidth: 'thin',
|
||||||
|
},
|
||||||
|
bubble: {
|
||||||
|
position: 'relative',
|
||||||
|
border: `1px solid ${theme.primaryAccent}`,
|
||||||
|
borderRadius: 10,
|
||||||
|
backgroundColor: Color(theme.primary).set('rgb.g', 150).alpha(0.35).hex(),
|
||||||
|
color: Color(theme.primary).brighten(5).hex(),
|
||||||
|
fontSize: 16,
|
||||||
|
|
||||||
|
marginLeft: 1,
|
||||||
|
padding: 5,
|
||||||
|
width: 'fit-content',
|
||||||
|
whiteSpace: 'nowrap',
|
||||||
|
|
||||||
|
cursor: 'pointer',
|
||||||
|
"&:hover": {
|
||||||
|
backgroundColor: Color(theme.primary).set('rgb.r', 150).alpha(0.35).hex(),
|
||||||
|
color: Color(theme.primary).brighten(5).alpha(0.35).hex(),
|
||||||
|
},
|
||||||
|
|
||||||
|
"&:hover $deleteIcon": {
|
||||||
|
display: 'block',
|
||||||
|
}
|
||||||
|
},
|
||||||
|
deleteIcon: {
|
||||||
|
display: 'none',
|
||||||
|
position: "absolute",
|
||||||
|
left: "48%",
|
||||||
|
top: 5,
|
||||||
|
color: "white",
|
||||||
|
},
|
||||||
|
addBtn: {
|
||||||
|
position: "absolute",
|
||||||
|
top: 10,
|
||||||
|
right: 10,
|
||||||
|
fontSize: 20,
|
||||||
|
cursor: 'pointer',
|
||||||
|
borderStyle: 'solid',
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: theme.secondary,
|
||||||
|
backgroundColor: theme.secondary,
|
||||||
|
color: theme.secondaryAccent,
|
||||||
|
padding: "3px 7px",
|
||||||
|
transition: "200ms ease-out",
|
||||||
|
"&:hover": {
|
||||||
|
borderRadius: 100,
|
||||||
|
backgroundColor: Color(theme.primary).set('rgb.g', 150).alpha(0.35).hex(),
|
||||||
|
borderColor: theme.secondaryAccent,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
@@ -7,7 +7,7 @@ export const usePageTheme = createAppUseStyles(theme => ({
|
|||||||
width: '100vw',
|
width: '100vw',
|
||||||
margin: 0,
|
margin: 0,
|
||||||
padding: 0,
|
padding: 0,
|
||||||
overflow: 'hidden',
|
overflow: 'auto',
|
||||||
maxWidth: '100vw',
|
maxWidth: '100vw',
|
||||||
maxHeight: '100vh',
|
maxHeight: '100vh',
|
||||||
|
|
||||||
@@ -22,7 +22,7 @@ export const usePageTheme = createAppUseStyles(theme => ({
|
|||||||
// children
|
// children
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
flexDirection: 'column',
|
flexDirection: 'column',
|
||||||
justifyContent: 'center',
|
justifyContent: 'flex-start',
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
|
|
||||||
'> div': {
|
'> div': {
|
||||||
|
|||||||
Reference in new issue
Block a user