diff --git a/webapp/src/components/ConditionEditor/index.stories.tsx b/webapp/src/components/ConditionEditor/index.stories.tsx index c26687d..ebb6c1f 100644 --- a/webapp/src/components/ConditionEditor/index.stories.tsx +++ b/webapp/src/components/ConditionEditor/index.stories.tsx @@ -9,6 +9,9 @@ export default { title: "ConditionEditor", component: ConditionEditor, parameters: { actions: { argTypesRegex: "^on.*" } }, + args: { + initialViewMode: "edit", + }, } as ComponentMeta; const Template: ComponentStory = ({ @@ -79,6 +82,29 @@ LogicCondition.args = { ], } as AutomationCondition, }; +export const TimeCondition = Template.bind({}); +TimeCondition.args = { + condition: { + condition: "or", + conditions: [ + { + condition: "time", + }, + { + condition: "time", + after: "10:00:00", + }, + { + condition: "time", + before: "input_datetime.test", + }, + { + condition: "time", + weekday: ["fri"], + }, + ], + } as AutomationCondition, +}; export const MultipleConditions: ComponentStory = ( args diff --git a/webapp/src/components/Inputs/InputTimeEntity.css b/webapp/src/components/Inputs/InputTimeEntity.css new file mode 100644 index 0000000..10a061d --- /dev/null +++ b/webapp/src/components/Inputs/InputTimeEntity.css @@ -0,0 +1,21 @@ +.input-time-entity { + display: flex; + flex-direction: row; + justify-content: center; + align-items: center; + gap: 0.5em; +} + +.input-time-entity button.MuiButtonBase-root { + border-color: var(--mui-info-light); + background-color: var(--mui-info-main); + color: var(--mui-info-contrastText); +} + +.input-time-entity button.MuiButtonBase-root:hover { + background-color: var(--mui-info-light); +} + +.input-time-entity .input-autocomplete { + min-width: 10em; +} \ No newline at end of file diff --git a/webapp/src/components/Inputs/InputTimeEntity.stories.tsx b/webapp/src/components/Inputs/InputTimeEntity.stories.tsx new file mode 100644 index 0000000..8bd4877 --- /dev/null +++ b/webapp/src/components/Inputs/InputTimeEntity.stories.tsx @@ -0,0 +1,35 @@ +import { ComponentMeta, ComponentStory } from "@storybook/react"; +import { Page } from "components/Page"; +import { useState } from "react"; + +import { InputTimeEntity } from "./InputTimeEntity"; + +export default { + title: "Inputs/InputTimeEntity", + component: InputTimeEntity, + parameters: { actions: { argTypesRegex: "^on.*" } }, +} as ComponentMeta; + +const Template: ComponentStory = (args) => { + const [value, setValue] = useState(""); + return ( + +
+ { + setValue(t); + args.onChange(t); + }} + /> +
+
+ ); +}; + +export const SimpleText = Template.bind({}); diff --git a/webapp/src/components/Inputs/InputTimeEntity.tsx b/webapp/src/components/Inputs/InputTimeEntity.tsx new file mode 100644 index 0000000..39c15b0 --- /dev/null +++ b/webapp/src/components/Inputs/InputTimeEntity.tsx @@ -0,0 +1,68 @@ +import "./InputTimeEntity.css"; + +import { FC, ReactNode } from "react"; + +import AccessTimeOutlinedIcon from "@mui/icons-material/AccessTimeOutlined"; +import MoreTimeOutlinedIcon from "@mui/icons-material/MoreTimeOutlined"; + +import { ButtonIcon } from "components/Icons/ButtonIcons"; +import { + convertObjectToAutomationTimeString, + isAutomationTimeString24Hours, +} from "utils/time"; +import { InputEntity } from "./InputEntities"; +import { InputTime } from "./InputTime"; + +export type InputTimeEntityProps = { + value: string; + onChange: (v: string) => void; + className?: string; +}; +export const InputTimeEntity: FC = ({ + value, + onChange, + className = "", +}) => { + const is24Hour = isAutomationTimeString24Hours(value); + let editor: ReactNode; + if (is24Hour) { + editor = ( + + onChange(t ? convertObjectToAutomationTimeString(t) : "00:00:00") + } + /> + ); + } else { + editor = ( + onChange(t ?? "")} + /> + ); + } + + return ( +
+ {editor}{" "} + : } + onClick={() => { + if (is24Hour) { + onChange(""); + } else { + onChange("00:00:00"); + } + }} + /> +
+ ); +}; diff --git a/webapp/src/components/NodeEditor/OptionManager/TriggerTime.css b/webapp/src/components/NodeEditor/OptionManager/TriggerTime.css index 190bb3e..e20fdd5 100644 --- a/webapp/src/components/NodeEditor/OptionManager/TriggerTime.css +++ b/webapp/src/components/NodeEditor/OptionManager/TriggerTime.css @@ -56,27 +56,4 @@ border-color: var(--mui-info-light); color: var(--mui-info-main); background-color: var(--mui-info-contrastText); -} - -.trigger-time--exact--option { - display: flex; - flex-direction: row; - justify-content: center; - align-items: center; - padding-top: 0.5em; - gap: 0.5em; -} - -.trigger-time--exact--option button.MuiButtonBase-root { - border-color: var(--mui-info-light); - background-color: var(--mui-info-main); - color: var(--mui-info-contrastText); -} - -.trigger-time--exact--option button.MuiButtonBase-root:hover { - background-color: var(--mui-info-light); -} - -.trigger-time--exact--option .input-autocomplete { - min-width: 10em; } \ No newline at end of file diff --git a/webapp/src/components/NodeEditor/OptionManager/TriggerTime.tsx b/webapp/src/components/NodeEditor/OptionManager/TriggerTime.tsx index 0eddaf1..72aad69 100644 --- a/webapp/src/components/NodeEditor/OptionManager/TriggerTime.tsx +++ b/webapp/src/components/NodeEditor/OptionManager/TriggerTime.tsx @@ -23,6 +23,7 @@ import { Button } from "components/Inputs/Button"; import { useState } from "react"; import AddIcon from "@mui/icons-material/Add"; import { ButtonIcon } from "components/Icons/ButtonIcons"; +import { InputTimeEntity } from "components/Inputs/InputTimeEntity"; export const TriggerTime: OptionManager = { defaultState: () => ({ @@ -102,53 +103,13 @@ export const TriggerExactTime: FC<{ return (
{times.map((v, i) => { - let editor: JSX.Element; - const is24Hour = isAutomationTimeString24Hours(v); - if (is24Hour) { - editor = ( - - update( - _at ? convertObjectToAutomationTimeString(_at) : "00:00:00", - i - ) - } - /> - ); - } else { - editor = ( - update(_at ?? "", i)} - /> - ); - } return ( -
- {editor}{" "} - : - } - onClick={() => { - if (is24Hour) { - update("", i); - } else { - update("00:00:00", i); - } - }} - /> -
+ update(t, i)} + /> ); })}