mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-28 11:46:42 +00:00
Fix enable checkbox in service field subsections (#22299)
* Fix enable checkbox in service field subsections * fix bug
This commit is contained in:
parent
dc0cab9307
commit
df064967ca
@ -61,6 +61,11 @@ const showOptionalToggle = (field) =>
|
|||||||
!field.required &&
|
!field.required &&
|
||||||
!("boolean" in field.selector && field.default);
|
!("boolean" in field.selector && field.default);
|
||||||
|
|
||||||
|
interface Field extends Omit<HassService["fields"][string], "selector"> {
|
||||||
|
key: string;
|
||||||
|
selector?: Selector;
|
||||||
|
}
|
||||||
|
|
||||||
interface ExtHassService extends Omit<HassService, "fields"> {
|
interface ExtHassService extends Omit<HassService, "fields"> {
|
||||||
fields: Array<
|
fields: Array<
|
||||||
Omit<HassService["fields"][string], "selector"> & {
|
Omit<HassService["fields"][string], "selector"> & {
|
||||||
@ -70,6 +75,7 @@ interface ExtHassService extends Omit<HassService, "fields"> {
|
|||||||
collapsed?: boolean;
|
collapsed?: boolean;
|
||||||
}
|
}
|
||||||
>;
|
>;
|
||||||
|
flatFields: Array<Field>;
|
||||||
hasSelector: string[];
|
hasSelector: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,7 +183,7 @@ export class HaServiceControl extends LitElement {
|
|||||||
if (!this._value.data) {
|
if (!this._value.data) {
|
||||||
this._value.data = {};
|
this._value.data = {};
|
||||||
}
|
}
|
||||||
serviceData.fields.forEach((field) => {
|
serviceData.flatFields.forEach((field) => {
|
||||||
if (
|
if (
|
||||||
field.selector &&
|
field.selector &&
|
||||||
field.required &&
|
field.required &&
|
||||||
@ -241,22 +247,28 @@ export class HaServiceControl extends LitElement {
|
|||||||
selector: value.selector as Selector | undefined,
|
selector: value.selector as Selector | undefined,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
const flatFields: Field[] = [];
|
||||||
const hasSelector: string[] = [];
|
const hasSelector: string[] = [];
|
||||||
fields.forEach((field) => {
|
fields.forEach((field) => {
|
||||||
if ((field as any).fields) {
|
if ((field as any).fields) {
|
||||||
Object.entries((field as any).fields).forEach(([key, subField]) => {
|
Object.entries((field as any).fields).forEach(([key, subField]) => {
|
||||||
|
flatFields.push({ ...(subField as Field), key });
|
||||||
if ((subField as any).selector) {
|
if ((subField as any).selector) {
|
||||||
hasSelector.push(key);
|
hasSelector.push(key);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (field.selector) {
|
} else {
|
||||||
|
flatFields.push(field);
|
||||||
|
if (field.selector) {
|
||||||
hasSelector.push(field.key);
|
hasSelector.push(field.key);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...serviceDomains[domain][serviceName],
|
...serviceDomains[domain][serviceName],
|
||||||
fields,
|
fields,
|
||||||
|
flatFields,
|
||||||
hasSelector,
|
hasSelector,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -397,7 +409,7 @@ export class HaServiceControl extends LitElement {
|
|||||||
|
|
||||||
const hasOptional = Boolean(
|
const hasOptional = Boolean(
|
||||||
!shouldRenderServiceDataYaml &&
|
!shouldRenderServiceDataYaml &&
|
||||||
serviceData?.fields.some((field) => showOptionalToggle(field))
|
serviceData?.flatFields.some((field) => showOptionalToggle(field))
|
||||||
);
|
);
|
||||||
|
|
||||||
const targetEntities = this._getTargetedEntities(
|
const targetEntities = this._getTargetedEntities(
|
||||||
@ -667,7 +679,7 @@ export class HaServiceControl extends LitElement {
|
|||||||
const field = this._getServiceInfo(
|
const field = this._getServiceInfo(
|
||||||
this._value?.action,
|
this._value?.action,
|
||||||
this.hass.services
|
this.hass.services
|
||||||
)?.fields.find((_field) => _field.key === key);
|
)?.flatFields.find((_field) => _field.key === key);
|
||||||
|
|
||||||
let defaultValue = field?.default;
|
let defaultValue = field?.default;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user