diff --git a/webapp/src/components/ConditionEditor/ConditionNodeBase.css b/webapp/src/components/ConditionEditor/ConditionNodeBase.css index 74313ce..65e6b18 100644 --- a/webapp/src/components/ConditionEditor/ConditionNodeBase.css +++ b/webapp/src/components/ConditionEditor/ConditionNodeBase.css @@ -64,4 +64,44 @@ align-items: center; padding: 0.5em; background-color: var(--mui-secondary-contrastText); +} + +.condition-node--time-editor { + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + gap: 0.25em; +} + +.condition-node--time-editor--ba { + display: flex; + flex-direction: row; + justify-content: flex-start; + align-items: center; + gap: 0.5em; + padding-top: 1.5em; + padding-bottom: 0.25em; + position: relative; + width: fit-content; + max-width: 100%; + overflow: hidden; +} + +.condition-node--time-editor--ba button.remove { + padding: 0.25em; + min-width: fit-content; + color: var(--mui-error-light); + border-color: transparent; +} + +.condition-node--time-editor--ba button.remove:hover { + border-color: var(--mui-error-light); + border-radius: 20px; +} + +.condition-node--time-editor--ba .label { + position: absolute; + top: 0; + left: 0.2em; } \ No newline at end of file diff --git a/webapp/src/components/ConditionEditor/editorRender.tsx b/webapp/src/components/ConditionEditor/editorRender.tsx index 0c7c273..5c7f530 100644 --- a/webapp/src/components/ConditionEditor/editorRender.tsx +++ b/webapp/src/components/ConditionEditor/editorRender.tsx @@ -1,4 +1,4 @@ -import { FC } from "react"; +import { FC, useState } from "react"; import { AutomationCondition, DeviceCondition, @@ -26,6 +26,12 @@ 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 { prettyName } from "utils/formatting"; +import { InputList } from "components/Inputs/InputList"; +import { Button } from "components/Inputs/Button"; +import { RemoveCircle } from "@mui/icons-material"; +import { DayOfWeek } from "types/automations/common"; interface Editor extends FC<{ @@ -274,31 +280,86 @@ export const StateEditor: Editor = ({ ); }; +type TimeEditorShows = "after" | "before" | "weekday"; export const TimeEditor: Editor = ({ onChange, condition }) => { + const [shows, setShows] = useState( + Object.keys(condition).filter((k) => + ["after", "before", "weekday"].includes(k) + ) as any + ); return ( - <> - - onChange({ - ...condition, - after, - }) +
+ {shows.map((show) => { + if (show === "after" || show === "before") { + return ( +
+ {prettyName(show)} + + onChange({ + ...condition, + [show]: v, + }) + } + /> + +
+ ); + } else { + return ( +
+ opt} + getLabel={(opt) => { + return { + mon: "Monday", + tue: "Tuesday", + wed: "Wednesday", + thu: "Thursday", + fri: "Friday", + sat: "Saturday", + sun: "Sunday", + }[opt]; + }} + onChange={(weekday: any) => + onChange({ + ...condition, + weekday: weekday ?? [], + }) + } + options={["mon", "tue", "wed", "thu", "fri", "sat", "sun"]} + /> +
+ ); } - /> - - onChange({ - ...condition, - before, - }) - } - /> - Weekday not support for no, use yaml for now {condition.weekday} - + })} + {shows.length < 3 && ( + !shows.includes(k) + )} + onChange={(k: any) => { + setShows(shows.concat([k])); + }} + /> + )} +
); }; diff --git a/webapp/src/components/NodeEditor/OptionManager/TriggerTime.tsx b/webapp/src/components/NodeEditor/OptionManager/TriggerTime.tsx index 72aad69..639134e 100644 --- a/webapp/src/components/NodeEditor/OptionManager/TriggerTime.tsx +++ b/webapp/src/components/NodeEditor/OptionManager/TriggerTime.tsx @@ -1,8 +1,6 @@ import "./TriggerTime.css"; import HelpOutlinedIcon from "@mui/icons-material/HelpOutlined"; -import AccessTimeOutlinedIcon from "@mui/icons-material/AccessTimeOutlined"; -import MoreTimeOutlinedIcon from "@mui/icons-material/MoreTimeOutlined"; import { OptionManager } from "./OptionManager"; import { @@ -10,19 +8,12 @@ import { AutomationTriggerExactTime, AutomationTriggerTimePattern, } from "types/automations/triggers"; -import { InputTime } from "components/Inputs/InputTime"; -import { - convertObjectToAutomationTimeString, - isAutomationTimeString24Hours, -} from "utils/time"; import InputText from "components/Inputs/InputText"; import { FC } from "react"; import { InputList } from "components/Inputs/InputList"; -import { InputEntity } from "components/Inputs/InputEntities"; 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 = {