Skip to content

Commit

Permalink
Revert conditional rendering of condition (#19257)
Browse files Browse the repository at this point in the history
* Fix conditionally showing `triggered by`

* revert conditional rendering

* Update add-automation-element-dialog.ts

* Update add-automation-element-dialog.ts
  • Loading branch information
bramkragten authored Jan 3, 2024
1 parent c7a98fa commit 29fefa1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 26 deletions.
1 change: 1 addition & 0 deletions src/data/condition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export const CONDITION_GROUPS: AutomationElementGroup = {
icon: mdiDotsHorizontal,
members: {
template: {},
trigger: {},
},
},
} as const;
43 changes: 19 additions & 24 deletions src/panels/config/automation/add-automation-element-dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,16 @@ class DialogAddAutomationElement extends LitElement implements HassDialog {
this._domains = undefined;
}

private _getGroups = (
type: AddAutomationElementDialogParams["type"],
group: string | undefined
): AutomationElementGroup =>
group
? isService(group)
? {}
: TYPES[type].groups[group].members!
: TYPES[type].groups;

private _convertToItem = (
key: string,
options,
Expand All @@ -169,22 +179,13 @@ class DialogAddAutomationElement extends LitElement implements HassDialog {
private _getFilteredItems = memoizeOne(
(
type: AddAutomationElementDialogParams["type"],
root: AddAutomationElementDialogParams["root"],
group: string | undefined,
filter: string,
localize: LocalizeFunc,
services: HomeAssistant["services"],
manifests?: DomainManifestLookup
): ListItem[] => {
const groups: AutomationElementGroup = group
? isService(group)
? {}
: TYPES[type].groups[group].members!
: TYPES[type].groups;

if (type === "condition" && group === "other" && !root) {
groups.trigger = {};
}
const groups = this._getGroups(type, group);

const flattenGroups = (grp: AutomationElementGroup) =>
Object.entries(grp).map(([key, options]) =>
Expand Down Expand Up @@ -213,28 +214,24 @@ class DialogAddAutomationElement extends LitElement implements HassDialog {
private _getGroupItems = memoizeOne(
(
type: AddAutomationElementDialogParams["type"],
root: AddAutomationElementDialogParams["root"],
group: string | undefined,
domains: Set<string> | undefined,
localize: LocalizeFunc,
services: HomeAssistant["services"],
manifests?: DomainManifestLookup
): ListItem[] => {
if (type === "action" && isService(group)) {
const result = this._services(localize, services, manifests, group);
let result = this._services(localize, services, manifests, group);
if (group === `${SERVICE_PREFIX}media_player`) {
result.unshift(this._convertToItem("play_media", {}, type, localize));
result = [
this._convertToItem("play_media", {}, type, localize),
...result,
];
}
return result;
}

const groups: AutomationElementGroup = group
? TYPES[type].groups[group].members!
: TYPES[type].groups;

if (type === "condition" && group === "other" && !root) {
groups.trigger = {};
}
const groups = this._getGroups(type, group);

const result = Object.entries(groups).map(([key, options]) =>
this._convertToItem(key, options, type, localize)
Expand Down Expand Up @@ -459,7 +456,6 @@ class DialogAddAutomationElement extends LitElement implements HassDialog {
const items = this._filter
? this._getFilteredItems(
this._params.type,
this._params.root,
this._group,
this._filter,
this.hass.localize,
Expand All @@ -468,7 +464,6 @@ class DialogAddAutomationElement extends LitElement implements HassDialog {
)
: this._getGroupItems(
this._params.type,
this._params.root,
this._group,
this._domains,
this.hass.localize,
Expand Down Expand Up @@ -537,7 +532,7 @@ class DialogAddAutomationElement extends LitElement implements HassDialog {
rootTabbable
style=${styleMap({
width: this._width ? `${this._width}px` : "auto",
height: this._height ? `${Math.min(670, this._height)}px` : "auto",
height: this._height ? `${Math.min(468, this._height)}px` : "auto",
})}
>
${this._params.clipboardItem &&
Expand Down Expand Up @@ -660,7 +655,7 @@ class DialogAddAutomationElement extends LitElement implements HassDialog {
width: 24px;
}
mwc-list {
max-height: 670px;
max-height: 468px;
max-width: 100vw;
}
search-input {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ export default class HaAutomationCondition extends LitElement {
showAddAutomationElementDialog(this, {
type: "condition",
add: this._addCondition,
root: !this.nested,
clipboardItem: this._clipboard?.condition?.condition,
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export interface AddAutomationElementDialogParams {
type: "trigger" | "condition" | "action";
add: (key: string) => void;
clipboardItem: string | undefined;
root?: boolean;
group?: string;
}
const loadDialog = () => import("./add-automation-element-dialog");
Expand Down

0 comments on commit 29fefa1

Please sign in to comment.