refactor inputs
This commit is contained in:
1 parent
2c5d64ab86
commit
549f52655b
45 files changed
+301
-256
No files matched your search
@@ -14,7 +14,7 @@ import ModeEditOutlineTwoToneIcon from "@mui/icons-material/ModeEditOutlineTwoTo
|
||||
import { CheckMarkIcon } from "components/Icons";
|
||||
|
||||
import { Modal } from "components/Modal";
|
||||
import { Button } from "components/Inputs/Button";
|
||||
import { Button } from "components/Inputs/Buttons/Button";
|
||||
import InputYaml from "components/Inputs/InputYaml";
|
||||
import { TagDB } from "components/AutomationManager/TagDB";
|
||||
import { DAGDims } from "components/DAGGraph/elements/types";
|
||||
|
||||
@@ -8,7 +8,7 @@ import SaveIcon from "@mui/icons-material/SaveOutlined";
|
||||
|
||||
import { cleanUpUndefined } from "utils/helpers";
|
||||
import { Modal } from "components/Modal";
|
||||
import { Button } from "components/Inputs/Button";
|
||||
import { Button } from "components/Inputs/Buttons/Button";
|
||||
import InputAutoText from "components/Inputs/InputAutoText";
|
||||
|
||||
import { TagDB } from "../TagDB";
|
||||
|
||||
@@ -16,7 +16,7 @@ import {
|
||||
AutomationManagerAuto,
|
||||
AutomationManagerAutoUpdatable,
|
||||
} from "../types";
|
||||
import { Button } from "components/Inputs/Button";
|
||||
import { Button } from "components/Inputs/Buttons/Button";
|
||||
import { ButtonIcon } from "components/Icons/ButtonIcons";
|
||||
|
||||
export type AutomationManagerSidebarProps = {
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
} from "types/automations/conditions";
|
||||
import InputNumber from "components/Inputs/InputNumber";
|
||||
import InputText from "components/Inputs/InputText";
|
||||
import { InputEntity } from "components/Inputs/InputEntities";
|
||||
import { InputEntity } from "components/Inputs/AutoComplete/InputEntities";
|
||||
import {
|
||||
ConditionNodeBase,
|
||||
ConditionNodeBaseViewMode,
|
||||
@@ -25,11 +25,11 @@ import { DeviceEditor } from "components/DeviceEditor";
|
||||
import { ButtonIcon } from "components/Icons/ButtonIcons";
|
||||
import AddIcon from "@mui/icons-material/Add";
|
||||
import { getEntityDomains } from "utils/automations";
|
||||
import { InputAutoComplete } from "components/Inputs/InputAutoComplete";
|
||||
import { InputTimeEntity } from "components/Inputs/InputTimeEntity";
|
||||
import { InputAutoComplete } from "components/Inputs/AutoComplete/InputAutoComplete";
|
||||
import { InputTimeEntity } from "components/Inputs/AutoComplete/InputTimeEntity";
|
||||
import { prettyName } from "utils/formatting";
|
||||
import { InputList } from "components/Inputs/InputList";
|
||||
import { Button } from "components/Inputs/Button";
|
||||
import { Button } from "components/Inputs/Buttons/Button";
|
||||
import { RemoveCircle } from "@mui/icons-material";
|
||||
|
||||
interface Editor<C extends AutomationCondition>
|
||||
|
||||
@@ -8,67 +8,61 @@ import { AutomationActionData } from "types/automations";
|
||||
import { createUpdaterFromAutomationData } from "../updater";
|
||||
import { ModalState } from "../board/types";
|
||||
import { DEFAULT_DIMS } from "./constants";
|
||||
import { makeStory } from "devUtils";
|
||||
|
||||
const Demo: FC<{
|
||||
automation: AutomationActionData;
|
||||
flipped: boolean;
|
||||
}> = (props) => {
|
||||
const { namer } = useHA();
|
||||
const [state, setState] = useState<AutomationActionData>(props.automation);
|
||||
const [modalState, setModalState] =
|
||||
useState<ModalState | undefined>(undefined);
|
||||
const updater = createUpdaterFromAutomationData(
|
||||
setModalState,
|
||||
state,
|
||||
setState
|
||||
);
|
||||
const elementData = useAutomationNodes(state, {
|
||||
dims: {
|
||||
...DEFAULT_DIMS,
|
||||
flipped: props.flipped,
|
||||
},
|
||||
namer,
|
||||
openModal: setModalState,
|
||||
stateUpdater: updater,
|
||||
});
|
||||
return (
|
||||
<DAGGraphBoard
|
||||
modalState={modalState}
|
||||
closeModal={() => setModalState(undefined)}
|
||||
state={{
|
||||
ready: true,
|
||||
data: {
|
||||
elements: elementData,
|
||||
},
|
||||
}}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export default {
|
||||
title: "DAGGraph/Elements",
|
||||
component: Demo,
|
||||
parameters: { actions: { argTypesRegex: "^on.*" } },
|
||||
args: {
|
||||
flipped: true,
|
||||
automation: {
|
||||
trigger: [],
|
||||
condition: [],
|
||||
sequence: [],
|
||||
const { make, componentMeta } = makeStory({
|
||||
Component: (props: {
|
||||
automation: AutomationActionData;
|
||||
flipped: boolean;
|
||||
}) => {
|
||||
const { namer } = useHA();
|
||||
const [state, setState] = useState<AutomationActionData>(props.automation);
|
||||
const [modalState, setModalState] =
|
||||
useState<ModalState | undefined>(undefined);
|
||||
const updater = createUpdaterFromAutomationData(
|
||||
setModalState,
|
||||
state,
|
||||
setState
|
||||
);
|
||||
const elementData = useAutomationNodes(state, {
|
||||
dims: {
|
||||
...DEFAULT_DIMS,
|
||||
flipped: props.flipped,
|
||||
},
|
||||
namer,
|
||||
openModal: setModalState,
|
||||
stateUpdater: updater,
|
||||
});
|
||||
return (
|
||||
<DAGGraphBoard
|
||||
modalState={modalState}
|
||||
closeModal={() => setModalState(undefined)}
|
||||
state={{
|
||||
ready: true,
|
||||
data: {
|
||||
elements: elementData,
|
||||
},
|
||||
}}
|
||||
/>
|
||||
);
|
||||
},
|
||||
meta: {
|
||||
title: "DAGGraph/Elements",
|
||||
args: {
|
||||
flipped: true,
|
||||
automation: {
|
||||
trigger: [],
|
||||
condition: [],
|
||||
sequence: [],
|
||||
},
|
||||
},
|
||||
},
|
||||
} as ComponentMeta<typeof Demo>;
|
||||
});
|
||||
|
||||
const Template: ComponentStory<typeof Demo> = (args) => (
|
||||
<Page>
|
||||
<Demo {...args} />
|
||||
</Page>
|
||||
);
|
||||
export default componentMeta;
|
||||
|
||||
export const Empty = Template.bind({});
|
||||
export const Trigger = Template.bind({});
|
||||
Trigger.args = {
|
||||
...Trigger.args,
|
||||
export const Empty = make({});
|
||||
export const Trigger = make({
|
||||
automation: {
|
||||
trigger: [
|
||||
{ platform: "homeassistant", event: "up" },
|
||||
@@ -82,10 +76,9 @@ Trigger.args = {
|
||||
condition: [],
|
||||
sequence: [],
|
||||
},
|
||||
};
|
||||
export const Conditions = Template.bind({});
|
||||
Conditions.args = {
|
||||
...Conditions.args,
|
||||
});
|
||||
|
||||
export const Conditions = make({
|
||||
automation: {
|
||||
trigger: [
|
||||
{
|
||||
@@ -119,11 +112,9 @@ Conditions.args = {
|
||||
],
|
||||
sequence: [],
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
export const FullAuto = Template.bind({});
|
||||
FullAuto.args = {
|
||||
...FullAuto.args,
|
||||
export const FullAuto = make({
|
||||
automation: {
|
||||
condition: [
|
||||
{
|
||||
@@ -272,11 +263,9 @@ FullAuto.args = {
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
export const ChooseAuto = Template.bind({});
|
||||
ChooseAuto.args = {
|
||||
...ChooseAuto.args,
|
||||
export const ChooseAuto = make({
|
||||
automation: {
|
||||
condition: [],
|
||||
trigger: [],
|
||||
@@ -370,12 +359,9 @@ ChooseAuto.args = {
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
export const EmptyChooseAuto = Template.bind({});
|
||||
|
||||
EmptyChooseAuto.args = {
|
||||
...EmptyChooseAuto.args,
|
||||
export const EmptyChooseAuto = make({
|
||||
automation: {
|
||||
condition: [],
|
||||
trigger: [],
|
||||
@@ -386,11 +372,9 @@ EmptyChooseAuto.args = {
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
export const RepeatAuto = Template.bind({});
|
||||
RepeatAuto.args = {
|
||||
...RepeatAuto.args,
|
||||
export const RepeatAuto = make({
|
||||
automation: {
|
||||
condition: [],
|
||||
trigger: [],
|
||||
@@ -437,11 +421,9 @@ RepeatAuto.args = {
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
export const ParallelAuto = Template.bind({});
|
||||
ParallelAuto.args = {
|
||||
...ParallelAuto.args,
|
||||
export const ParallelAuto = make({
|
||||
automation: {
|
||||
condition: [],
|
||||
trigger: [],
|
||||
@@ -467,11 +449,9 @@ ParallelAuto.args = {
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
export const BadNodes = Template.bind({});
|
||||
BadNodes.args = {
|
||||
...BadNodes.args,
|
||||
export const BadNodes = make({
|
||||
automation: {
|
||||
condition: [
|
||||
{
|
||||
@@ -500,11 +480,9 @@ BadNodes.args = {
|
||||
},
|
||||
] as any,
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
export const IfElseNode = Template.bind({});
|
||||
IfElseNode.args = {
|
||||
...IfElseNode.args,
|
||||
export const IfElseNode = make({
|
||||
automation: {
|
||||
condition: [],
|
||||
trigger: [],
|
||||
@@ -516,4 +494,24 @@ IfElseNode.args = {
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
export const TimeNodes = make({
|
||||
automation: {
|
||||
condition: [],
|
||||
trigger: [
|
||||
{
|
||||
platform: "time",
|
||||
at: "",
|
||||
},
|
||||
{
|
||||
platform: "time_pattern",
|
||||
},
|
||||
],
|
||||
sequence: [
|
||||
{
|
||||
condition: "time",
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
@@ -4,7 +4,7 @@ import { ButtonIcon } from "components/Icons/ButtonIcons";
|
||||
import { FC } from "react";
|
||||
import { ButtonNodeProps } from "./types";
|
||||
import { Handle, Position } from "react-flow-renderer";
|
||||
import { Button } from "components/Inputs/Button";
|
||||
import { Button } from "components/Inputs/Buttons/Button";
|
||||
|
||||
export const ButtonNode: FC<ButtonNodeProps> = ({
|
||||
height,
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import {
|
||||
BaseOption,
|
||||
InputAutoComplete,
|
||||
} from "components/Inputs/InputAutoComplete";
|
||||
import { InputDevice } from "components/Inputs/InputDevice";
|
||||
import { InputDeviceCapabilties } from "components/Inputs/InputDeviceCapabilties";
|
||||
import { InputEntity } from "components/Inputs/InputEntities";
|
||||
} from "components/Inputs/AutoComplete/InputAutoComplete";
|
||||
import { InputDevice } from "components/Inputs/AutoComplete/InputDevice";
|
||||
import { InputDeviceCapabilties } from "components/Inputs/AutoComplete/InputDeviceCapabilties";
|
||||
import { InputEntity } from "components/Inputs/AutoComplete/InputEntities";
|
||||
import { cleanUpUndefined } from "utils/helpers";
|
||||
import { DeviceBaseType, DeviceTypeCapability } from "haService/types";
|
||||
import { AutomationDeviceState } from "types/automations/common";
|
||||
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+4
-4
@@ -4,10 +4,10 @@ import { useSnackbar } from "notistack";
|
||||
import { useRef } from "react";
|
||||
import { prettyName } from "utils/formatting";
|
||||
import { InputAutoComplete, Option } from "./InputAutoComplete";
|
||||
import InputBoolean from "./InputBoolean";
|
||||
import { InputTime } from "./InputDayTime";
|
||||
import InputNumber from "./InputNumber";
|
||||
import InputText from "./InputText";
|
||||
import InputBoolean from "../InputBoolean";
|
||||
import { InputTime } from "../InputDayTime";
|
||||
import InputNumber from "../InputNumber";
|
||||
import InputText from "../InputText";
|
||||
|
||||
export type InputDeviceCapabiltiesProps<T extends Record<string, any>> = {
|
||||
defn: HaFormSchema[];
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+1
-1
@@ -11,7 +11,7 @@ import {
|
||||
isAutomationTimeString24Hours,
|
||||
} from "utils/time";
|
||||
import { InputEntity } from "./InputEntities";
|
||||
import { InputTime } from "./InputTime";
|
||||
import { InputTime } from "../InputTime";
|
||||
|
||||
export type InputTimeEntityProps = {
|
||||
value: string;
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -1,33 +1,36 @@
|
||||
import React from "react";
|
||||
import { ComponentMeta, ComponentStory } from '@storybook/react';
|
||||
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
||||
import { Modal } from ".";
|
||||
import { useState } from 'react';
|
||||
import { Button } from "components/Inputs/Button";
|
||||
|
||||
import { useState } from "react";
|
||||
import { Button } from "components/Inputs/Buttons/Button";
|
||||
|
||||
export default {
|
||||
title: 'Modal',
|
||||
title: "Modal",
|
||||
component: Modal,
|
||||
parameters: { actions: { argTypesRegex: '^on.*' } },
|
||||
parameters: { actions: { argTypesRegex: "^on.*" } },
|
||||
args: {
|
||||
open: true
|
||||
}
|
||||
} as ComponentMeta<typeof Modal>
|
||||
open: true,
|
||||
},
|
||||
} as ComponentMeta<typeof Modal>;
|
||||
|
||||
export const Simple: ComponentStory<typeof Modal> = args => {
|
||||
return <>
|
||||
<Modal {...args}>
|
||||
<div>Hello World!</div>
|
||||
</Modal>
|
||||
</>
|
||||
}
|
||||
export const WithButtons: ComponentStory<typeof Modal> = args => {
|
||||
export const Simple: ComponentStory<typeof Modal> = (args) => {
|
||||
return (
|
||||
<>
|
||||
<Modal {...args}>
|
||||
<div>Hello World!</div>
|
||||
</Modal>
|
||||
</>
|
||||
);
|
||||
};
|
||||
export const WithButtons: ComponentStory<typeof Modal> = (args) => {
|
||||
const [open, setOpen] = useState(false);
|
||||
return <>
|
||||
<Button onClick={() => setOpen(!open)}>Open Me!</Button>
|
||||
<Modal open={open}>
|
||||
<div>Hello World!</div>
|
||||
<Button onClick={() => setOpen(!open)}>Close Me!</Button>
|
||||
</Modal>
|
||||
</>
|
||||
}
|
||||
return (
|
||||
<>
|
||||
<Button onClick={() => setOpen(!open)}>Open Me!</Button>
|
||||
<Modal open={open}>
|
||||
<div>Hello World!</div>
|
||||
<Button onClick={() => setOpen(!open)}>Close Me!</Button>
|
||||
</Modal>
|
||||
</>
|
||||
);
|
||||
};
|
||||
@@ -1,7 +1,7 @@
|
||||
import InputNumber from "components/Inputs/InputNumber";
|
||||
import { RepeatAction } from "types/automations/actions";
|
||||
import { OptionManager } from "./OptionManager";
|
||||
import { InputAutoComplete } from "components/Inputs/InputAutoComplete";
|
||||
import { InputAutoComplete } from "components/Inputs/AutoComplete/InputAutoComplete";
|
||||
|
||||
const determineType = (repeatNode: RepeatAction["repeat"]) =>
|
||||
"count" in repeatNode ? "count" : "until" in repeatNode ? "until" : "while";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { InputService } from "components/Inputs/InputService";
|
||||
import { InputService } from "components/Inputs/AutoComplete/InputService";
|
||||
import { ServiceEditor } from "components/ServiceEditor";
|
||||
import { ServiceAction } from "types/automations/actions";
|
||||
import { OptionManager, updateActionData } from "./OptionManager";
|
||||
|
||||
@@ -1,63 +1,82 @@
|
||||
import { OptionManager } from './OptionManager';
|
||||
import { AutomationTriggerNumericState } from 'types/automations/triggers';
|
||||
import InputText from 'components/Inputs/InputText';
|
||||
import { InputEntity } from 'components/Inputs/InputEntities';
|
||||
import InputNumber from 'components/Inputs/InputNumber';
|
||||
import { InputTime } from 'components/Inputs/InputTime'; import InputYaml from 'components/Inputs/InputYaml';
|
||||
import { OptionManager } from "./OptionManager";
|
||||
import { AutomationTriggerNumericState } from "types/automations/triggers";
|
||||
import InputText from "components/Inputs/InputText";
|
||||
import { InputEntity } from "components/Inputs/AutoComplete/InputEntities";
|
||||
import InputNumber from "components/Inputs/InputNumber";
|
||||
import { InputTime } from "components/Inputs/InputTime";
|
||||
import InputYaml from "components/Inputs/InputYaml";
|
||||
|
||||
|
||||
export const TriggerNumericState: OptionManager<AutomationTriggerNumericState> = {
|
||||
defaultState: () => ({
|
||||
"platform": 'numeric_state',
|
||||
"entity_id": "",
|
||||
}),
|
||||
isReady: () => true,
|
||||
renderOptionList: (state, setState) => {
|
||||
return <>
|
||||
<InputEntity
|
||||
value={state.entity_id}
|
||||
multiple
|
||||
onChange={entity_id => setState({
|
||||
...state,
|
||||
entity_id
|
||||
})}
|
||||
/>
|
||||
<InputText label="Attribute" value={state.attribute ?? ""} onChange={attribute => setState({
|
||||
...state,
|
||||
attribute
|
||||
})} />
|
||||
<InputNumber
|
||||
label="Above"
|
||||
value={state.above ? Number(state.above) : undefined}
|
||||
onChange={above => setState({
|
||||
...state,
|
||||
above: above ? String(above) : undefined,
|
||||
})}
|
||||
/>
|
||||
<InputNumber
|
||||
label="Below"
|
||||
value={state.below ? Number(state.below) : undefined}
|
||||
onChange={below => setState({
|
||||
...state,
|
||||
below: below ? String(below) : undefined,
|
||||
})}
|
||||
/>
|
||||
<InputYaml
|
||||
label="Template"
|
||||
value={state.value_template ?? ""}
|
||||
onChange={value_template => setState({
|
||||
...state,
|
||||
value_template
|
||||
})}
|
||||
/>
|
||||
<InputTime
|
||||
label="For"
|
||||
value={state.for}
|
||||
onChange={_for => setState({
|
||||
...state,
|
||||
for: _for,
|
||||
})}
|
||||
/>
|
||||
</>
|
||||
}
|
||||
}
|
||||
export const TriggerNumericState: OptionManager<AutomationTriggerNumericState> =
|
||||
{
|
||||
defaultState: () => ({
|
||||
platform: "numeric_state",
|
||||
entity_id: "",
|
||||
}),
|
||||
isReady: () => true,
|
||||
renderOptionList: (state, setState) => {
|
||||
return (
|
||||
<>
|
||||
<InputEntity
|
||||
value={state.entity_id}
|
||||
multiple
|
||||
onChange={(entity_id) =>
|
||||
setState({
|
||||
...state,
|
||||
entity_id,
|
||||
})
|
||||
}
|
||||
/>
|
||||
<InputText
|
||||
label="Attribute"
|
||||
value={state.attribute ?? ""}
|
||||
onChange={(attribute) =>
|
||||
setState({
|
||||
...state,
|
||||
attribute,
|
||||
})
|
||||
}
|
||||
/>
|
||||
<InputNumber
|
||||
label="Above"
|
||||
value={state.above ? Number(state.above) : undefined}
|
||||
onChange={(above) =>
|
||||
setState({
|
||||
...state,
|
||||
above: above ? String(above) : undefined,
|
||||
})
|
||||
}
|
||||
/>
|
||||
<InputNumber
|
||||
label="Below"
|
||||
value={state.below ? Number(state.below) : undefined}
|
||||
onChange={(below) =>
|
||||
setState({
|
||||
...state,
|
||||
below: below ? String(below) : undefined,
|
||||
})
|
||||
}
|
||||
/>
|
||||
<InputYaml
|
||||
label="Template"
|
||||
value={state.value_template ?? ""}
|
||||
onChange={(value_template) =>
|
||||
setState({
|
||||
...state,
|
||||
value_template,
|
||||
})
|
||||
}
|
||||
/>
|
||||
<InputTime
|
||||
label="For"
|
||||
value={state.for}
|
||||
onChange={(_for) =>
|
||||
setState({
|
||||
...state,
|
||||
for: _for,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
},
|
||||
};
|
||||
@@ -1,9 +1,9 @@
|
||||
import { OptionManager } from "./OptionManager";
|
||||
import { AutomationTriggerState } from "types/automations/triggers";
|
||||
import InputText from "components/Inputs/InputText";
|
||||
import { InputEntity } from "components/Inputs/InputEntities";
|
||||
import { InputEntity } from "components/Inputs/AutoComplete/InputEntities";
|
||||
import { InputTime } from "components/Inputs/InputTime";
|
||||
import { InputAutoComplete } from "components/Inputs/InputAutoComplete";
|
||||
import { InputAutoComplete } from "components/Inputs/AutoComplete/InputAutoComplete";
|
||||
import { FC } from "react";
|
||||
import { getEntityDomains } from "utils/automations";
|
||||
import { InputList } from "components/Inputs/InputList";
|
||||
|
||||
@@ -11,10 +11,10 @@ import {
|
||||
import InputText from "components/Inputs/InputText";
|
||||
import { FC } from "react";
|
||||
import { InputList } from "components/Inputs/InputList";
|
||||
import { Button } from "components/Inputs/Button";
|
||||
import { Button } from "components/Inputs/Buttons/Button";
|
||||
import { useState } from "react";
|
||||
import AddIcon from "@mui/icons-material/Add";
|
||||
import { InputTimeEntity } from "components/Inputs/InputTimeEntity";
|
||||
import { InputTimeEntity } from "components/Inputs/AutoComplete/InputTimeEntity";
|
||||
|
||||
export const TriggerTime: OptionManager<AutomationTriggerTime> = {
|
||||
defaultState: () => ({
|
||||
@@ -59,7 +59,8 @@ export const TriggerTime: OptionManager<AutomationTriggerTime> = {
|
||||
divisible by that number. You can specify "*" to match any value.{" "}
|
||||
<a
|
||||
href="https://www.home-assistant.io/docs/automation/trigger/#time-pattern-trigger"
|
||||
target="_blank" rel="noreferrer"
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
>
|
||||
More Info.
|
||||
</a>
|
||||
|
||||
@@ -1,40 +1,53 @@
|
||||
import { OptionManager } from './OptionManager';
|
||||
import { AutomationTriggerZone } from 'types/automations/triggers';
|
||||
import { InputList } from 'components/Inputs/InputList';
|
||||
import { InputEntity } from 'components/Inputs/InputEntities';
|
||||
|
||||
import { OptionManager } from "./OptionManager";
|
||||
import { AutomationTriggerZone } from "types/automations/triggers";
|
||||
import { InputList } from "components/Inputs/InputList";
|
||||
import { InputEntity } from "components/Inputs/AutoComplete/InputEntities";
|
||||
|
||||
export const TriggerZone: OptionManager<AutomationTriggerZone> = {
|
||||
defaultState: () => ({
|
||||
"platform": 'zone',
|
||||
"zone": "",
|
||||
"event": "enter",
|
||||
"entity_id": "",
|
||||
platform: "zone",
|
||||
zone: "",
|
||||
event: "enter",
|
||||
entity_id: "",
|
||||
}),
|
||||
isReady: () => true,
|
||||
renderOptionList: (state, setState) => {
|
||||
return <>
|
||||
<InputEntity label="Zone" restrictToDomain={['zone']} value={state.zone} onChange={zone => setState({
|
||||
...state,
|
||||
zone: zone ?? ""
|
||||
})} />
|
||||
<InputList
|
||||
label="Event"
|
||||
current={state.event}
|
||||
options={['enter', 'leave']}
|
||||
onChange={event => setState({
|
||||
...state, event,
|
||||
})}
|
||||
/>
|
||||
<InputEntity
|
||||
multiple
|
||||
restrictToDomain={["device_tracker", "person"]}
|
||||
value={state.entity_id}
|
||||
onChange={entity_id => setState({
|
||||
...state,
|
||||
entity_id
|
||||
})}
|
||||
/>
|
||||
</>
|
||||
}
|
||||
}
|
||||
return (
|
||||
<>
|
||||
<InputEntity
|
||||
label="Zone"
|
||||
restrictToDomain={["zone"]}
|
||||
value={state.zone}
|
||||
onChange={(zone) =>
|
||||
setState({
|
||||
...state,
|
||||
zone: zone ?? "",
|
||||
})
|
||||
}
|
||||
/>
|
||||
<InputList
|
||||
label="Event"
|
||||
current={state.event}
|
||||
options={["enter", "leave"]}
|
||||
onChange={(event) =>
|
||||
setState({
|
||||
...state,
|
||||
event,
|
||||
})
|
||||
}
|
||||
/>
|
||||
<InputEntity
|
||||
multiple
|
||||
restrictToDomain={["device_tracker", "person"]}
|
||||
value={state.entity_id}
|
||||
onChange={(entity_id) =>
|
||||
setState({
|
||||
...state,
|
||||
entity_id,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
},
|
||||
};
|
||||
@@ -3,7 +3,7 @@ import { ComponentMeta, ComponentStory } from "@storybook/react";
|
||||
import { NodeEditor } from ".";
|
||||
|
||||
import { AutomationCondition } from "types/automations/conditions";
|
||||
import { Button } from "components/Inputs/Button";
|
||||
import { Button } from "components/Inputs/Buttons/Button";
|
||||
import { useState } from "react";
|
||||
import { Modal } from "components/Modal";
|
||||
import { Page } from "components/Page";
|
||||
|
||||
@@ -4,7 +4,7 @@ import { FC, ReactNode } from "react";
|
||||
import { AutomationNode, AutomationNodeMapping } from "types/automations/index";
|
||||
import { useEditorNodeState } from "./OptionManager";
|
||||
import { InputList } from "components/Inputs/InputList";
|
||||
import { Button } from "components/Inputs/Button";
|
||||
import { Button } from "components/Inputs/Buttons/Button";
|
||||
import InputBoolean from "components/Inputs/InputBoolean";
|
||||
import { useConfirm } from "material-ui-confirm";
|
||||
import { getNodeSubTypeDescription } from "./utils";
|
||||
|
||||
@@ -4,13 +4,16 @@ import { ServiceEditorOption } from "./options";
|
||||
import InputText from "components/Inputs/InputText";
|
||||
import InputNumber from "components/Inputs/InputNumber";
|
||||
import { RemoveCircle } from "@mui/icons-material";
|
||||
import { InputAutoComplete, Option } from "components/Inputs/InputAutoComplete";
|
||||
import {
|
||||
InputAutoComplete,
|
||||
Option,
|
||||
} from "components/Inputs/AutoComplete/InputAutoComplete";
|
||||
import { prettyName } from "utils/formatting";
|
||||
import InputBoolean from "components/Inputs/InputBoolean";
|
||||
import { SelectorNumber, SelectorText } from "haService/fieldTypes";
|
||||
import InputYaml from "components/Inputs/InputYaml";
|
||||
import { useSnackbar } from "notistack";
|
||||
import { InputEntity } from "components/Inputs/InputEntities";
|
||||
import { InputEntity } from "components/Inputs/AutoComplete/InputEntities";
|
||||
import { ButtonIcon } from "components/Icons/ButtonIcons";
|
||||
|
||||
export type ServiceEditorFieldProps = {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import "./ServiceEditorTarget.css";
|
||||
import { InputDevice } from "components/Inputs/InputDevice";
|
||||
import { InputEntity } from "components/Inputs/InputEntities";
|
||||
import { InputDevice } from "components/Inputs/AutoComplete/InputDevice";
|
||||
import { InputEntity } from "components/Inputs/AutoComplete/InputEntities";
|
||||
import { Targets } from "haService/fieldTypes";
|
||||
import { FC } from "react";
|
||||
import { InputArea } from "components/Inputs/InputArea";
|
||||
import { InputArea } from "components/Inputs/AutoComplete/InputArea";
|
||||
|
||||
type RawTargetData = {
|
||||
entity_id?: string[] | string;
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
ServiceEditorData,
|
||||
} from "./options";
|
||||
import { ServiceEditorField } from "./ServiceEditorField";
|
||||
import { InputAutoComplete } from "components/Inputs/InputAutoComplete";
|
||||
import { InputAutoComplete } from "components/Inputs/AutoComplete/InputAutoComplete";
|
||||
import { ServiceEditorTarget } from "./ServiceEditorTarget";
|
||||
|
||||
export type ServiceEditorProps = {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { BaseOption } from "components/Inputs/InputAutoComplete";
|
||||
import { BaseOption } from "components/Inputs/AutoComplete/InputAutoComplete";
|
||||
import { FieldData, TypedHassService } from "haService/fieldTypes";
|
||||
import { prettyName } from "utils/formatting";
|
||||
|
||||
@@ -7,17 +7,22 @@ export type ServiceEditorData = {
|
||||
target: Record<string, any>;
|
||||
};
|
||||
export type ServiceEditorOption = BaseOption<{
|
||||
data: FieldData
|
||||
data: FieldData;
|
||||
}>;
|
||||
|
||||
export const convertFieldToOption = (id: string, data: FieldData): ServiceEditorOption => ({
|
||||
export const convertFieldToOption = (
|
||||
id: string,
|
||||
data: FieldData
|
||||
): ServiceEditorOption => ({
|
||||
id,
|
||||
label: data.name ?? prettyName(id),
|
||||
data,
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
export const splitUpOptions = (service: TypedHassService, data: ServiceEditorData) => {
|
||||
export const splitUpOptions = (
|
||||
service: TypedHassService,
|
||||
data: ServiceEditorData
|
||||
) => {
|
||||
const required: ServiceEditorOption[] = [];
|
||||
const additional: ServiceEditorOption[] = [];
|
||||
const incmFields: string[] = [];
|
||||
@@ -28,7 +33,7 @@ export const splitUpOptions = (service: TypedHassService, data: ServiceEditorDat
|
||||
required.push(opt);
|
||||
} else {
|
||||
if (data.field[opt.id]) {
|
||||
incmFields.push(opt.id)
|
||||
incmFields.push(opt.id);
|
||||
} else {
|
||||
additional.push(opt);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import { Connection, getCollection } from "home-assistant-js-websocket";
|
||||
import { useHassCollection } from "./useHassCollection";
|
||||
import { Option, BaseOption } from "components/Inputs/InputAutoComplete";
|
||||
import {
|
||||
Option,
|
||||
BaseOption,
|
||||
} from "components/Inputs/AutoComplete/InputAutoComplete";
|
||||
import { EntityRegisteryItem, HassEntitiesRegistry } from "./types";
|
||||
import { prettyName } from "utils/formatting";
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Option } from "components/Inputs/InputAutoComplete";
|
||||
import { Option } from "components/Inputs/AutoComplete/InputAutoComplete";
|
||||
import { HACollectionState, useHassCollection } from "./useHassCollection";
|
||||
import { entitiesColl, HassEntities } from "home-assistant-js-websocket";
|
||||
import { entitySourceColl } from "./additionalCollections";
|
||||
|
||||
@@ -4,7 +4,7 @@ import { Page } from "components/Page";
|
||||
import { useHA } from "haService";
|
||||
import InputYaml from "components/Inputs/InputYaml";
|
||||
import { InputList } from "components/Inputs/InputList";
|
||||
import { Button } from "components/Inputs/Button";
|
||||
import { Button } from "components/Inputs/Buttons/Button";
|
||||
import { ServiceEditor } from "components/ServiceEditor";
|
||||
|
||||
const Test: FC = () => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { BaseOption } from "components/Inputs/InputAutoComplete";
|
||||
import { BaseOption } from "components/Inputs/AutoComplete/InputAutoComplete";
|
||||
import { MessageBase } from "home-assistant-js-websocket";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { prettyName } from "utils/formatting";
|
||||
|
||||
@@ -9,7 +9,7 @@ import { useHassCollection } from "./useHassCollection";
|
||||
import { useHAConnection } from "./connection";
|
||||
import { useSnackbar } from "notistack";
|
||||
import { TypedHassService } from "./fieldTypes";
|
||||
import { Option } from "components/Inputs/InputAutoComplete";
|
||||
import { Option } from "components/Inputs/AutoComplete/InputAutoComplete";
|
||||
import { getDeviceExtraWsCalls } from "./extras";
|
||||
import { useHAEntities } from "./HAEntities";
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import { Page } from "components/Page";
|
||||
import { useHA } from "haService";
|
||||
import InputYaml from "components/Inputs/InputYaml";
|
||||
import { InputList } from "components/Inputs/InputList";
|
||||
import { Button } from "components/Inputs/Button";
|
||||
import { Button } from "components/Inputs/Buttons/Button";
|
||||
import { ServiceEditor } from "components/ServiceEditor";
|
||||
|
||||
const Test: FC = () => {
|
||||
|
||||
Reference in new issue
Block a user