added weekday and refactored condition time
This commit is contained in:
1 parent
184734ee70
commit
582859b35b
3 files changed
+124
-32
No files matched your search
@@ -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;
|
||||
}
|
||||
@@ -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<C extends AutomationCondition>
|
||||
extends FC<{
|
||||
@@ -274,31 +280,86 @@ export const StateEditor: Editor<StateCondition> = ({
|
||||
);
|
||||
};
|
||||
|
||||
type TimeEditorShows = "after" | "before" | "weekday";
|
||||
export const TimeEditor: Editor<TimeCondition> = ({ onChange, condition }) => {
|
||||
const [shows, setShows] = useState<TimeEditorShows[]>(
|
||||
Object.keys(condition).filter((k) =>
|
||||
["after", "before", "weekday"].includes(k)
|
||||
) as any
|
||||
);
|
||||
return (
|
||||
<>
|
||||
<InputTime
|
||||
label="After"
|
||||
value={condition.after}
|
||||
onChange={(after) =>
|
||||
onChange({
|
||||
...condition,
|
||||
after,
|
||||
})
|
||||
<div className="condition-node--time-editor">
|
||||
{shows.map((show) => {
|
||||
if (show === "after" || show === "before") {
|
||||
return (
|
||||
<div className="condition-node--time-editor--ba" key={show}>
|
||||
<b className="label">{prettyName(show)}</b>
|
||||
<InputTimeEntity
|
||||
value={condition[show] ?? ""}
|
||||
onChange={(v) =>
|
||||
onChange({
|
||||
...condition,
|
||||
[show]: v,
|
||||
})
|
||||
}
|
||||
/>
|
||||
<Button
|
||||
className="remove"
|
||||
onClick={() => {
|
||||
setShows(shows.filter((k) => k !== show));
|
||||
const upd = { ...condition };
|
||||
delete upd[show];
|
||||
onChange({ ...upd });
|
||||
}}
|
||||
>
|
||||
<RemoveCircle />
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
} else {
|
||||
return (
|
||||
<div>
|
||||
<InputAutoComplete
|
||||
label="Weekday"
|
||||
value={condition.weekday ?? []}
|
||||
multiple={true}
|
||||
getID={(opt) => 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"]}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
/>
|
||||
<InputTime
|
||||
label="Before"
|
||||
value={condition.before}
|
||||
onChange={(before) =>
|
||||
onChange({
|
||||
...condition,
|
||||
before,
|
||||
})
|
||||
}
|
||||
/>
|
||||
<b>Weekday not support for no, use yaml for now</b> {condition.weekday}
|
||||
</>
|
||||
})}
|
||||
{shows.length < 3 && (
|
||||
<InputList
|
||||
className="condition-node--time-editor--new"
|
||||
label="Option"
|
||||
options={["after", "before", "weekday"].filter(
|
||||
(k: any) => !shows.includes(k)
|
||||
)}
|
||||
onChange={(k: any) => {
|
||||
setShows(shows.concat([k]));
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user