input area
This commit is contained in:
1 parent
0fc3ea6146
commit
15c97b81b4
16 files changed
+699
-416
No files matched your search
@@ -5,10 +5,7 @@ import InputText from "components/Inputs/InputText";
|
||||
import InputNumber from "components/Inputs/InputNumber";
|
||||
import { IconButton } from "@mui/material";
|
||||
import { RemoveCircle } from "@mui/icons-material";
|
||||
import { InputEntity } from "components/Inputs/InputEntities";
|
||||
import InputAutoText from "components/Inputs/InputAutoText";
|
||||
import { InputAutoComplete } from "components/Inputs/InputAutoComplete";
|
||||
import { Option } from "haService";
|
||||
import { InputAutoComplete, Option } from "components/Inputs/InputAutoComplete";
|
||||
import { prettyName } from "utils/formatting";
|
||||
|
||||
export type ServiceEditorFieldProps = {
|
||||
@@ -45,85 +42,67 @@ export const ServiceEditorField: FC<ServiceEditorFieldProps> = ({
|
||||
required={isRequired}
|
||||
/>
|
||||
);
|
||||
if (option.type === "field") {
|
||||
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") {
|
||||
return {
|
||||
id: opt,
|
||||
label: prettyName(opt),
|
||||
};
|
||||
}
|
||||
return {
|
||||
id: opt.value,
|
||||
label: opt.label,
|
||||
};
|
||||
})}
|
||||
getLabel={(opt) => {
|
||||
if (typeof opt === "string") {
|
||||
return prettyName(opt);
|
||||
}
|
||||
return opt.label;
|
||||
}}
|
||||
onlyShowLabel
|
||||
/>
|
||||
);
|
||||
}
|
||||
example = option.data.example ? `Example: ${option.data.example}` : "";
|
||||
if (option.data.selector?.number) {
|
||||
return (
|
||||
<InputText
|
||||
<InputNumber
|
||||
className="service-editor--field"
|
||||
label={label}
|
||||
title={description}
|
||||
helperText={description}
|
||||
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}
|
||||
placeholder={example}
|
||||
required={isRequired}
|
||||
endAdornment={removeIcon}
|
||||
placeholder={example}
|
||||
/>
|
||||
);
|
||||
} else {
|
||||
if (option.id === "entity") {
|
||||
if ("domain" in option.data) {
|
||||
return (
|
||||
<InputEntity
|
||||
value={value}
|
||||
onChange={onChange}
|
||||
className="service-editor--field"
|
||||
multiple
|
||||
restrictToDomain={
|
||||
option.data.domain ? [option.data.domain] : undefined
|
||||
}
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
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") {
|
||||
return {
|
||||
id: opt,
|
||||
label: prettyName(opt),
|
||||
};
|
||||
}
|
||||
return {
|
||||
id: opt.value,
|
||||
label: opt.label,
|
||||
};
|
||||
})}
|
||||
getLabel={(opt) => {
|
||||
if (typeof opt === "string") {
|
||||
return prettyName(opt);
|
||||
}
|
||||
return opt.label;
|
||||
}}
|
||||
onlyShowLabel
|
||||
/>
|
||||
);
|
||||
}
|
||||
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 input;
|
||||
};
|
||||
Reference in new issue
Block a user