handling missing ids better + more tranlsations
This commit is contained in:
1 parent
69a9805c02
commit
774ebe482a
45 files changed
+556
-262
No files matched your search
@@ -14,7 +14,7 @@ const { componentMeta, make } = makeStory({
|
||||
}) => {
|
||||
const [[metadata, tags], setState] = useState([args.metadata, args.tags]);
|
||||
const tagDB = useTagDB(
|
||||
[{ id: metadata.id, tags: Object.fromEntries(tags) }],
|
||||
metadata.id ? [{ id: metadata.id, tags: Object.fromEntries(tags) }] : [],
|
||||
(_, t) => setState([metadata, Object.entries(t)])
|
||||
);
|
||||
|
||||
|
||||
@@ -104,7 +104,7 @@ export const AutoInfoBox: FC<AutoInfoBoxProps> = ({
|
||||
<div className="automation-editor--info-box-inner">
|
||||
<InputText
|
||||
label={langStore.get("ID")}
|
||||
value={metadata.id}
|
||||
value={metadata.id ?? langStore.get("N/A")}
|
||||
onChange={onUpdateMetadata("id")}
|
||||
/>
|
||||
<InputText
|
||||
@@ -125,7 +125,7 @@ export const AutoInfoBox: FC<AutoInfoBoxProps> = ({
|
||||
options={["parallel", "single", "queued", "restart"]}
|
||||
/>
|
||||
<div className="automation-editor--info-box--tags">
|
||||
<h1>Tags</h1>
|
||||
<h1>{langStore.get("TAGS")}</h1>
|
||||
<div className="automation-editor--info-box--tag-list">
|
||||
{tags.map(([tagName, tagValue], tagIndex) => (
|
||||
<div key={tagIndex} className="automation-editor--info-box--tag">
|
||||
|
||||
@@ -19,7 +19,7 @@ const { make, componentMeta } = makeStory({
|
||||
<AutomationEditor
|
||||
{...args}
|
||||
tagDB={useTagDB(
|
||||
state ? [{ id: state.id, tags: state.tags }] : [],
|
||||
state && state.id ? [{ id: state.id, tags: state.tags }] : [],
|
||||
() => {}
|
||||
)}
|
||||
automation={state}
|
||||
|
||||
@@ -32,6 +32,8 @@ import { MiniFailure } from "types/validators/helper";
|
||||
import { AutoInfoBox } from "./AutoInfoBox";
|
||||
import { useAutomatioEditorState, EditorData } from "./state";
|
||||
import { useLang } from "lang";
|
||||
import { useSnackbar } from "notistack";
|
||||
import { Alert } from "@mui/material";
|
||||
|
||||
interface Props {
|
||||
automation?: AutomationData | BareAutomationData;
|
||||
@@ -41,6 +43,8 @@ interface Props {
|
||||
onDelete: () => void;
|
||||
tagDB: TagDB;
|
||||
isNew?: boolean;
|
||||
readonly: boolean;
|
||||
issue?: string;
|
||||
}
|
||||
export const AutomationEditor: FC<Props> = ({
|
||||
dims,
|
||||
@@ -49,10 +53,12 @@ export const AutomationEditor: FC<Props> = ({
|
||||
onDelete,
|
||||
onTrigger,
|
||||
tagDB,
|
||||
isNew,
|
||||
readonly,
|
||||
issue,
|
||||
}) => {
|
||||
// state
|
||||
const langStore = useLang();
|
||||
const snackbr = useSnackbar();
|
||||
const {
|
||||
state,
|
||||
updateSequence,
|
||||
@@ -63,7 +69,15 @@ export const AutomationEditor: FC<Props> = ({
|
||||
save,
|
||||
saveAndUpdate,
|
||||
undo,
|
||||
} = useAutomatioEditorState(propsAutos, propsOnUpdate);
|
||||
} = useAutomatioEditorState(propsAutos, (auto) => {
|
||||
if (readonly) {
|
||||
snackbr.enqueueSnackbar(langStore.get("READONLY_CANNOT_UPDATE"), {
|
||||
color: "warning",
|
||||
});
|
||||
} else {
|
||||
propsOnUpdate(auto);
|
||||
}
|
||||
});
|
||||
const [infoBoxOpen, setInfoBox] = useState(false);
|
||||
const [
|
||||
{ ckFlipped },
|
||||
@@ -95,7 +109,13 @@ export const AutomationEditor: FC<Props> = ({
|
||||
);
|
||||
}
|
||||
return (
|
||||
<div className={["automation-editor", state.status].join(" ")}>
|
||||
<div
|
||||
className={[
|
||||
"automation-editor",
|
||||
state.status,
|
||||
readonly ? "readonly" : "",
|
||||
].join(" ")}
|
||||
>
|
||||
{state.status === "saving" && (
|
||||
<LinearProgress className="linear-loader" />
|
||||
)}
|
||||
@@ -112,13 +132,15 @@ export const AutomationEditor: FC<Props> = ({
|
||||
state.status,
|
||||
].join(" ")}
|
||||
>
|
||||
<Button onClick={() => setInfoBox(false)}>Close</Button>
|
||||
<Button onClick={() => setInfoBox(false)}>
|
||||
{langStore.get("CLOSE")}
|
||||
</Button>
|
||||
<Button
|
||||
className={"automation-editor--flow-wrapper--toolbar--save-btn"}
|
||||
onClick={save}
|
||||
disabled={state.status !== "changed"}
|
||||
disabled={state.status !== "changed" || readonly}
|
||||
>
|
||||
Save <CheckMarkIcon color="#bf4" />
|
||||
{langStore.get("SAVE")} <CheckMarkIcon color="#bf4" />
|
||||
</Button>
|
||||
</div>
|
||||
</AutoInfoBox>
|
||||
@@ -220,6 +242,11 @@ export const AutomationEditor: FC<Props> = ({
|
||||
{langStore.get("SAVE")} <CheckMarkIcon color="#bf4" />
|
||||
</Button>
|
||||
</div>
|
||||
{readonly && (
|
||||
<Alert color="warning">
|
||||
{langStore.get("READONLY_MODE")} - {issue}
|
||||
</Alert>
|
||||
)}
|
||||
<DAGAutomationGraph
|
||||
action={state.data.action}
|
||||
trigger={state.data.trigger}
|
||||
@@ -306,16 +333,14 @@ export const ValidationBox: FC<{
|
||||
<div className="automation-editor-failures">
|
||||
<ul>
|
||||
{failures.map((f, i) => (
|
||||
<>
|
||||
<li key={i}>
|
||||
<b>{f.path}</b>:
|
||||
<ul>
|
||||
{f.message.map((m, j) => (
|
||||
<li key={j}>{m}</li>
|
||||
))}
|
||||
</ul>
|
||||
</li>
|
||||
</>
|
||||
<li key={i}>
|
||||
<b>{f.path}</b>:
|
||||
<ul>
|
||||
{f.message.map((m, j) => (
|
||||
<li key={j}>{m}</li>
|
||||
))}
|
||||
</ul>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
<span>{langStore.get("VALIDATION_PLEASE_CORRECT_FILE")}</span>
|
||||
|
||||
@@ -23,6 +23,7 @@ const { make, componentMeta } = makeStory({
|
||||
id: "1",
|
||||
title: "Example",
|
||||
entityId: "automation.1",
|
||||
readonly: false,
|
||||
description: "Amazing automation!",
|
||||
tags: {},
|
||||
state: "on",
|
||||
@@ -38,6 +39,7 @@ const { make, componentMeta } = makeStory({
|
||||
id: "2",
|
||||
title: "Example 2",
|
||||
entityId: "automation.2",
|
||||
readonly: false,
|
||||
description: "Cool!",
|
||||
state: "on",
|
||||
source_file: "automation.yaml",
|
||||
@@ -89,6 +91,7 @@ export const Nested = make({
|
||||
entityId: "automation.1",
|
||||
description: "",
|
||||
title: "Automation #1",
|
||||
readonly: false,
|
||||
state: "on",
|
||||
source_file: "automation.yaml",
|
||||
source_file_type: "list",
|
||||
@@ -102,6 +105,7 @@ export const Nested = make({
|
||||
{
|
||||
id: "2",
|
||||
entityId: "automation.2",
|
||||
readonly: false,
|
||||
description: "another one",
|
||||
title: "Automation #2",
|
||||
state: "off",
|
||||
@@ -117,6 +121,7 @@ export const Nested = make({
|
||||
{
|
||||
id: "3",
|
||||
entityId: "automation.3",
|
||||
readonly: false,
|
||||
description: "bad one",
|
||||
title: "Automation #3",
|
||||
state: "offing",
|
||||
@@ -153,6 +158,7 @@ export const Nested = make({
|
||||
},
|
||||
data: [
|
||||
{
|
||||
readonly: false,
|
||||
id: "4",
|
||||
entityId: "automation.4",
|
||||
description: "Cool thing",
|
||||
|
||||
@@ -52,6 +52,7 @@ export const useAutomationDB = (
|
||||
const auto = defaultAutomation(String(Date.now()));
|
||||
setNewAuto([
|
||||
{
|
||||
readonly: false,
|
||||
id: auto.id,
|
||||
entityId: "",
|
||||
title: auto.alias ?? "",
|
||||
@@ -77,13 +78,18 @@ const genMapping = (
|
||||
tagsDB: TagDB,
|
||||
langStore: LangStore
|
||||
) => {
|
||||
const configData: Record<string, AutomationData> = configAutomations.reduce(
|
||||
(all, n) => ({
|
||||
...all,
|
||||
[n.id]: n,
|
||||
}),
|
||||
{}
|
||||
);
|
||||
const configDataNoId: AutomationData[] = [];
|
||||
const configData: Record<string, AutomationData & { id: string }> =
|
||||
configAutomations.reduce((all, n) => {
|
||||
if (n.id) {
|
||||
return {
|
||||
...all,
|
||||
[n.id]: n,
|
||||
};
|
||||
}
|
||||
configDataNoId.push(n);
|
||||
return all;
|
||||
}, {});
|
||||
const automatioinMap: Record<
|
||||
string,
|
||||
[AutomationManagerAuto, AutomationData | null]
|
||||
@@ -91,7 +97,7 @@ const genMapping = (
|
||||
Object.entries(haEntities)
|
||||
.filter(([entityId, _]) => entityId.toLowerCase().startsWith("automation."))
|
||||
.forEach(([entityId, entityData], i) => {
|
||||
const autoId = entityData.attributes.id ?? `${entityData.state}-${i}`;
|
||||
const autoId = entityData.attributes.id ?? entityId.split(".")[1];
|
||||
let title = entityData.attributes.friendly_name ?? "";
|
||||
let description = "";
|
||||
let issue: string | undefined = ["on", "off"].includes(entityData.state)
|
||||
@@ -127,12 +133,13 @@ const genMapping = (
|
||||
source_file_type,
|
||||
configuration_key,
|
||||
issue,
|
||||
readonly: found == null,
|
||||
},
|
||||
found,
|
||||
];
|
||||
});
|
||||
|
||||
Object.values(configData).forEach((auto) => {
|
||||
Object.values(configData).forEach((auto, i) => {
|
||||
automatioinMap[auto.id] = [
|
||||
{
|
||||
id: auto.id,
|
||||
@@ -145,10 +152,55 @@ const genMapping = (
|
||||
source_file_type: auto.source_file_type,
|
||||
configuration_key: auto.configuration_key,
|
||||
issue: langStore.get("ISSUES_NO_LOAD_AUTOMATION"),
|
||||
readonly: false,
|
||||
},
|
||||
auto,
|
||||
];
|
||||
});
|
||||
let failedGeneration: number = 0;
|
||||
configDataNoId.forEach((auto) => {
|
||||
let generatedAutoId = `automation_${failedGeneration + 1}`;
|
||||
if (auto.alias) {
|
||||
generatedAutoId = auto.alias
|
||||
.toLowerCase()
|
||||
.replaceAll(/\W/g, " ")
|
||||
.trim()
|
||||
.replaceAll(" ", "_");
|
||||
} else {
|
||||
failedGeneration += 1;
|
||||
}
|
||||
if (automatioinMap[generatedAutoId]) {
|
||||
automatioinMap[generatedAutoId] = [
|
||||
{
|
||||
...automatioinMap[generatedAutoId][0],
|
||||
issue: langStore.get("ISSUE_MUST_CONTAIN_A_UNQIUE_ID_TO_EDIT", {
|
||||
sourceFile: auto.source_file,
|
||||
}),
|
||||
readonly: true,
|
||||
},
|
||||
auto,
|
||||
];
|
||||
} else {
|
||||
automatioinMap[generatedAutoId] = [
|
||||
{
|
||||
id: generatedAutoId,
|
||||
entityId: "",
|
||||
title: auto.alias ?? "",
|
||||
description: auto.description ?? "",
|
||||
state: langStore.get("AUTOMATION_STATE_UNREGISTERED"),
|
||||
tags: {},
|
||||
source_file: auto.source_file,
|
||||
source_file_type: auto.source_file_type,
|
||||
configuration_key: auto.configuration_key,
|
||||
issue: langStore.get("ISSUE_MUST_CONTAIN_A_UNQIUE_ID_TO_EDIT", {
|
||||
sourceFile: auto.source_file,
|
||||
}),
|
||||
readonly: true,
|
||||
},
|
||||
auto,
|
||||
];
|
||||
}
|
||||
});
|
||||
|
||||
return automatioinMap;
|
||||
};
|
||||
@@ -50,6 +50,8 @@ export const AutomationManagerLoaded: FC<
|
||||
{state.currentAutomationId !== null ? (
|
||||
state.currentAutomation ? (
|
||||
<AutomationEditor
|
||||
readonly={state.currentAutomationIsReadOnly}
|
||||
issue={state.currentAutomationIssue}
|
||||
dims={{
|
||||
...DEFAULT_DIMS,
|
||||
flipped: true,
|
||||
|
||||
@@ -37,7 +37,11 @@ export const useAutomationManagerState = ({
|
||||
.map(({ id, tags = {} }) => ({
|
||||
id,
|
||||
tags,
|
||||
})),
|
||||
}))
|
||||
.filter(({ id }) => typeof id === "string") as Array<{
|
||||
id: string;
|
||||
tags: Record<string, string>;
|
||||
}>,
|
||||
onUpdateTags
|
||||
);
|
||||
const automationDB = useAutomationDB(hassEntities, configAutomations, tagsDB);
|
||||
@@ -78,6 +82,14 @@ export const useAutomationManagerState = ({
|
||||
get currentAutomationEntityId(): string | null {
|
||||
return currentAutomation === null ? null : currentAutomation[0].entityId;
|
||||
},
|
||||
get currentAutomationIsReadOnly(): boolean {
|
||||
return currentAutomation === null ? true : currentAutomation[0].readonly;
|
||||
},
|
||||
get currentAutomationIssue(): string | undefined {
|
||||
return currentAutomation === null
|
||||
? undefined
|
||||
: currentAutomation[0].issue;
|
||||
},
|
||||
async setSelectedAutomationId(i: string | null, force: boolean = false) {
|
||||
if (methods.currentAutomationIsNew && !force) {
|
||||
if (!(await stillHaveNewAreYouSure())) {
|
||||
@@ -94,7 +106,9 @@ export const useAutomationManagerState = ({
|
||||
}
|
||||
}
|
||||
const auto = automationDB.addNew();
|
||||
methods.setSelectedAutomationId(auto.id, true);
|
||||
if (auto.id) {
|
||||
methods.setSelectedAutomationId(auto.id, true);
|
||||
}
|
||||
},
|
||||
editorUpdateAutomation(auto: AutomationData | BareAutomationData) {
|
||||
if (methods.currentAutomationIsNew) {
|
||||
|
||||
@@ -71,6 +71,7 @@ const story = makeStory({
|
||||
source_file: "automation.yaml",
|
||||
source_file_type: "list",
|
||||
configuration_key: ["automation"],
|
||||
readonly: false,
|
||||
},
|
||||
]);
|
||||
setSelAutoId(id);
|
||||
@@ -100,6 +101,7 @@ const makeAuto = (
|
||||
source_file: "automation.yaml",
|
||||
source_file_type: "list",
|
||||
configuration_key: ["automation"],
|
||||
readonly: false,
|
||||
...data,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -38,10 +38,11 @@ const automations: AutomationManagerAuto[] = [
|
||||
description: a.description ?? "",
|
||||
state: "on",
|
||||
tags: a.tags,
|
||||
id: a.id,
|
||||
id: a.id as string,
|
||||
isSelected: false,
|
||||
source_file: "automation.yaml",
|
||||
source_file_type: "list",
|
||||
readonly: false,
|
||||
configuration_key: ["automation"],
|
||||
}));
|
||||
|
||||
@@ -51,7 +52,8 @@ const bigList = bigMockAutoList.map<AutomationManagerAuto>((a) => ({
|
||||
description: a.description ?? "",
|
||||
state: "on",
|
||||
tags: a.tags,
|
||||
id: a.id,
|
||||
id: a.id as string,
|
||||
readonly: false,
|
||||
isSelected: false,
|
||||
source_file: "automation.yaml",
|
||||
source_file_type: "list",
|
||||
|
||||
@@ -12,6 +12,7 @@ export type AutomationManagerAuto = AutomationManagerAutoUpdatable & {
|
||||
source_file: string;
|
||||
source_file_type: string;
|
||||
configuration_key: string[];
|
||||
readonly: boolean;
|
||||
};
|
||||
export type AutomationManagerAutoItem = AutomationManagerAuto & {
|
||||
flags: AutomationManagerItemFlags;
|
||||
|
||||
@@ -271,7 +271,7 @@ export const StateEditor: Editor<StateCondition> = ({
|
||||
}
|
||||
/>
|
||||
<InputTime
|
||||
label="For"
|
||||
label={langStore.get("FOR")}
|
||||
value={condition.for}
|
||||
onChange={(_for) =>
|
||||
onChange({
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
InputAutoCompletePropsBase,
|
||||
} from "./InputAutoComplete";
|
||||
import { useHAAreas } from "haService/AreaRegistry";
|
||||
import { useLang } from "lang";
|
||||
|
||||
export type InputAreaProps = InputAutoCompletePropsBase & {
|
||||
restrictToDomain?: string[];
|
||||
@@ -11,12 +12,13 @@ export type InputAreaProps = InputAutoCompletePropsBase & {
|
||||
};
|
||||
|
||||
export const InputArea: FC<InputAreaProps> = (props) => {
|
||||
const lang = useLang();
|
||||
// state
|
||||
const areas = useHAAreas();
|
||||
return (
|
||||
<InputAutoComplete
|
||||
{...props}
|
||||
label={props.label ?? "Area"}
|
||||
label={props.label ?? lang.get("AREA")}
|
||||
getID={areas.getID}
|
||||
getLabel={areas.getLabel}
|
||||
options={areas.getOptions()}
|
||||
|
||||
@@ -7,6 +7,7 @@ import Popper from "@mui/material/Popper";
|
||||
import { SearchItem } from "./extras";
|
||||
import { ReactNode } from "react";
|
||||
import { prettyName } from "utils/formatting";
|
||||
import { useLang } from "lang";
|
||||
|
||||
export type BaseOption<T = {}> = {
|
||||
id: string;
|
||||
@@ -65,6 +66,7 @@ export function computeSimilarity(
|
||||
export function InputAutoComplete<T extends Option>(
|
||||
props: InputAutoCompleteProps<T>
|
||||
) {
|
||||
const lang = useLang();
|
||||
// aliases
|
||||
const getID = (opt: T): string => {
|
||||
if (props.getID) {
|
||||
@@ -212,7 +214,7 @@ export function InputAutoComplete<T extends Option>(
|
||||
}}
|
||||
variant="filled"
|
||||
required={props.required}
|
||||
label={props.label ?? "Entity ID"}
|
||||
label={props.label ?? lang.get("ENTITY_ID")}
|
||||
helperText={helperText}
|
||||
disabled={props.disabled}
|
||||
error={error}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { FC } from "react";
|
||||
import { useHADeviceRegistry } from "haService";
|
||||
import { useLang } from "lang";
|
||||
import {
|
||||
InputAutoComplete,
|
||||
InputAutoCompletePropsBase,
|
||||
@@ -9,11 +10,12 @@ export type InputDeviceProps = InputAutoCompletePropsBase;
|
||||
|
||||
export const InputDevice: FC<InputDeviceProps> = (props) => {
|
||||
// state
|
||||
const lang = useLang();
|
||||
const dr = useHADeviceRegistry();
|
||||
return (
|
||||
<InputAutoComplete
|
||||
{...props}
|
||||
label={props.label ?? "Device"}
|
||||
label={props.label ?? lang.get("DEVICE")}
|
||||
getID={dr.getID}
|
||||
getLabel={dr.getLabel}
|
||||
options={dr.getOptions()}
|
||||
|
||||
@@ -1,19 +1,27 @@
|
||||
import { FC } from "react";
|
||||
import { useHAServices } from 'haService';
|
||||
import { InputAutoComplete, InputAutoCompletePropsBase } from './InputAutoComplete';
|
||||
import { prettyName } from 'utils/formatting';
|
||||
import { useHAServices } from "haService";
|
||||
import {
|
||||
InputAutoComplete,
|
||||
InputAutoCompletePropsBase,
|
||||
} from "./InputAutoComplete";
|
||||
import { prettyName } from "utils/formatting";
|
||||
import { useLang } from "lang";
|
||||
|
||||
export type InputServiceProps = InputAutoCompletePropsBase & { multiple?: false };
|
||||
export type InputServiceProps = InputAutoCompletePropsBase & {
|
||||
multiple?: false;
|
||||
};
|
||||
|
||||
export const InputService: FC<InputServiceProps> = props => {
|
||||
const services = useHAServices();
|
||||
return <InputAutoComplete
|
||||
{...props}
|
||||
label={props.label ?? "Service"}
|
||||
options={services.getOptions()}
|
||||
getID={services.getID}
|
||||
getLabel={services.getLabel}
|
||||
groupBy={opt => (typeof opt !== 'string') ? prettyName(opt.domain) : ''}
|
||||
export const InputService: FC<InputServiceProps> = (props) => {
|
||||
const services = useHAServices();
|
||||
const lang = useLang();
|
||||
return (
|
||||
<InputAutoComplete
|
||||
{...props}
|
||||
label={props.label ?? lang.get("SERVICE")}
|
||||
options={services.getOptions()}
|
||||
getID={services.getID}
|
||||
getLabel={services.getLabel}
|
||||
groupBy={(opt) => (typeof opt !== "string" ? prettyName(opt.domain) : "")}
|
||||
/>
|
||||
}
|
||||
|
||||
);
|
||||
};
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
} from "utils/time";
|
||||
import { InputEntity } from "./InputEntities";
|
||||
import { InputTime } from "components/Inputs/Base/InputTime";
|
||||
import { useLang } from "lang";
|
||||
|
||||
export type InputTimeEntityProps = {
|
||||
value: string;
|
||||
@@ -23,6 +24,7 @@ export const InputTimeEntity: FC<InputTimeEntityProps> = ({
|
||||
onChange,
|
||||
className = "",
|
||||
}) => {
|
||||
const lang = useLang();
|
||||
const is24Hour = isAutomationTimeString24Hours(value);
|
||||
let editor: ReactNode;
|
||||
if (is24Hour) {
|
||||
@@ -39,7 +41,7 @@ export const InputTimeEntity: FC<InputTimeEntityProps> = ({
|
||||
} else {
|
||||
editor = (
|
||||
<InputEntity
|
||||
label="Time Entity"
|
||||
label={lang.get("TIME_ENTITY")}
|
||||
restrictMode="or"
|
||||
restrictedDeviceClass={["timestamp"]}
|
||||
restrictToDomain={["input_datetime"]}
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
} from "utils/time";
|
||||
import { prettyName } from "utils/formatting";
|
||||
import { ButtonIcon } from "components/Icons/ButtonIcons";
|
||||
import { useLang } from "lang";
|
||||
|
||||
// constants
|
||||
const fields: Array<keyof AutomationTimeObject> = [
|
||||
@@ -29,6 +30,7 @@ export type InputTimeProps = {
|
||||
};
|
||||
export const InputTime: FC<InputTimeProps> = (props) => {
|
||||
// state
|
||||
const lang = useLang();
|
||||
const [disabled, setDisabled] = useState(!props.value);
|
||||
const [displayValue, setDisplayValue] = useState(
|
||||
convertAutomationTimeToTimeObject(props.value)
|
||||
@@ -127,21 +129,26 @@ export const InputTime: FC<InputTimeProps> = (props) => {
|
||||
<div className={["input-time", props.className ?? ""].join(" ")}>
|
||||
{/* <InputLabel >{props.label}</InputLabel> */}
|
||||
<div className="input-time--inner">
|
||||
{fields.map((name) => (
|
||||
<TextField
|
||||
key={name}
|
||||
variant="filled"
|
||||
label={prettyName(name)}
|
||||
defaultValue="00"
|
||||
InputProps={{
|
||||
disabled,
|
||||
type: "number",
|
||||
title: prettyName(name),
|
||||
}}
|
||||
value={displayValue[name] ?? 0}
|
||||
onChange={(e) => updateOne(name)(e.target.value)}
|
||||
/>
|
||||
))}
|
||||
{fields.map((name) => {
|
||||
const label = prettyName(
|
||||
lang.get(`TIME_UNITS_${name}`.toUpperCase())
|
||||
);
|
||||
return (
|
||||
<TextField
|
||||
key={name}
|
||||
variant="filled"
|
||||
label={label}
|
||||
defaultValue="00"
|
||||
InputProps={{
|
||||
disabled,
|
||||
type: "number",
|
||||
title: label,
|
||||
}}
|
||||
value={displayValue[name] ?? 0}
|
||||
onChange={(e) => updateOne(name)(e.target.value)}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
{!props.restrictEmpty && (
|
||||
<ButtonIcon
|
||||
onClick={() => setDisabled(!disabled)}
|
||||
|
||||
@@ -10,18 +10,18 @@ export const ActionEventState: OptionManager<FireEventAction> = {
|
||||
event_data: {},
|
||||
}),
|
||||
isReady: ({ alias, event }) => alias !== "" && event !== "",
|
||||
renderOptionList: (state, setState) => {
|
||||
Component: ({ state, setState, langStore }) => {
|
||||
const update = updateActionData(state, setState);
|
||||
return (
|
||||
<>
|
||||
<InputText
|
||||
textBoxFor="event"
|
||||
label="Event"
|
||||
label={langStore.get("EVENT")}
|
||||
value={state.event}
|
||||
onChange={(event) => update({ event })}
|
||||
/>
|
||||
<InputYaml
|
||||
label="Event Data"
|
||||
label={langStore.get("EVENT_DATA")}
|
||||
value={state.event_data}
|
||||
onChange={(event_data) => update({ event_data })}
|
||||
/>
|
||||
|
||||
@@ -15,12 +15,12 @@ export const ActionRepeatState: OptionManager<RepeatAction> = {
|
||||
},
|
||||
}),
|
||||
isReady: () => true,
|
||||
Component: ({ state, setState }) => {
|
||||
Component: ({ state, setState, langStore }) => {
|
||||
const repeatType = determineType(state.repeat);
|
||||
return (
|
||||
<>
|
||||
<InputAutoComplete
|
||||
label="Type"
|
||||
label={langStore.get("TYPE")}
|
||||
value={repeatType}
|
||||
options={["while", "until", "count"]}
|
||||
onChange={(v) => {
|
||||
@@ -53,7 +53,7 @@ export const ActionRepeatState: OptionManager<RepeatAction> = {
|
||||
/>
|
||||
{"count" in state.repeat && (
|
||||
<InputNumber
|
||||
label="How many times?"
|
||||
label={langStore.get("HOW_MANY_TIMES")}
|
||||
value={state.repeat.count}
|
||||
onChange={(count = 1) =>
|
||||
setState({
|
||||
|
||||
@@ -7,11 +7,11 @@ export const ActionSceneState: OptionManager<SceneAction> = {
|
||||
scene: "",
|
||||
}),
|
||||
isReady: () => true,
|
||||
Component: ({ state, setState }) => {
|
||||
Component: ({ state, setState, langStore }) => {
|
||||
return (
|
||||
<>
|
||||
<InputEntity
|
||||
label="Scene"
|
||||
label={langStore.get("SCENE")}
|
||||
restrictToDomain={["scene"]}
|
||||
value={state.scene ?? ""}
|
||||
onChange={(d) => setState({ ...state, scene: d ?? "" })}
|
||||
|
||||
@@ -8,11 +8,11 @@ export const ActionStopState: OptionManager<StopAction> = {
|
||||
stop: "",
|
||||
}),
|
||||
isReady: () => true,
|
||||
Component: ({ state, setState }) => {
|
||||
Component: ({ state, setState, langStore }) => {
|
||||
return (
|
||||
<>
|
||||
<InputText
|
||||
label="Stop Reason"
|
||||
label={langStore.get("STOP_REASON")}
|
||||
value={state.stop ?? []}
|
||||
onChange={(d) => setState({ ...state, stop: d })}
|
||||
/>
|
||||
|
||||
@@ -24,7 +24,7 @@ export const ActionWaitState: OptionManager<ThisAction> = {
|
||||
delay: "",
|
||||
}),
|
||||
isReady: () => true,
|
||||
Component: ({ state, setState }) => {
|
||||
Component: ({ state, setState, langStore }) => {
|
||||
// state
|
||||
const update = updateActionData(state, setState);
|
||||
const [current, _setCurrent] = useState(getCurrentOption(state));
|
||||
@@ -63,7 +63,7 @@ export const ActionWaitState: OptionManager<ThisAction> = {
|
||||
<>
|
||||
<InputTime
|
||||
className="for"
|
||||
label="for"
|
||||
label={langStore.get("FOR")}
|
||||
value={(state as any).delay}
|
||||
onChange={(delay) => update({ delay })}
|
||||
/>
|
||||
@@ -87,7 +87,7 @@ export const ActionWaitState: OptionManager<ThisAction> = {
|
||||
<>
|
||||
<InputYaml
|
||||
className="triggers"
|
||||
label="Triggers"
|
||||
label={langStore.get("TRIGGERS")}
|
||||
value={state.wait_for_trigger ?? []}
|
||||
onChange={(wait_for_trigger) => update({ wait_for_trigger })}
|
||||
/>
|
||||
@@ -100,7 +100,7 @@ export const ActionWaitState: OptionManager<ThisAction> = {
|
||||
<div className="node-editor--action-wait">
|
||||
<InputList
|
||||
className="wait-type"
|
||||
label="Wait Type"
|
||||
label={langStore.get("WAIT_TYPE")}
|
||||
prettyOptionLabels
|
||||
options={["template", "trigger", "delay"]}
|
||||
current={current}
|
||||
@@ -110,7 +110,7 @@ export const ActionWaitState: OptionManager<ThisAction> = {
|
||||
{current !== "delay" ? (
|
||||
<div className="wait-options">
|
||||
<InputNumber
|
||||
label="Timeout"
|
||||
label={langStore.get("TIMEOUT")}
|
||||
value={
|
||||
(state as any).timeout
|
||||
? Number((state as any).timeout)
|
||||
@@ -123,7 +123,7 @@ export const ActionWaitState: OptionManager<ThisAction> = {
|
||||
}
|
||||
/>
|
||||
<InputBoolean
|
||||
label="Continue on Timeout"
|
||||
label={langStore.get("CONTINUTE_ON_TIMEOUT")}
|
||||
value={(state as any).continue_on_timeout ?? false}
|
||||
onChange={(continue_on_timeout) =>
|
||||
update({ continue_on_timeout })
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { HAService } from "haService";
|
||||
import { HAEntitiesState } from "haService/HAEntities";
|
||||
import { LangStore } from "lang";
|
||||
import { FC } from "react";
|
||||
import { AutomationAction } from "types/automations/actions";
|
||||
import { AutomationCondition } from "types/automations/conditions";
|
||||
@@ -21,6 +22,7 @@ export type OptionManager<T> = {
|
||||
setState: (s: T) => void;
|
||||
ha: HAService;
|
||||
createMode: boolean;
|
||||
langStore: LangStore;
|
||||
}>;
|
||||
}
|
||||
);
|
||||
|
||||
@@ -15,6 +15,7 @@ import { Button } from "components/Inputs/Buttons/Button";
|
||||
import { useState } from "react";
|
||||
import AddIcon from "@mui/icons-material/Add";
|
||||
import { InputTimeEntity } from "components/Inputs/AutoComplete/InputTimeEntity";
|
||||
import { useLang } from "lang";
|
||||
|
||||
export const TriggerTime: OptionManager<AutomationTriggerTime> = {
|
||||
defaultState: () => ({
|
||||
@@ -115,10 +116,11 @@ export const TriggerTimePattern: FC<{
|
||||
state: AutomationTriggerTimePattern;
|
||||
setState: (t: AutomationTriggerTimePattern) => void;
|
||||
}> = ({ state, setState }) => {
|
||||
const lang = useLang();
|
||||
return (
|
||||
<div className="trigger-time--pattern">
|
||||
<InputText
|
||||
label="Hours"
|
||||
label={lang.get("TIME_UNITS_HOURS")}
|
||||
value={state.hours ?? ""}
|
||||
onChange={(hours) =>
|
||||
setState({
|
||||
@@ -128,7 +130,7 @@ export const TriggerTimePattern: FC<{
|
||||
}
|
||||
/>
|
||||
<InputText
|
||||
label="Minutes"
|
||||
label={lang.get("TIME_UNITS_MINUTES")}
|
||||
value={state.minutes ?? ""}
|
||||
onChange={(minutes) =>
|
||||
setState({
|
||||
@@ -138,7 +140,7 @@ export const TriggerTimePattern: FC<{
|
||||
}
|
||||
/>
|
||||
<InputText
|
||||
label="Seconds"
|
||||
label={lang.get("TIME_UNITS_SECONDS")}
|
||||
value={state.seconds ?? ""}
|
||||
onChange={(seconds) =>
|
||||
setState({
|
||||
|
||||
@@ -158,6 +158,7 @@ export const useEditorNodeState = (
|
||||
setState={setState}
|
||||
ha={ha}
|
||||
createMode={createMode}
|
||||
langStore={langStore}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
|
||||
@@ -134,7 +134,7 @@ export const NodeEditor: FC<NodeEditorProps> = ({
|
||||
areYouSureNotReady("close", true).then((ok) => ok && onClose())
|
||||
}
|
||||
>
|
||||
Close
|
||||
{langStore.get("CLOSE")}
|
||||
</Button>
|
||||
<Button
|
||||
className="node-editor--footer--save"
|
||||
|
||||
Reference in new issue
Block a user