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
@@ -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)}
|
||||
|
||||
Reference in new issue
Block a user