added boolean to serviceeditor

helpertext
This commit is contained in:
ari committed 2022-06-19 00:29:39 -04:00
1 parent 1496bc66ad
commit da699403df
7 files changed
+322 -137

No files matched your search

@@ -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,
},
},
},
});