added some initial work on intl
This commit is contained in:
1 parent
157efa04b1
commit
caad458b48
22 files changed
+588
-155
No files matched your search
@@ -10,6 +10,7 @@ import { AddIcon, TrashIcon } from "components/Icons";
|
||||
import InputAutoText from "components/Inputs/InputAutoText";
|
||||
import { TagDB } from "components/AutomationManager/TagDB";
|
||||
import { ButtonIcon } from "components/Icons/ButtonIcons";
|
||||
import { useLang } from "lang";
|
||||
|
||||
export interface AutoInfoBoxProps {
|
||||
metadata: AutomationMetadata & Partial<AutomationShortumationMetadata>;
|
||||
@@ -26,6 +27,7 @@ export const AutoInfoBox: FC<AutoInfoBoxProps> = ({
|
||||
tagDB,
|
||||
}) => {
|
||||
// state
|
||||
const langStore = useLang();
|
||||
const [newTag, setNewTag] = useState<[string, string]>(["", ""]);
|
||||
const [[errorIndex, error], _setError] = useState<[number | "new", string]>([
|
||||
-1,
|
||||
@@ -54,12 +56,12 @@ export const AutoInfoBox: FC<AutoInfoBoxProps> = ({
|
||||
);
|
||||
const validTagName = (newName: string): string | undefined => {
|
||||
if (newName.length <= 0) {
|
||||
return "Name must be at least 1 character long";
|
||||
return langStore.get("VALIDATION_AUTOMATION_NAME");
|
||||
}
|
||||
// eslint-disable-next-line
|
||||
for (const [name, _] of tags) {
|
||||
if (name.trim() === newName.trim()) {
|
||||
return `The tag '${name}' already exists`;
|
||||
return langStore.get("VALIDATION_TAG_EXISTS", { name });
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -101,23 +103,23 @@ export const AutoInfoBox: FC<AutoInfoBoxProps> = ({
|
||||
<div className="automation-editor--info-box">
|
||||
<div className="automation-editor--info-box-inner">
|
||||
<InputText
|
||||
label="ID"
|
||||
label={langStore.get("ID")}
|
||||
value={metadata.id}
|
||||
onChange={onUpdateMetadata("id")}
|
||||
/>
|
||||
<InputText
|
||||
label="Name"
|
||||
label={langStore.get("NAME")}
|
||||
value={metadata.alias ?? ""}
|
||||
onChange={onUpdateMetadata("alias")}
|
||||
/>
|
||||
<InputText
|
||||
multiline
|
||||
label="Description"
|
||||
label={langStore.get("DESCRIPTION")}
|
||||
value={metadata.description ?? ""}
|
||||
onChange={onUpdateMetadata("description")}
|
||||
/>
|
||||
<InputList
|
||||
label="Mode"
|
||||
label={langStore.get("MODE")}
|
||||
current={metadata.mode}
|
||||
onChange={onUpdateMetadata("mode")}
|
||||
options={["parallel", "single", "queued", "restart"]}
|
||||
@@ -129,14 +131,14 @@ export const AutoInfoBox: FC<AutoInfoBoxProps> = ({
|
||||
<div key={tagIndex} className="automation-editor--info-box--tag">
|
||||
<InputAutoText
|
||||
value={tagName}
|
||||
label="Name"
|
||||
label={langStore.get("NAME")}
|
||||
onChange={(v) => updateTagName(v, tagIndex)}
|
||||
options={foundNewTagNames}
|
||||
error={errorIndex === tagIndex ? error : undefined}
|
||||
/>
|
||||
<InputAutoText
|
||||
value={tagValue}
|
||||
label="Tag"
|
||||
label={langStore.get("TAG")}
|
||||
onChange={(v) => onUpdateTags(v, tagIndex)}
|
||||
options={tagDB.getTagValues(tagName)}
|
||||
error={errorIndex === tagIndex ? error : undefined}
|
||||
@@ -153,14 +155,14 @@ export const AutoInfoBox: FC<AutoInfoBoxProps> = ({
|
||||
<div className="automation-editor--info-box--tag">
|
||||
<InputAutoText
|
||||
value={newTag[0]}
|
||||
label="Name"
|
||||
label={langStore.get("NAME")}
|
||||
onChange={(v) => setNewTag([v, newTag[1]])}
|
||||
options={foundNewTagNames}
|
||||
error={errorIndex === "new" ? error : undefined}
|
||||
/>
|
||||
<InputAutoText
|
||||
value={newTag[1]}
|
||||
label="Tag"
|
||||
label={langStore.get("TAG")}
|
||||
onChange={(v) => setNewTag([newTag[0], v])}
|
||||
options={tagDB.getTagValues(newTag[0])}
|
||||
error={errorIndex === "new" ? error : undefined}
|
||||
|
||||
@@ -31,6 +31,7 @@ import { MiniFailure } from "types/validators/helper";
|
||||
|
||||
import { AutoInfoBox } from "./AutoInfoBox";
|
||||
import { useAutomatioEditorState, EditorData } from "./state";
|
||||
import { useLang } from "lang";
|
||||
|
||||
interface Props {
|
||||
automation?: AutomationData | BareAutomationData;
|
||||
@@ -51,6 +52,7 @@ export const AutomationEditor: FC<Props> = ({
|
||||
isNew,
|
||||
}) => {
|
||||
// state
|
||||
const langStore = useLang();
|
||||
const {
|
||||
state,
|
||||
updateSequence,
|
||||
@@ -131,7 +133,7 @@ export const AutomationEditor: FC<Props> = ({
|
||||
<div className="id">{state.data.id}</div>
|
||||
<InputTextView
|
||||
value={state.data.alias ?? ""}
|
||||
placeholder="Name"
|
||||
placeholder={langStore.get("NAME")}
|
||||
onChange={(alias) =>
|
||||
updateMetadata(
|
||||
{
|
||||
@@ -145,7 +147,7 @@ export const AutomationEditor: FC<Props> = ({
|
||||
</span>
|
||||
<InputList
|
||||
fullWidth={false}
|
||||
label="Mode"
|
||||
label={langStore.get("MODE")}
|
||||
className="automation-editor--flow-wrapper--toolbar--modes"
|
||||
current={{
|
||||
id: state.data.mode,
|
||||
@@ -165,28 +167,26 @@ export const AutomationEditor: FC<Props> = ({
|
||||
options={[
|
||||
{
|
||||
id: "single",
|
||||
label: "Do not start a new run. Issue a warning.",
|
||||
label: langStore.get("MODE_SIGNLE_LABEL"),
|
||||
},
|
||||
{
|
||||
id: "parallel",
|
||||
label:
|
||||
"Start a new, independent run in parallel with previous runs.",
|
||||
label: langStore.get("MODE_SIGNLE_PARALLEL"),
|
||||
},
|
||||
{
|
||||
id: "queued",
|
||||
label:
|
||||
"Start a new run after all previous runs complete. Runs are guaranteed to execute in the order they were queued.",
|
||||
label: langStore.get("MODE_SIGNLE_QUEUED"),
|
||||
},
|
||||
{
|
||||
id: "restart",
|
||||
label: "Start a new run after first stopping previous run.",
|
||||
label: langStore.get("MODE_SIGNLE_RESTART"),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
<InputTextView
|
||||
className="description"
|
||||
value={state.data.description ?? ""}
|
||||
placeholder="Description"
|
||||
placeholder={langStore.get("DESCRIPTION")}
|
||||
onChange={(description) =>
|
||||
updateMetadata(
|
||||
{
|
||||
@@ -204,7 +204,7 @@ export const AutomationEditor: FC<Props> = ({
|
||||
onClick={() => setFlipped(!flipped)}
|
||||
>
|
||||
<Icon>{flipped ? "flip_to_front" : "flip_to_back"}</Icon>
|
||||
Flip
|
||||
{langStore.get("FLIPP")}
|
||||
</Button>
|
||||
)}
|
||||
{state.status === "changed" && (
|
||||
@@ -217,7 +217,7 @@ export const AutomationEditor: FC<Props> = ({
|
||||
onClick={save}
|
||||
disabled={state.status !== "changed"}
|
||||
>
|
||||
Save <CheckMarkIcon color="#bf4" />
|
||||
{langStore.get("SAVE")} <CheckMarkIcon color="#bf4" />
|
||||
</Button>
|
||||
</div>
|
||||
<DAGAutomationGraph
|
||||
@@ -242,26 +242,26 @@ export const AutomationEditor: FC<Props> = ({
|
||||
// tooltipOpen
|
||||
sx={{ pointerEvents: "auto" }}
|
||||
icon={<RunIcon />}
|
||||
tooltipTitle={"Trigger"}
|
||||
tooltipTitle={langStore.get("TRIGGER")}
|
||||
onClick={onTrigger}
|
||||
/>
|
||||
<SpeedDialAction
|
||||
// tooltipOpen
|
||||
icon={<DeleteIcon />}
|
||||
tooltipTitle={"Delete"}
|
||||
tooltipTitle={langStore.get("DELETE")}
|
||||
onClick={onDelete}
|
||||
/>
|
||||
<SpeedDialAction
|
||||
// tooltipOpen
|
||||
icon={<EditIcon />}
|
||||
tooltipTitle={"Metadata"}
|
||||
tooltipTitle={langStore.get("METADATA")}
|
||||
onClick={() => setInfoBox(!infoBoxOpen)}
|
||||
/>
|
||||
{state.status === "changed" && (
|
||||
<SpeedDialAction
|
||||
// tooltipOpen
|
||||
icon={<UndoIcon />}
|
||||
tooltipTitle={"Undo"}
|
||||
tooltipTitle={langStore.get("UNDO")}
|
||||
onClick={undo}
|
||||
/>
|
||||
)}
|
||||
@@ -277,6 +277,7 @@ export const ValidationBox: FC<{
|
||||
data: EditorData;
|
||||
onSave: (d: EditorData) => void;
|
||||
}> = (props) => {
|
||||
const langStore = useLang();
|
||||
const [{ failures, data }, setState] = useState({
|
||||
failures: props.failures,
|
||||
data: props.data,
|
||||
@@ -317,12 +318,10 @@ export const ValidationBox: FC<{
|
||||
</>
|
||||
))}
|
||||
</ul>
|
||||
<span>
|
||||
Please correct the automation file manually and then continue!
|
||||
</span>
|
||||
<InputYaml label="Raw" value={data} onChange={onSave} />
|
||||
<span>{langStore.get("VALIDATION_PLEASE_CORRECT_FILE")}</span>
|
||||
<InputYaml label={langStore.get("RAW")} value={data} onChange={onSave} />
|
||||
<Button disabled={failures.length > 0} onClick={() => props.onSave(data)}>
|
||||
Save
|
||||
{langStore.get("SAVE")}
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { HassEntities } from "home-assistant-js-websocket";
|
||||
import { LangStore, useLang } from "lang";
|
||||
import { useEffect, useState } from "react";
|
||||
import { AutomationData, BareAutomationData } from "types/automations";
|
||||
import { defaultAutomation } from "utils/defaults";
|
||||
@@ -10,7 +11,8 @@ export const useAutomationDB = (
|
||||
configAutomations: AutomationData[],
|
||||
tagsDB: TagDB
|
||||
) => {
|
||||
const autoMap = genMapping(haEntities, configAutomations, tagsDB);
|
||||
const langStore = useLang();
|
||||
const autoMap = genMapping(haEntities, configAutomations, tagsDB, langStore);
|
||||
const [newAuto, setNewAuto] =
|
||||
useState<
|
||||
null | [AutomationManagerAuto, AutomationData | BareAutomationData]
|
||||
@@ -54,13 +56,13 @@ export const useAutomationDB = (
|
||||
entityId: "",
|
||||
title: auto.alias ?? "",
|
||||
description: auto.description ?? "",
|
||||
state: "unregistered",
|
||||
state: langStore.get("AUTOMATION_STATE_UNREGISTERED"),
|
||||
tags: {},
|
||||
issue: "New Automation",
|
||||
issue: langStore.get("NEW_AUTOMATION"),
|
||||
isNew: true,
|
||||
source_file: "n/a",
|
||||
source_file_type: "n/a",
|
||||
configuration_key: ["n/a"],
|
||||
source_file: langStore.get("N/A"),
|
||||
source_file_type: langStore.get("N/A"),
|
||||
configuration_key: [],
|
||||
},
|
||||
auto,
|
||||
]);
|
||||
@@ -72,7 +74,8 @@ export const useAutomationDB = (
|
||||
const genMapping = (
|
||||
haEntities: HassEntities,
|
||||
configAutomations: AutomationData[],
|
||||
tagsDB: TagDB
|
||||
tagsDB: TagDB,
|
||||
langStore: LangStore
|
||||
) => {
|
||||
const configData: Record<string, AutomationData> = configAutomations.reduce(
|
||||
(all, n) => ({
|
||||
@@ -93,7 +96,9 @@ const genMapping = (
|
||||
let description = "";
|
||||
let issue: string | undefined = ["on", "off"].includes(entityData.state)
|
||||
? undefined
|
||||
: `recived invalid state "${entityData.state}, this could be because you have a lingering automation that was not cleared by homeassistant, try to reboot HA or manually clear this automation from HA Database."`;
|
||||
: langStore.get("ISSUES_INVALID_STATE", {
|
||||
state: entityData.state,
|
||||
});
|
||||
let found: AutomationData | null = null;
|
||||
let source_file = "n/a";
|
||||
let source_file_type = "n/a";
|
||||
@@ -107,7 +112,7 @@ const genMapping = (
|
||||
configuration_key = found.configuration_key ?? configuration_key;
|
||||
delete configData[autoId];
|
||||
} else {
|
||||
issue = "failed to find this automation in '/config' folder";
|
||||
issue = langStore.get("ISSUES_FIND_AUTOMATION_IN_CONFIG");
|
||||
}
|
||||
|
||||
automatioinMap[autoId] = [
|
||||
@@ -134,13 +139,12 @@ const genMapping = (
|
||||
entityId: "",
|
||||
title: auto.alias ?? "",
|
||||
description: auto.description ?? "",
|
||||
state: "unregistered",
|
||||
state: langStore.get("AUTOMATION_STATE_UNREGISTERED"),
|
||||
tags: tagsDB.getTags(auto.id),
|
||||
source_file: auto.source_file,
|
||||
source_file_type: auto.source_file_type,
|
||||
configuration_key: auto.configuration_key,
|
||||
issue:
|
||||
"homeassistant did not load this automation, try to manually reload automations or restart homeassistant.",
|
||||
issue: langStore.get("ISSUES_NO_LOAD_AUTOMATION"),
|
||||
},
|
||||
auto,
|
||||
];
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
} from "./state";
|
||||
import Alert from "@mui/material/Alert";
|
||||
import { useConfirm } from "material-ui-confirm";
|
||||
import { useLang } from "lang";
|
||||
|
||||
export type AutomationManagerLoadedProps = UseAutomationManagerStateArgs & {
|
||||
onAutomationDelete: (aid: string, eid: string) => void;
|
||||
@@ -17,13 +18,14 @@ export type AutomationManagerLoadedProps = UseAutomationManagerStateArgs & {
|
||||
export const AutomationManagerLoaded: FC<
|
||||
PropsWithChildren<AutomationManagerLoadedProps>
|
||||
> = ({ children, ...args }) => {
|
||||
const langStore = useLang();
|
||||
const state = useAutomationManagerState(args);
|
||||
const confirm = useConfirm();
|
||||
|
||||
const onAutomationDelete = async (aid: string, eid: string) =>
|
||||
confirm({
|
||||
title: "Are you sure you want to delete this automation?",
|
||||
confirmationText: "Delete",
|
||||
title: langStore.get("CONFIRMATION_DELETE_THIS_AUTOMATION"),
|
||||
confirmationText: langStore.get("DELETE"),
|
||||
})
|
||||
.then(() => {
|
||||
args.onAutomationDelete(aid, eid);
|
||||
@@ -76,8 +78,9 @@ export const AutomationManagerLoaded: FC<
|
||||
) : (
|
||||
<div>
|
||||
<Alert color="warning">
|
||||
Failed to find an automation on disk with id{" "}
|
||||
{state.currentAutomationId}.
|
||||
{langStore.get("ISSUE_FAILED_TO_FIND_AUTOMATION_ON_DISK", {
|
||||
id: state.currentAutomationId,
|
||||
})}
|
||||
</Alert>
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -7,6 +7,7 @@ import { useAutomationDB } from "./automationDB";
|
||||
import { useConfirm } from "material-ui-confirm";
|
||||
import { AutomationManagerAutoUpdatable } from "../types";
|
||||
import { useSnackbar } from "notistack";
|
||||
import { useLang } from "lang";
|
||||
|
||||
export type UseAutomationManagerStateArgs = {
|
||||
configAutomations: AutomationData[];
|
||||
@@ -26,6 +27,7 @@ export const useAutomationManagerState = ({
|
||||
onAutomationStateChange,
|
||||
}: UseAutomationManagerStateArgs) => {
|
||||
// state
|
||||
const langStore = useLang();
|
||||
const confirm = useConfirm();
|
||||
const snackbr = useSnackbar();
|
||||
const cookies = useAMSCookies();
|
||||
@@ -44,10 +46,9 @@ export const useAutomationManagerState = ({
|
||||
const stillHaveNewAreYouSure = async () => {
|
||||
try {
|
||||
await confirm({
|
||||
content:
|
||||
"Selecting another automation will cause you to lose all work done on this new automation. Please save your work on this automation first.",
|
||||
confirmationText: "Switch Automation",
|
||||
cancellationText: "Cancel",
|
||||
content: langStore.get("WARNING_SWITCHING_FROM_NONE_SAVE"),
|
||||
confirmationText: langStore.get("SWITCH_AUTOMATION"),
|
||||
cancellationText: langStore.get("CANCEL"),
|
||||
});
|
||||
return true;
|
||||
} catch (_) {
|
||||
@@ -128,9 +129,10 @@ export const useAutomationManagerState = ({
|
||||
}
|
||||
} else {
|
||||
snackbr.enqueueSnackbar(
|
||||
`Failed to save automation "${aid}" contents - ${JSON.stringify(
|
||||
a
|
||||
)} -- not found in /config`,
|
||||
langStore.get("ERROR_FAILED_TO_SAVE", {
|
||||
aid,
|
||||
contents: JSON.stringify(a),
|
||||
}),
|
||||
{ variant: "error" }
|
||||
);
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import { Button } from "components/Inputs/Buttons/Button";
|
||||
import InputAutoText from "components/Inputs/InputAutoText";
|
||||
|
||||
import { TagDB } from "../TagDB";
|
||||
import { useLang } from "lang";
|
||||
|
||||
export type TagsProps = {
|
||||
automationId: string;
|
||||
@@ -29,6 +30,7 @@ export type TagModalState =
|
||||
};
|
||||
|
||||
export const Tags: FC<TagsProps> = ({ automationId, tagsDB }) => {
|
||||
const langStore = useLang();
|
||||
const [modalState, setModal] = useState<TagModalState>({ open: false });
|
||||
const tags = tagsDB.getTags(automationId, true);
|
||||
const onUpdate = (t: Record<string, string>) =>
|
||||
@@ -44,7 +46,7 @@ export const Tags: FC<TagsProps> = ({ automationId, tagsDB }) => {
|
||||
<InputAutoText
|
||||
className="name"
|
||||
options={tagsDB.getTagNames(Object.keys(tags))}
|
||||
label="Tag Name"
|
||||
label={langStore.get("TAG_NAME")}
|
||||
value={modalState.tag[0]}
|
||||
onChange={(v) =>
|
||||
setModal({
|
||||
@@ -56,7 +58,7 @@ export const Tags: FC<TagsProps> = ({ automationId, tagsDB }) => {
|
||||
<InputAutoText
|
||||
className="value"
|
||||
options={tagsDB.getTagValues(modalState.tag[0])}
|
||||
label="Tag Value"
|
||||
label={langStore.get("TAG_VALUE")}
|
||||
value={modalState.tag[1]}
|
||||
onChange={(v) =>
|
||||
setModal({
|
||||
@@ -67,7 +69,7 @@ export const Tags: FC<TagsProps> = ({ automationId, tagsDB }) => {
|
||||
/>
|
||||
<div className="buttons">
|
||||
<Button onClick={() => setModal({ open: false })} color="info">
|
||||
Close
|
||||
{langStore.get("CLOSE")}
|
||||
</Button>
|
||||
<Button
|
||||
disabled={!validTag}
|
||||
@@ -80,7 +82,7 @@ export const Tags: FC<TagsProps> = ({ automationId, tagsDB }) => {
|
||||
}}
|
||||
color="success"
|
||||
>
|
||||
{modalState.isNew ? "Create" : "Save"}
|
||||
{modalState.isNew ? langStore.get("CREATE") : langStore.get("SAVE")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -15,6 +15,7 @@ import { AutomationManagerAuto } from "../types";
|
||||
import { Tags } from "./Tags";
|
||||
import { TagDB } from "../TagDB";
|
||||
import { Chip, Tooltip } from "@mui/material";
|
||||
import { useLang } from "lang";
|
||||
|
||||
export type MetadataBoxProps = AutomationManagerAuto & {
|
||||
onDelete: () => void;
|
||||
@@ -28,6 +29,10 @@ export type MetadataBoxProps = AutomationManagerAuto & {
|
||||
};
|
||||
export const MetadataBox: FC<MetadataBoxProps> = (props) => {
|
||||
const isValidState = ["on", "off"].includes(props.state);
|
||||
const langStore = useLang();
|
||||
const prettyState = ["on", "off"].includes(props.state)
|
||||
? langStore.get(`AUTOMATION_STATE_${props.state}`)
|
||||
: props.state;
|
||||
return (
|
||||
<div
|
||||
className={[
|
||||
@@ -38,7 +43,13 @@ export const MetadataBox: FC<MetadataBoxProps> = (props) => {
|
||||
>
|
||||
<div
|
||||
className="metadatabox--switch"
|
||||
title={!isValidState ? "Invalid state" : `Automation is ${props.state}`}
|
||||
title={
|
||||
!isValidState
|
||||
? langStore.get("ERROR_INVALID_AUTOMATION_STATE")
|
||||
: langStore.get("AUTOMATION_STATE_IS", {
|
||||
state: prettyState,
|
||||
})
|
||||
}
|
||||
>
|
||||
<Switch
|
||||
checked={props.state !== "off"}
|
||||
@@ -53,11 +64,16 @@ export const MetadataBox: FC<MetadataBoxProps> = (props) => {
|
||||
<div className="metadatabox--title">
|
||||
<span className="metadatabox--title--source">
|
||||
<Tooltip
|
||||
title={`This automation is located in the file ${props.source_file}. It's currently '${props.state}', it's entity id is '${props.entityId}' and it's automation id is '${props.id}'`}
|
||||
title={langStore.get("AUTOMATION_METADATA_TOOLTIP_TEXT", {
|
||||
source_file: props.source_file,
|
||||
state: prettyState,
|
||||
entityId: props.entityId,
|
||||
id: props.id,
|
||||
})}
|
||||
>
|
||||
<Chip
|
||||
label={`@${props.source_file} (${props.source_file_type}) - ${
|
||||
props.entityId ?? "n/a"
|
||||
props.entityId ?? langStore.get("N/A")
|
||||
}`}
|
||||
className="text-ellipsis"
|
||||
/>
|
||||
@@ -66,7 +82,7 @@ export const MetadataBox: FC<MetadataBoxProps> = (props) => {
|
||||
<Tooltip title={`ID=${props.id}, EntityID=${props.entityId}`}>
|
||||
<InputTextView
|
||||
className="title"
|
||||
placeholder="Title"
|
||||
placeholder={langStore.get("TITLE")}
|
||||
value={props.title}
|
||||
onChange={props.onTitleUpdate}
|
||||
disabled={props.isNew}
|
||||
@@ -74,7 +90,7 @@ export const MetadataBox: FC<MetadataBoxProps> = (props) => {
|
||||
</Tooltip>
|
||||
<InputTextView
|
||||
className="description"
|
||||
placeholder="Description"
|
||||
placeholder={langStore.get("DESCRIPTION")}
|
||||
value={props.description}
|
||||
onChange={props.onDescriptionUpdate}
|
||||
disabled={props.isNew}
|
||||
@@ -93,19 +109,19 @@ export const MetadataBox: FC<MetadataBoxProps> = (props) => {
|
||||
className="select"
|
||||
icon={<SelectIcon />}
|
||||
onClick={props.onSelect}
|
||||
title="Select automation"
|
||||
title={langStore.get("SELECT_AUTOMATION")}
|
||||
/>
|
||||
<ButtonIcon
|
||||
className="run"
|
||||
icon={<RunIcon />}
|
||||
onClick={props.onRun}
|
||||
title="Trigger automation"
|
||||
title={langStore.get("TRIGGER_AUTOMATION")}
|
||||
/>
|
||||
<ButtonIcon
|
||||
className="delete"
|
||||
icon={<DeleteForeverIcon />}
|
||||
onClick={props.onDelete}
|
||||
title="Delete automation"
|
||||
title={langStore.get("DELETE_AUTOMATION")}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -18,6 +18,7 @@ import {
|
||||
} from "../types";
|
||||
import { Button } from "components/Inputs/Buttons/Button";
|
||||
import { ButtonIcon } from "components/Icons/ButtonIcons";
|
||||
import { useLang } from "lang";
|
||||
|
||||
export type AutomationManagerSidebarProps = {
|
||||
tagsDB: TagDB;
|
||||
@@ -41,6 +42,7 @@ export const AutomationManagerSidebar: FC<AutomationManagerSidebarProps> = ({
|
||||
onSelectedAutomationId,
|
||||
...events
|
||||
}) => {
|
||||
const langStore = useLang();
|
||||
const [searchText, setSearchText] = useState("");
|
||||
const [selectedTagIdx, setSelectedTagIdx] = useState<number[]>([]);
|
||||
const [isHidden, setHidden] = useState(false);
|
||||
@@ -76,9 +78,13 @@ export const AutomationManagerSidebar: FC<AutomationManagerSidebarProps> = ({
|
||||
].join(" ")}
|
||||
>
|
||||
<div className="automation-manager--sidebar-box--nav">
|
||||
<InputText label="Search" value={searchText} onChange={setSearchText} />
|
||||
<InputText
|
||||
label={langStore.get("SEARCH")}
|
||||
value={searchText}
|
||||
onChange={setSearchText}
|
||||
/>
|
||||
<InputMultiSelect
|
||||
label="Tags"
|
||||
label={langStore.get("TAGS")}
|
||||
selected={selectedTagIdx}
|
||||
onChange={setSelectedTagIdx}
|
||||
options={tags}
|
||||
@@ -109,7 +115,7 @@ export const AutomationManagerSidebar: FC<AutomationManagerSidebarProps> = ({
|
||||
color="primary"
|
||||
className="add-btn"
|
||||
>
|
||||
Add
|
||||
{langStore.get("ADD")}
|
||||
</Button>
|
||||
<ButtonIcon
|
||||
className="hide-btn"
|
||||
|
||||
@@ -15,6 +15,7 @@ import * as av from "types/validators/autmation";
|
||||
import { useConfirm } from "material-ui-confirm";
|
||||
import InputYaml from "components/Inputs/Base/InputYaml";
|
||||
import { APIResponse } from "apiService/types";
|
||||
import { useLang } from "lang";
|
||||
|
||||
export type AutomationManagerProps = {
|
||||
onAutomationStateChange: (eid: string, on: boolean) => Promise<any>;
|
||||
@@ -33,6 +34,7 @@ export const AutomationManager: FC<AutomationManagerProps> = ({
|
||||
forceDeleteAutomation: _forceDeleteAutomation,
|
||||
triggerAutomation: _triggerAutomation,
|
||||
}) => {
|
||||
const langStore = useLang();
|
||||
const snackbr = useSnackbar();
|
||||
const confirm = useConfirm();
|
||||
const validationsShown = useRef(false);
|
||||
@@ -52,9 +54,14 @@ export const AutomationManager: FC<AutomationManagerProps> = ({
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
snackbr.enqueueSnackbar(errorMessage.replace("{{err}}", String(err)), {
|
||||
variant: "error",
|
||||
});
|
||||
snackbr.enqueueSnackbar(
|
||||
langStore.get(errorMessage, {
|
||||
err: String(err),
|
||||
}),
|
||||
{
|
||||
variant: "error",
|
||||
}
|
||||
);
|
||||
setIsSaving(isSaving.filter((k) => k !== name));
|
||||
});
|
||||
}
|
||||
@@ -68,9 +75,14 @@ export const AutomationManager: FC<AutomationManagerProps> = ({
|
||||
if (resp.ok) {
|
||||
refreshAutomations();
|
||||
} else {
|
||||
snackbr.enqueueSnackbar(errorMessage.replace("{{err}}", resp.error), {
|
||||
variant: "error",
|
||||
});
|
||||
snackbr.enqueueSnackbar(
|
||||
langStore.get(errorMessage, {
|
||||
err: resp.error,
|
||||
}),
|
||||
{
|
||||
variant: "error",
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -78,24 +90,26 @@ export const AutomationManager: FC<AutomationManagerProps> = ({
|
||||
|
||||
const onAutomationStateChange = (eid: string, on: boolean) =>
|
||||
wrapPromise(
|
||||
"changing automation state",
|
||||
'failed to toggle autonation due to "{{err}}"',
|
||||
langStore.get("AUTOMATION_MANAGER_STATE_CHANGE"),
|
||||
"AUTOMATION_MANAGER_STATE_CHANGE_FAIL",
|
||||
() => _onAutomationStateChange(eid, on)
|
||||
);
|
||||
const refreshAutomations = () =>
|
||||
wrapPromise(
|
||||
"refreshing automations",
|
||||
'failed refreshing automations due to "{{err}}"',
|
||||
langStore.get("AUTOMATION_MANAGER_REFRESH"),
|
||||
"AUTOMATION_MANAGER_REFRESH_FAIL",
|
||||
() => _refreshAutomations()
|
||||
);
|
||||
const forceDeleteAutomation = (eid: string) =>
|
||||
wrapPromise("deleting automations", 'failed delete due to "{{err}}"', () =>
|
||||
_forceDeleteAutomation(eid)
|
||||
wrapPromise(
|
||||
langStore.get("AUTOMATION_MANAGER_DELETE"),
|
||||
"AUTOMATION_MANAGER_DELETE_FAIL",
|
||||
() => _forceDeleteAutomation(eid)
|
||||
);
|
||||
const triggerAutomation = (eid: string) =>
|
||||
wrapPromise(
|
||||
"triggering automations",
|
||||
'failed trigger due to "{{err}}"',
|
||||
langStore.get("AUTOMATION_MANAGER_TRIGGER"),
|
||||
"AUTOMATION_MANAGER_TRIGGER_FAIL",
|
||||
() => _triggerAutomation(eid)
|
||||
);
|
||||
|
||||
@@ -129,7 +143,7 @@ export const AutomationManager: FC<AutomationManagerProps> = ({
|
||||
cancellationButtonProps: {
|
||||
style: { display: "none" },
|
||||
},
|
||||
title: "Invalid Automations detected!",
|
||||
title: langStore.get("ERROR_INVALID_AUTOMATION_DETECTED"),
|
||||
content: (
|
||||
<>
|
||||
<ol className="invalid-automation-modal-list">
|
||||
@@ -165,6 +179,7 @@ export const AutomationManager: FC<AutomationManagerProps> = ({
|
||||
.catch(console.error);
|
||||
}
|
||||
}
|
||||
// eslint-disable-next-line
|
||||
}, [api.state.automations, confirm]);
|
||||
|
||||
// handle bad states
|
||||
@@ -172,8 +187,7 @@ export const AutomationManager: FC<AutomationManagerProps> = ({
|
||||
return (
|
||||
<div className="automation-manager error">
|
||||
<Alert color="error">
|
||||
Failed to connect to websocket, please check that your access token is
|
||||
properly setup
|
||||
{langStore.get("ERROR_FAILED_CONNECTION_TO_HA")}
|
||||
</Alert>{" "}
|
||||
<br />
|
||||
<code>{JSON.stringify(haEntities.error)}</code>
|
||||
@@ -205,7 +219,7 @@ export const AutomationManager: FC<AutomationManagerProps> = ({
|
||||
return (
|
||||
<div className="automation-manager error">
|
||||
<Alert color="error">
|
||||
Failed to load automations from <code>/config</code>
|
||||
{langStore.get("ISSUES_FIND_AUTOMATION_IN_CONFIG")}
|
||||
</Alert>{" "}
|
||||
<br />
|
||||
<code>{error}</code>
|
||||
@@ -237,8 +251,8 @@ export const AutomationManager: FC<AutomationManagerProps> = ({
|
||||
onAutomationStateChange={onAutomationStateChange}
|
||||
onAutomationAdd={(auto) =>
|
||||
wrapApiPromise(
|
||||
"adding automation",
|
||||
"Failed to create automation, recieved error: {{err}}!",
|
||||
langStore.get("AUTOMATION_MANAGER_ADD"),
|
||||
"AUTOMATION_MANAGER_ADD_FAIL",
|
||||
() => api.createAutomation(auto) as any
|
||||
)
|
||||
}
|
||||
@@ -258,7 +272,7 @@ export const AutomationManager: FC<AutomationManagerProps> = ({
|
||||
}
|
||||
if (!deleteSent) {
|
||||
snackbr.enqueueSnackbar(
|
||||
"Failed to delete automation, this may be resolved by a refresh or reboot of Home Assistant",
|
||||
langStore.get("AUTOMATION_MANAGER_DELETE_LIGHT"),
|
||||
{
|
||||
variant: "error",
|
||||
}
|
||||
@@ -268,15 +282,15 @@ export const AutomationManager: FC<AutomationManagerProps> = ({
|
||||
}}
|
||||
onAutomationUpdate={(auto) =>
|
||||
wrapApiPromise(
|
||||
"updating automation",
|
||||
"Failed to update automation, recieved error: {{err}}!",
|
||||
langStore.get("AUTOMATION_MANAGER_UPDATE"),
|
||||
"AUTOMATION_MANAGER_UPDATE_FAIL",
|
||||
() => api.updateAutomation(auto) as any
|
||||
)
|
||||
}
|
||||
onUpdateTags={async (aid, t) => {
|
||||
wrapApiPromise(
|
||||
"updating tags",
|
||||
"Failed to update tags, recieved error: {{err}}!",
|
||||
langStore.get("AUTOMATION_MANAGER_UPDATE_TAGS"),
|
||||
"AUTOMATION_MANAGER_UPDATE_TAGS_FAIL",
|
||||
() =>
|
||||
api.updateTags({
|
||||
automation_id: aid,
|
||||
|
||||
@@ -12,6 +12,7 @@ import { getViewer } from "./viewRender";
|
||||
import { getEditor } from "./editorRender";
|
||||
import useWindowSize from "utils/useWindowSize";
|
||||
import { ConditionNodeSettings } from "./ConditionNodeSettings";
|
||||
import { useLang } from "lang";
|
||||
|
||||
export type ConditionNodeBaseProps = {
|
||||
condition: AutomationCondition;
|
||||
@@ -24,6 +25,7 @@ export type ConditionNodeBaseViewMode = "edit" | "yaml" | "view";
|
||||
export const ConditionNodeBase: FC<ConditionNodeBaseProps> = (props) => {
|
||||
// state
|
||||
const ha = useHA();
|
||||
const langStore = useLang();
|
||||
const { isMobile } = useWindowSize();
|
||||
const [{ isEdited, condition }, setCondition] = useState<{
|
||||
isEdited: boolean;
|
||||
@@ -61,6 +63,7 @@ export const ConditionNodeBase: FC<ConditionNodeBaseProps> = (props) => {
|
||||
onChange={updateCondition}
|
||||
ha={ha}
|
||||
initialViewMode="edit"
|
||||
langStore={langStore}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -101,6 +104,7 @@ export const ConditionNodeBase: FC<ConditionNodeBaseProps> = (props) => {
|
||||
},
|
||||
} as any)
|
||||
}
|
||||
prettyOptionLabels={false}
|
||||
/>
|
||||
{isMobile && icons}
|
||||
</div>
|
||||
|
||||
@@ -31,6 +31,7 @@ import { prettyName } from "utils/formatting";
|
||||
import { InputList } from "components/Inputs/InputList";
|
||||
import { Button } from "components/Inputs/Buttons/Button";
|
||||
import { RemoveCircle } from "@mui/icons-material";
|
||||
import { LangStore } from "lang";
|
||||
|
||||
interface Editor<C extends AutomationCondition>
|
||||
extends FC<{
|
||||
@@ -38,6 +39,7 @@ interface Editor<C extends AutomationCondition>
|
||||
onChange: (condition: C) => void;
|
||||
ha: HAService;
|
||||
initialViewMode: ConditionNodeBaseViewMode;
|
||||
langStore: LangStore;
|
||||
}> {}
|
||||
|
||||
export const getEditor = (condition: AutomationCondition): Editor<any> => {
|
||||
@@ -70,11 +72,12 @@ export const getEditor = (condition: AutomationCondition): Editor<any> => {
|
||||
export const TemplateEditor: Editor<TemplateCondition> = ({
|
||||
onChange,
|
||||
condition,
|
||||
langStore,
|
||||
}) => {
|
||||
return (
|
||||
<>
|
||||
<InputYaml
|
||||
label="Template"
|
||||
label={langStore.get("TEMPLATE")}
|
||||
value={condition.value_template}
|
||||
onChange={(value_template) =>
|
||||
onChange({
|
||||
@@ -119,6 +122,7 @@ export const DeviceConditionEditor: Editor<DeviceCondition> = ({
|
||||
export const NumericStateEditor: Editor<NumericCondition> = ({
|
||||
onChange,
|
||||
condition,
|
||||
langStore,
|
||||
}) => {
|
||||
return (
|
||||
<>
|
||||
@@ -133,7 +137,7 @@ export const NumericStateEditor: Editor<NumericCondition> = ({
|
||||
}
|
||||
/>
|
||||
<InputText
|
||||
label="Attribute"
|
||||
label={langStore.get("ATTRIBUTE")}
|
||||
value={condition.attribute ?? ""}
|
||||
onChange={(attribute) =>
|
||||
onChange({
|
||||
@@ -143,7 +147,7 @@ export const NumericStateEditor: Editor<NumericCondition> = ({
|
||||
}
|
||||
/>
|
||||
<InputNumber
|
||||
label="Above"
|
||||
label={langStore.get("ABOVE")}
|
||||
value={condition.above ? Number(condition.above) : undefined}
|
||||
onChange={(above) =>
|
||||
onChange({
|
||||
@@ -153,7 +157,7 @@ export const NumericStateEditor: Editor<NumericCondition> = ({
|
||||
}
|
||||
/>
|
||||
<InputNumber
|
||||
label="Below"
|
||||
label={langStore.get("BELOW")}
|
||||
value={condition.below ? Number(condition.below) : undefined}
|
||||
onChange={(below) =>
|
||||
onChange({
|
||||
@@ -163,7 +167,7 @@ export const NumericStateEditor: Editor<NumericCondition> = ({
|
||||
}
|
||||
/>
|
||||
<InputYaml
|
||||
label="Template"
|
||||
label={langStore.get("TEMPLATE")}
|
||||
value={condition.value_template ?? ""}
|
||||
onChange={(value_template) =>
|
||||
onChange({
|
||||
@@ -221,6 +225,7 @@ export const StateEditor: Editor<StateCondition> = ({
|
||||
onChange,
|
||||
condition,
|
||||
ha,
|
||||
langStore,
|
||||
}) => {
|
||||
const restrictToDomain =
|
||||
!condition.entity_id || condition.entity_id.length === 0
|
||||
@@ -241,7 +246,7 @@ export const StateEditor: Editor<StateCondition> = ({
|
||||
}
|
||||
/>
|
||||
<InputAutoComplete
|
||||
label="Attribute"
|
||||
label={langStore.get("ATTRIBUTE")}
|
||||
value={condition.attribute ?? ""}
|
||||
options={ha.entities.getAttributes(condition.entity_id)}
|
||||
multiple={false}
|
||||
@@ -253,11 +258,11 @@ export const StateEditor: Editor<StateCondition> = ({
|
||||
}
|
||||
/>
|
||||
<InputText
|
||||
label="State"
|
||||
label={langStore.get("STATE")}
|
||||
value={String(condition.state)}
|
||||
placeholder={ha.entities
|
||||
.getStates(condition.entity_id, condition.attribute)
|
||||
.join(" or ")}
|
||||
.join(` ${langStore.get("OR").toLowerCase()} `)}
|
||||
onChange={(state) =>
|
||||
onChange({
|
||||
...condition,
|
||||
@@ -280,7 +285,11 @@ export const StateEditor: Editor<StateCondition> = ({
|
||||
};
|
||||
|
||||
type TimeEditorShows = "after" | "before" | "weekday";
|
||||
export const TimeEditor: Editor<TimeCondition> = ({ onChange, condition }) => {
|
||||
export const TimeEditor: Editor<TimeCondition> = ({
|
||||
onChange,
|
||||
condition,
|
||||
langStore,
|
||||
}) => {
|
||||
const [shows, setShows] = useState<TimeEditorShows[]>(
|
||||
Object.keys(condition).filter((k) =>
|
||||
["after", "before", "weekday"].includes(k)
|
||||
@@ -321,19 +330,19 @@ export const TimeEditor: Editor<TimeCondition> = ({ onChange, condition }) => {
|
||||
<b className="label">{prettyName(show)}</b>
|
||||
<InputAutoComplete
|
||||
className="condition-node--time-editor--weekday"
|
||||
label="Weekday"
|
||||
label={langStore.get("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",
|
||||
mon: langStore.get("DAY_mon"),
|
||||
tue: langStore.get("DAY_tue"),
|
||||
wed: langStore.get("DAY_wed"),
|
||||
thu: langStore.get("DAY_thu"),
|
||||
fri: langStore.get("DAY_fri"),
|
||||
sat: langStore.get("DAY_sat"),
|
||||
sun: langStore.get("DAY_sun"),
|
||||
}[opt];
|
||||
}}
|
||||
onChange={(weekday: any) =>
|
||||
@@ -362,7 +371,7 @@ export const TimeEditor: Editor<TimeCondition> = ({ onChange, condition }) => {
|
||||
{shows.length < 3 && (
|
||||
<InputList
|
||||
className="condition-node--time-editor--new"
|
||||
label="Option"
|
||||
label={langStore.get("OPTION")}
|
||||
options={["after", "before", "weekday"].filter(
|
||||
(k: any) => !shows.includes(k)
|
||||
)}
|
||||
@@ -378,11 +387,12 @@ export const TimeEditor: Editor<TimeCondition> = ({ onChange, condition }) => {
|
||||
export const TriggerEditor: Editor<TriggerCondition> = ({
|
||||
onChange,
|
||||
condition,
|
||||
langStore,
|
||||
}) => {
|
||||
return (
|
||||
<>
|
||||
<InputText
|
||||
label="Trigger ID"
|
||||
label={langStore.get("TRIGGER_ID")}
|
||||
value={condition.id}
|
||||
onChange={(id) =>
|
||||
onChange({
|
||||
@@ -395,11 +405,15 @@ export const TriggerEditor: Editor<TriggerCondition> = ({
|
||||
);
|
||||
};
|
||||
|
||||
export const ZoneEditor: Editor<ZoneCondition> = ({ onChange, condition }) => {
|
||||
export const ZoneEditor: Editor<ZoneCondition> = ({
|
||||
onChange,
|
||||
condition,
|
||||
langStore,
|
||||
}) => {
|
||||
return (
|
||||
<>
|
||||
<InputEntity
|
||||
label="Zone"
|
||||
label={langStore.get("ZONE")}
|
||||
value={condition.zone ?? []}
|
||||
multiple
|
||||
onChange={(zone) =>
|
||||
@@ -411,7 +425,7 @@ export const ZoneEditor: Editor<ZoneCondition> = ({ onChange, condition }) => {
|
||||
restrictToDomain={["zone"]}
|
||||
/>
|
||||
<InputEntity
|
||||
label="Entity with Location"
|
||||
label={langStore.get("ENTITY_WITH_LOCATION")}
|
||||
value={condition.entity_id}
|
||||
multiple
|
||||
onChange={(entity_id) =>
|
||||
|
||||
@@ -13,6 +13,7 @@ import { prettyName } from "utils/formatting";
|
||||
import DeleteForeverIcon from "@mui/icons-material/DeleteForever";
|
||||
import { useConfirm } from "material-ui-confirm";
|
||||
import { useSnackbar } from "notistack";
|
||||
import { useLang } from "lang";
|
||||
|
||||
export const CollectionNodeElement: FC<PropsWithChildren<CollectionNodeProps>> =
|
||||
({
|
||||
@@ -27,6 +28,7 @@ export const CollectionNodeElement: FC<PropsWithChildren<CollectionNodeProps>> =
|
||||
title,
|
||||
children,
|
||||
}) => {
|
||||
const lang = useLang();
|
||||
const color = convertNodeTypeToSequenceNodeColor(collectionType);
|
||||
const nodeColor = useSequenceNodeColor(color);
|
||||
const confirm = useConfirm();
|
||||
@@ -55,14 +57,19 @@ export const CollectionNodeElement: FC<PropsWithChildren<CollectionNodeProps>> =
|
||||
})
|
||||
.then(() => {
|
||||
onDelete();
|
||||
snackbr.enqueueSnackbar("Deleted.", {
|
||||
snackbr.enqueueSnackbar(lang.get("DELETED"), {
|
||||
variant: "info",
|
||||
});
|
||||
})
|
||||
.catch(() =>
|
||||
snackbr.enqueueSnackbar(`Did not delete ${trueTile}.`, {
|
||||
variant: "info",
|
||||
})
|
||||
snackbr.enqueueSnackbar(
|
||||
lang.get("NOT_DELETED_THING", {
|
||||
item: trueTile,
|
||||
}),
|
||||
{
|
||||
variant: "info",
|
||||
}
|
||||
)
|
||||
);
|
||||
}}
|
||||
borderless
|
||||
|
||||
@@ -16,6 +16,7 @@ import InputBoolean from "components/Inputs/Base/InputBoolean";
|
||||
import { SpeedDial } from "components/SpeedDial";
|
||||
import { SequenceNodeElementProps } from "./types";
|
||||
import { useSequenceNodeColor } from "./util";
|
||||
import { useLang } from "lang";
|
||||
|
||||
export const SequenceNodeElement: FC<
|
||||
PropsWithChildren<SequenceNodeElementProps>
|
||||
@@ -35,6 +36,7 @@ export const SequenceNodeElement: FC<
|
||||
isClosed,
|
||||
setIsClosed,
|
||||
}) => {
|
||||
const langStore = useLang();
|
||||
const confirm = useConfirm();
|
||||
const snackbr = useSnackbar();
|
||||
const nodeColor = useSequenceNodeColor(color);
|
||||
@@ -89,18 +91,21 @@ export const SequenceNodeElement: FC<
|
||||
<IconButton
|
||||
onClick={() => {
|
||||
confirm({
|
||||
description: "Are you sure you want to delete this node?",
|
||||
description: langStore.get("CONFIRMATION_DELETE_THIS_NODE"),
|
||||
})
|
||||
.then(() => {
|
||||
onXClick();
|
||||
snackbr.enqueueSnackbar("Deleted.", {
|
||||
snackbr.enqueueSnackbar(langStore.get("DELETED"), {
|
||||
variant: "info",
|
||||
});
|
||||
})
|
||||
.catch(() =>
|
||||
snackbr.enqueueSnackbar("Did not delete node.", {
|
||||
variant: "info",
|
||||
})
|
||||
snackbr.enqueueSnackbar(
|
||||
langStore.get("NOT_DELETED_NODE"),
|
||||
{
|
||||
variant: "info",
|
||||
}
|
||||
)
|
||||
);
|
||||
}}
|
||||
size="small"
|
||||
|
||||
@@ -8,6 +8,7 @@ import { InputEntity } from "components/Inputs/AutoComplete/InputEntities";
|
||||
import { cleanUpUndefined } from "utils/helpers";
|
||||
import { DeviceBaseType, DeviceTypeCapability } from "haService/types";
|
||||
import { AutomationDeviceState } from "types/automations/common";
|
||||
import { useLang } from "lang";
|
||||
|
||||
export type DeviceEditorProps<DBT extends DeviceBaseType> = {
|
||||
type: "action" | "condition" | "trigger";
|
||||
@@ -23,6 +24,8 @@ export function DeviceEditor<DBT extends DeviceBaseType>({
|
||||
caps,
|
||||
options,
|
||||
}: DeviceEditorProps<DBT>) {
|
||||
// state
|
||||
const langStore = useLang();
|
||||
// aliases
|
||||
const update = (upd: Partial<AutomationDeviceState & Record<string, any>>) =>
|
||||
setState(
|
||||
@@ -40,13 +43,13 @@ export function DeviceEditor<DBT extends DeviceBaseType>({
|
||||
<>
|
||||
<InputDevice
|
||||
key="devices"
|
||||
label="Device"
|
||||
label={langStore.get("DEVICE")}
|
||||
value={state.device_id ?? ""}
|
||||
onChange={(device_id) => setState({ device_id: device_id ?? "" })}
|
||||
/>
|
||||
<InputAutoComplete
|
||||
key="action"
|
||||
label="Action"
|
||||
label={langStore.get("ACTION")}
|
||||
multiple={false}
|
||||
value={actionId}
|
||||
options={Object.keys(options).map((k) => options[k])}
|
||||
@@ -67,7 +70,7 @@ export function DeviceEditor<DBT extends DeviceBaseType>({
|
||||
{entities.length > 0 && (
|
||||
<InputEntity
|
||||
key={"entities" + state.device_id}
|
||||
label="Entity"
|
||||
label={langStore.get("ENTITY")}
|
||||
value={state.entity_id ?? ""}
|
||||
multiple={false}
|
||||
onChange={(entity_id) =>
|
||||
@@ -85,7 +88,11 @@ export function DeviceEditor<DBT extends DeviceBaseType>({
|
||||
/>
|
||||
)}
|
||||
{Object.keys(options).length + entities.length === 0 && (
|
||||
<>This device has no {type}s.</>
|
||||
<>
|
||||
{langStore.get("WARNING_DEVICE_NO_TYPES", {
|
||||
type: `${type}s`,
|
||||
})}
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -9,6 +9,7 @@ import FormHelperText from "@mui/material/FormHelperText";
|
||||
import InputAdornment from "@mui/material/InputAdornment";
|
||||
import { Save } from "@mui/icons-material";
|
||||
import { ButtonIcon } from "components/Icons/ButtonIcons";
|
||||
import { useLang } from "lang";
|
||||
|
||||
export interface Props<T extends {}> {
|
||||
label: string;
|
||||
@@ -34,6 +35,7 @@ export default function InputYaml<T extends {}>({
|
||||
helperText,
|
||||
endAdornment,
|
||||
}: Props<T>) {
|
||||
const langStore = useLang();
|
||||
const originalText = yaml.dump(value);
|
||||
const [{ text, error }, setState] = useState<{
|
||||
text: string;
|
||||
@@ -48,7 +50,7 @@ export default function InputYaml<T extends {}>({
|
||||
yaml.load(t);
|
||||
setState({ text: t, error: undefined });
|
||||
} catch (_) {
|
||||
setState({ text: t, error: "! Invalid Yaml !" });
|
||||
setState({ text: t, error: langStore.get("ERROR_INVALID_YAML") });
|
||||
}
|
||||
};
|
||||
const onSave = () => {
|
||||
@@ -94,7 +96,9 @@ export default function InputYaml<T extends {}>({
|
||||
<ButtonIcon
|
||||
disabled={!hasChanged}
|
||||
onClick={() => onSave()}
|
||||
title={!!error ? "Invalid YAML" : hasChanged ? "Save" : ""}
|
||||
title={
|
||||
!!error ? "Invalid YAML" : hasChanged ? langStore.get("SAVE") : ""
|
||||
}
|
||||
icon={
|
||||
<Save
|
||||
color={hasChanged ? (!!error ? "error" : "success") : "disabled"}
|
||||
|
||||
@@ -7,6 +7,7 @@ import FormControl from "@mui/material/FormControl";
|
||||
import Select from "@mui/material/Select";
|
||||
import { prettyName } from "utils/formatting";
|
||||
import { ReactNode } from "react";
|
||||
import { useLang } from "lang";
|
||||
|
||||
export type Props<T extends string | Object> = {
|
||||
current?: T;
|
||||
@@ -17,6 +18,7 @@ export type Props<T extends string | Object> = {
|
||||
className?: string;
|
||||
prettyOptionLabels?: boolean;
|
||||
getKey?: (n: T) => string;
|
||||
getLabel?: (n: T) => string;
|
||||
getDescription?: (n: T) => string;
|
||||
placeholder?: any;
|
||||
title?: string;
|
||||
@@ -34,6 +36,7 @@ export function InputList<T extends string | Object>({
|
||||
className,
|
||||
prettyOptionLabels = true,
|
||||
getKey = String,
|
||||
getLabel: _getLabel,
|
||||
getDescription,
|
||||
placeholder,
|
||||
title,
|
||||
@@ -42,8 +45,17 @@ export function InputList<T extends string | Object>({
|
||||
disabled,
|
||||
fullWidth = true,
|
||||
}: Props<T>) {
|
||||
const langStore = useLang();
|
||||
const invalidCurrent =
|
||||
current && !options.map(getKey).includes(getKey(current));
|
||||
|
||||
const getLabel =
|
||||
_getLabel ??
|
||||
function (x: T) {
|
||||
return typeof x === "string"
|
||||
? prettyName(langStore.get(x.toUpperCase()))
|
||||
: getKey(x);
|
||||
};
|
||||
return (
|
||||
<FormControl
|
||||
className={className}
|
||||
@@ -73,7 +85,11 @@ export function InputList<T extends string | Object>({
|
||||
>
|
||||
{options.map((t, i) => (
|
||||
<MenuItem key={i} value={getKey(t)} className="input-list--menu-item">
|
||||
{prettyOptionLabels ? prettyName(getKey(t)) : getKey(t)}
|
||||
{prettyOptionLabels
|
||||
? prettyName(getKey(t))
|
||||
: getLabel
|
||||
? getLabel(t)
|
||||
: getKey(t)}
|
||||
{!!getDescription && (
|
||||
<>
|
||||
<br />
|
||||
|
||||
@@ -5,6 +5,7 @@ import Autocomplete from "@mui/material/Autocomplete";
|
||||
import TextField from "@mui/material/TextField";
|
||||
import Checkbox from "@mui/material/Checkbox";
|
||||
import { useSnackbar } from "notistack";
|
||||
import { useLang } from "lang";
|
||||
|
||||
export interface Props<T extends string> {
|
||||
label: string;
|
||||
@@ -23,6 +24,7 @@ export default function InputMultiSelect<T extends string>({
|
||||
max = 3,
|
||||
}: Props<T>) {
|
||||
// alias
|
||||
const langStore = useLang();
|
||||
const snackbr = useSnackbar();
|
||||
return (
|
||||
<Autocomplete
|
||||
@@ -31,10 +33,13 @@ export default function InputMultiSelect<T extends string>({
|
||||
value={selected.map((i) => options[i])}
|
||||
onChange={(_, newValues: T[] = []) => {
|
||||
if (newValues.length > max) {
|
||||
snackbr.enqueueSnackbar("Can only select up to 3 tags", {
|
||||
variant: "warning",
|
||||
autoHideDuration: 1500,
|
||||
});
|
||||
snackbr.enqueueSnackbar(
|
||||
langStore.get("VALIDATION_MAX_TAG_SELECTION", { count: "3" }),
|
||||
{
|
||||
variant: "warning",
|
||||
autoHideDuration: 1500,
|
||||
}
|
||||
);
|
||||
}
|
||||
onChange(
|
||||
newValues
|
||||
|
||||
@@ -13,6 +13,7 @@ import { getDescriptionFromAutomationNode } from "utils/formatting";
|
||||
import { useHA } from "haService";
|
||||
import { Generic } from "./Generic";
|
||||
import { getNodeTypeAndValidate } from "utils/automations";
|
||||
import { useLang } from "lang";
|
||||
|
||||
type UseState = <S>(s: S) => [S, Dispatch<SetStateAction<S>>];
|
||||
|
||||
@@ -23,6 +24,7 @@ export const useEditorNodeState = (
|
||||
uState: UseState = useState
|
||||
) => {
|
||||
// state
|
||||
const langStore = useLang();
|
||||
const [allState, setAllState] = uState({
|
||||
yamlMode: false,
|
||||
isModified: false,
|
||||
@@ -77,7 +79,9 @@ export const useEditorNodeState = (
|
||||
isErrored: allState.isErrored,
|
||||
get prettyNodeType() {
|
||||
if (nodeType) {
|
||||
return `${nodeType.slice(0, 1).toUpperCase()}${nodeType.slice(1)} Type`;
|
||||
return `${langStore.get(nodeType.toUpperCase())} ${langStore.get(
|
||||
"TYPE"
|
||||
)}`;
|
||||
} else {
|
||||
return "n/a";
|
||||
}
|
||||
@@ -100,7 +104,7 @@ export const useEditorNodeState = (
|
||||
aliasEditor = (
|
||||
<InputText
|
||||
key="alias"
|
||||
label="Trigger ID"
|
||||
label={langStore.get("TRIGGER_ID")}
|
||||
value={(allState.node as any).id}
|
||||
onChange={(id) =>
|
||||
setState({
|
||||
@@ -115,7 +119,7 @@ export const useEditorNodeState = (
|
||||
aliasEditor = (
|
||||
<InputText
|
||||
key="alias"
|
||||
label="Alias"
|
||||
label={langStore.get("ALIAS")}
|
||||
value={getDescriptionFromAutomationNode(
|
||||
allState.node,
|
||||
ha.namer,
|
||||
|
||||
@@ -8,6 +8,7 @@ import { Button } from "components/Inputs/Buttons/Button";
|
||||
import InputBoolean from "components/Inputs/Base/InputBoolean";
|
||||
import { useConfirm } from "material-ui-confirm";
|
||||
import { getNodeSubTypeDescription } from "./utils";
|
||||
import { useLang } from "lang";
|
||||
|
||||
export interface NodeEditorProps {
|
||||
node: AutomationNode;
|
||||
@@ -29,6 +30,7 @@ export const NodeEditor: FC<NodeEditorProps> = ({
|
||||
children,
|
||||
}) => {
|
||||
// state
|
||||
const langStore = useLang();
|
||||
const state = useEditorNodeState(node, allowedTypes, saveBtnCreateText);
|
||||
const confirm = useConfirm();
|
||||
|
||||
@@ -41,19 +43,19 @@ export const NodeEditor: FC<NodeEditorProps> = ({
|
||||
) => {
|
||||
const notes: string[] = [];
|
||||
if (!isReady) {
|
||||
notes.push("This node is missing some values");
|
||||
notes.push(langStore.get("VALIDATION_MISSING_VALUES_FOR_NODE"));
|
||||
}
|
||||
if (state.isErrored) {
|
||||
notes.push("This node contains errors");
|
||||
notes.push(langStore.get("VALIDATION_ERROR_VALUES_IN_NODE"));
|
||||
}
|
||||
if (checkModified && isModified) {
|
||||
notes.push("This node is has some unsaved work");
|
||||
notes.push(langStore.get("VALIDATION_UNSAVED_WORK_IN_NODE"));
|
||||
}
|
||||
if (notes.length > 0) {
|
||||
try {
|
||||
await confirm({
|
||||
confirmationText: "Yes",
|
||||
title: `Are you sure you want to ${what}?`,
|
||||
title: langStore.get("CONFIRM_EXIT", { what }),
|
||||
description: (
|
||||
<ul>
|
||||
{notes.map((n, i) => (
|
||||
@@ -85,11 +87,11 @@ export const NodeEditor: FC<NodeEditorProps> = ({
|
||||
<div className="node-editor--body-title">
|
||||
{allowedTypes.length > 1 ? (
|
||||
<InputList
|
||||
label="Type"
|
||||
label={langStore.get("TYPE")}
|
||||
current={state.nodeType}
|
||||
options={allowedTypes}
|
||||
onChange={state.setNodeType}
|
||||
prettyOptionLabels
|
||||
prettyOptionLabels={false}
|
||||
/>
|
||||
) : (
|
||||
<></>
|
||||
@@ -101,7 +103,7 @@ export const NodeEditor: FC<NodeEditorProps> = ({
|
||||
getDescription={getNodeSubTypeDescription}
|
||||
options={state.subTypes}
|
||||
onChange={state.setSubType}
|
||||
prettyOptionLabels
|
||||
prettyOptionLabels={false}
|
||||
/>
|
||||
) : (
|
||||
<></>
|
||||
@@ -115,7 +117,7 @@ export const NodeEditor: FC<NodeEditorProps> = ({
|
||||
/>
|
||||
<InputBoolean
|
||||
className="enabled-flag"
|
||||
label="Enabled"
|
||||
label={langStore.get("ENABLED")}
|
||||
value={state.data.enabled ?? true}
|
||||
onChange={state.setEnabled}
|
||||
/>
|
||||
@@ -140,9 +142,11 @@ export const NodeEditor: FC<NodeEditorProps> = ({
|
||||
onClick={() =>
|
||||
areYouSureNotReady("save").then((ok) => ok && onSave(state.data))
|
||||
}
|
||||
title={!isReady ? "Some fields have not been properly filled up" : ""}
|
||||
title={
|
||||
!isReady ? langStore.get("VALIDATION_NOT_ALL_FIELD_FILLED_IN") : ""
|
||||
}
|
||||
>
|
||||
{saveBtnCreateText ? "Create" : "Save"}
|
||||
{saveBtnCreateText ? langStore.get("CREATE") : langStore.get("SAVE")}
|
||||
</Button>
|
||||
{children}
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user