added boolean to serviceeditor
helpertext
This commit is contained in:
1 parent
1496bc66ad
commit
da699403df
7 files changed
+322
-137
No files matched your search
@@ -197,6 +197,10 @@ export function InputAutoComplete<T extends Option>(
|
||||
renderInput={(params) => (
|
||||
<TextField
|
||||
{...params}
|
||||
InputProps={{
|
||||
...params.InputProps,
|
||||
endAdornment: props.endAdornment ?? params.InputProps.endAdornment,
|
||||
}}
|
||||
variant="filled"
|
||||
required={props.required}
|
||||
label={props.label ?? "Entity ID"}
|
||||
|
||||
@@ -1,27 +1,41 @@
|
||||
import Checkbox from "@mui/material/Checkbox";
|
||||
import FormGroup from "@mui/material/FormGroup";
|
||||
import FormControlLabel from "@mui/material/FormControlLabel";
|
||||
import { ReactNode } from "react";
|
||||
import { FormHelperText, InputAdornment } from "@mui/material";
|
||||
|
||||
export interface Props {
|
||||
label: string;
|
||||
value: boolean;
|
||||
title?: string;
|
||||
helperText?: string;
|
||||
onChange: (v: boolean) => void;
|
||||
disabled?: boolean;
|
||||
className?: string;
|
||||
required?: boolean;
|
||||
placeholder?: string;
|
||||
endAdornment?: ReactNode;
|
||||
}
|
||||
export default function InputBoolean({
|
||||
label,
|
||||
value = false,
|
||||
title,
|
||||
helperText,
|
||||
onChange,
|
||||
disabled = false,
|
||||
className,
|
||||
required,
|
||||
placeholder,
|
||||
endAdornment,
|
||||
}: Props) {
|
||||
return (
|
||||
<FormGroup className={className}>
|
||||
<FormGroup
|
||||
className={className}
|
||||
title={title}
|
||||
style={{
|
||||
alignItems: "flex-start",
|
||||
}}
|
||||
>
|
||||
<FormControlLabel
|
||||
disabled={disabled}
|
||||
control={
|
||||
@@ -32,8 +46,31 @@ export default function InputBoolean({
|
||||
placeholder={placeholder}
|
||||
/>
|
||||
}
|
||||
label={label}
|
||||
label={
|
||||
endAdornment ? (
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
flexDirection: "row",
|
||||
justifyContent: "center",
|
||||
alignItems: "center",
|
||||
}}
|
||||
>
|
||||
<span
|
||||
style={{
|
||||
flex: 1,
|
||||
}}
|
||||
>
|
||||
{label}
|
||||
</span>
|
||||
<InputAdornment position="end">{endAdornment}</InputAdornment>
|
||||
</div>
|
||||
) : (
|
||||
label
|
||||
)
|
||||
}
|
||||
/>
|
||||
<FormHelperText>{helperText}</FormHelperText>
|
||||
</FormGroup>
|
||||
);
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import TextField from "@mui/material/TextField";
|
||||
import IconButton from "@mui/material/IconButton";
|
||||
import InputAdornment from "@mui/material/InputAdornment";
|
||||
import Edit from "@mui/icons-material/Edit";
|
||||
import { ReactNode } from "react";
|
||||
|
||||
export interface Props {
|
||||
label: string | JSX.Element;
|
||||
@@ -15,6 +16,7 @@ export interface Props {
|
||||
unit?: string;
|
||||
placeholder?: any;
|
||||
required?: boolean;
|
||||
endAdornment?: ReactNode;
|
||||
}
|
||||
export default function InputNumber({
|
||||
label,
|
||||
@@ -27,6 +29,7 @@ export default function InputNumber({
|
||||
unit,
|
||||
placeholder,
|
||||
required,
|
||||
endAdornment,
|
||||
}: Props) {
|
||||
const disabled = value === undefined || value === null;
|
||||
let labelElm = <></>;
|
||||
@@ -54,7 +57,9 @@ export default function InputNumber({
|
||||
required={required}
|
||||
fullWidth
|
||||
InputProps={{
|
||||
endAdornment: (
|
||||
endAdornment: endAdornment ? (
|
||||
endAdornment
|
||||
) : (
|
||||
<InputAdornment position="end">
|
||||
<IconButton onClick={() => onChange(disabled ? 0 : undefined)}>
|
||||
{disabled ? <Edit /> : <Close />}
|
||||
|
||||
@@ -2,4 +2,18 @@
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.service-editor--field .MuiFormHelperText-contained {
|
||||
max-width: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.service-editor--field--description {
|
||||
text-overflow: ellipsis;
|
||||
overflow: hidden;
|
||||
word-wrap: break-word;
|
||||
white-space: nowrap;
|
||||
width: 100%;
|
||||
max-width: 100%;
|
||||
}
|
||||
@@ -7,6 +7,8 @@ import { IconButton } from "@mui/material";
|
||||
import { RemoveCircle } from "@mui/icons-material";
|
||||
import { InputAutoComplete, Option } from "components/Inputs/InputAutoComplete";
|
||||
import { prettyName } from "utils/formatting";
|
||||
import InputBoolean from "components/Inputs/InputBoolean";
|
||||
import { SelectorNumber, SelectorText } from "haService/fieldTypes";
|
||||
|
||||
export type ServiceEditorFieldProps = {
|
||||
option: ServiceEditorOption;
|
||||
@@ -32,64 +34,63 @@ export const ServiceEditorField: FC<ServiceEditorFieldProps> = ({
|
||||
</IconButton>
|
||||
);
|
||||
example = option.data.example ? `Example: ${option.data.example}` : "";
|
||||
if (option.data.selector?.number) {
|
||||
return (
|
||||
<InputNumber
|
||||
className="service-editor--field"
|
||||
label={label}
|
||||
value={value ?? option.data.default}
|
||||
min={option.data.selector.number.min}
|
||||
max={option.data.selector.number.max}
|
||||
step={option.data.selector.number.step}
|
||||
unit={option.data.selector.number.unit_of_measurement}
|
||||
onChange={onChange}
|
||||
required={isRequired}
|
||||
placeholder={example}
|
||||
/>
|
||||
);
|
||||
}
|
||||
if (option.data.selector?.select) {
|
||||
return (
|
||||
<InputAutoComplete
|
||||
className="service-editor--field"
|
||||
label={label}
|
||||
value={value}
|
||||
onChange={onChange}
|
||||
endAdornment={removeIcon}
|
||||
required={isRequired}
|
||||
options={option.data.selector.select.options.map<Option>((opt) => {
|
||||
if (typeof opt === "string") {
|
||||
const prop = {
|
||||
className: "service-editor--field",
|
||||
label,
|
||||
title: description,
|
||||
helperText: (
|
||||
<div className="service-editor--field--description">{description}</div>
|
||||
),
|
||||
value: value ?? option.data.default,
|
||||
onChange: onChange,
|
||||
required: isRequired,
|
||||
placeholder: example,
|
||||
endAdornment: removeIcon,
|
||||
};
|
||||
if (option.data.selector) {
|
||||
if ("number" in option.data.selector) {
|
||||
const options: Partial<SelectorNumber> =
|
||||
option.data.selector.number ?? {};
|
||||
return (
|
||||
<InputNumber
|
||||
{...prop}
|
||||
min={options.min}
|
||||
max={options.max}
|
||||
step={options.step}
|
||||
/>
|
||||
);
|
||||
}
|
||||
if (option.data.selector?.select) {
|
||||
return (
|
||||
<InputAutoComplete
|
||||
{...prop}
|
||||
options={option.data.selector.select.options.map<Option>((opt) => {
|
||||
if (typeof opt === "string") {
|
||||
return {
|
||||
id: opt,
|
||||
label: prettyName(opt),
|
||||
};
|
||||
}
|
||||
return {
|
||||
id: opt,
|
||||
label: prettyName(opt),
|
||||
id: opt.value,
|
||||
label: opt.label,
|
||||
};
|
||||
}
|
||||
return {
|
||||
id: opt.value,
|
||||
label: opt.label,
|
||||
};
|
||||
})}
|
||||
getLabel={(opt) => {
|
||||
if (typeof opt === "string") {
|
||||
return prettyName(opt);
|
||||
}
|
||||
return opt.label;
|
||||
}}
|
||||
onlyShowLabel
|
||||
/>
|
||||
);
|
||||
})}
|
||||
getLabel={(opt) => {
|
||||
if (typeof opt === "string") {
|
||||
return prettyName(opt);
|
||||
}
|
||||
return opt.label;
|
||||
}}
|
||||
onlyShowLabel
|
||||
/>
|
||||
);
|
||||
} else if ("text" in option.data.selector) {
|
||||
const options: Partial<SelectorText> = option.data.selector.text ?? {};
|
||||
return <InputText {...prop} multiline={options.multiline} />;
|
||||
} else if ("boolean" in option.data.selector) {
|
||||
return <InputBoolean {...prop} />;
|
||||
}
|
||||
}
|
||||
return (
|
||||
<InputText
|
||||
className="service-editor--field"
|
||||
label={label}
|
||||
title={description}
|
||||
helperText={description}
|
||||
value={value ?? option.data.default}
|
||||
onChange={onChange}
|
||||
placeholder={example}
|
||||
required={isRequired}
|
||||
endAdornment={removeIcon}
|
||||
/>
|
||||
);
|
||||
return <InputText {...prop} />;
|
||||
};
|
||||
@@ -16,41 +16,52 @@ const Template: ComponentStory<typeof ServiceEditor> = (props) => {
|
||||
const [state, setState] = useState(props.data);
|
||||
return (
|
||||
<Page>
|
||||
<ServiceEditor
|
||||
{...props}
|
||||
data={state}
|
||||
onUpdate={(d) => {
|
||||
setState(d);
|
||||
props.onUpdate(d);
|
||||
}}
|
||||
/>
|
||||
<div
|
||||
style={{
|
||||
maxHeight: "25vh",
|
||||
maxHeight: "99vh",
|
||||
overflow: "auto",
|
||||
}}
|
||||
>
|
||||
<InputYaml label="" value={state} onChange={() => {}} />
|
||||
</div>
|
||||
<div
|
||||
style={{
|
||||
maxHeight: "25vh",
|
||||
overflow: "auto",
|
||||
}}
|
||||
>
|
||||
<InputYaml label="" value={props.service.fields} onChange={() => {}} />
|
||||
</div>
|
||||
<div
|
||||
style={{
|
||||
maxHeight: "25vh",
|
||||
overflow: "auto",
|
||||
}}
|
||||
>
|
||||
<InputYaml
|
||||
label=""
|
||||
value={props.service.target ?? {}}
|
||||
onChange={() => {}}
|
||||
<ServiceEditor
|
||||
{...props}
|
||||
data={state}
|
||||
onUpdate={(d) => {
|
||||
setState(d);
|
||||
props.onUpdate(d);
|
||||
}}
|
||||
/>
|
||||
<div
|
||||
style={{
|
||||
maxHeight: "25vh",
|
||||
overflow: "auto",
|
||||
}}
|
||||
>
|
||||
<InputYaml label="" value={state} onChange={() => {}} />
|
||||
</div>
|
||||
<div
|
||||
style={{
|
||||
maxHeight: "25vh",
|
||||
overflow: "auto",
|
||||
}}
|
||||
>
|
||||
<InputYaml
|
||||
label=""
|
||||
value={props.service.fields}
|
||||
onChange={() => {}}
|
||||
/>
|
||||
</div>
|
||||
<div
|
||||
style={{
|
||||
maxHeight: "25vh",
|
||||
overflow: "auto",
|
||||
}}
|
||||
>
|
||||
<InputYaml
|
||||
label=""
|
||||
value={props.service.target ?? {}}
|
||||
onChange={() => {}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</Page>
|
||||
);
|
||||
@@ -427,3 +438,122 @@ export const LightTurnOn = makeExample({
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const UltimateService = makeExample({
|
||||
name: "Ultimate Service",
|
||||
description: "Show a notification in the frontend.",
|
||||
fields: {
|
||||
message: {
|
||||
name: "Text",
|
||||
description: "Message body of the notification. [Templates accepted]",
|
||||
example: "Please check your configuration.yaml.",
|
||||
selector: {
|
||||
text: null,
|
||||
},
|
||||
},
|
||||
entity_id: {
|
||||
name: "Entity with domain filter",
|
||||
description: "Name(s) of media player entities.",
|
||||
selector: {
|
||||
entity: {
|
||||
domain: "media_player",
|
||||
},
|
||||
},
|
||||
},
|
||||
level: {
|
||||
name: "Options",
|
||||
description: "Log level.",
|
||||
default: "error",
|
||||
selector: {
|
||||
select: {
|
||||
options: [
|
||||
{
|
||||
label: "Debug",
|
||||
value: "debug",
|
||||
},
|
||||
{
|
||||
label: "Info",
|
||||
value: "info",
|
||||
},
|
||||
{
|
||||
label: "Warning",
|
||||
value: "warning",
|
||||
},
|
||||
{
|
||||
label: "Error",
|
||||
value: "error",
|
||||
},
|
||||
{
|
||||
label: "Critical",
|
||||
value: "critical",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
format: {
|
||||
name: "String Options",
|
||||
description: "Stream format supported by media player.",
|
||||
default: "hls",
|
||||
selector: {
|
||||
select: {
|
||||
options: ["hls"],
|
||||
},
|
||||
},
|
||||
},
|
||||
keep_days: {
|
||||
name: "Number",
|
||||
description: "Number of history days to keep in database after purge.",
|
||||
selector: {
|
||||
number: {
|
||||
min: 0,
|
||||
max: 365,
|
||||
unit_of_measurement: "days",
|
||||
},
|
||||
},
|
||||
},
|
||||
repack: {
|
||||
name: "Boolean",
|
||||
description:
|
||||
"Attempt to save disk space by rewriting the entire database file.",
|
||||
default: false,
|
||||
selector: {
|
||||
boolean: null,
|
||||
},
|
||||
},
|
||||
domains: {
|
||||
name: "Objects",
|
||||
description:
|
||||
"List the domains that need to be removed from the recorder database.",
|
||||
example: "sun",
|
||||
default: [],
|
||||
selector: {
|
||||
object: null,
|
||||
},
|
||||
},
|
||||
addon: {
|
||||
name: "Add-on",
|
||||
description: "The add-on slug.",
|
||||
example: "core_ssh",
|
||||
selector: {
|
||||
addon: null,
|
||||
},
|
||||
},
|
||||
name: {
|
||||
name: "Theme",
|
||||
description: "Name of a predefined theme",
|
||||
example: "default",
|
||||
selector: {
|
||||
theme: null,
|
||||
},
|
||||
},
|
||||
icon: {
|
||||
name: "Icon",
|
||||
description: "Name of icon for the group.",
|
||||
example: "mdi:camera",
|
||||
selector: {
|
||||
icon: null,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
Reference in new issue
Block a user