Compare commits

..
2 Commits
Author SHA1 Message Date
Petar Petrov 921fd35aad Keep bottom sheet position when refreshing the YAML sidebar 2026-12-05 15:40:49 +02:00
Petar Petrov 1566f37f85 Refresh the automation sidebar when rows change
- Update the open sidebar without reopening it
- Recreate YAML editors when refreshed config requires it
2026-12-05 15:34:10 +02:00
12 changed files with 102 additions and 37 deletions

No files matched your search

@@ -303,7 +303,7 @@ export default class HaAutomationActionRow extends LitElement {
this.optionsInSidebar &&
this.action !== this._sidebarAction
) {
this.openSidebar();
this._refreshSidebar();
}
}
@@ -1276,12 +1276,10 @@ export default class HaAutomationActionRow extends LitElement {
this._isNew = true;
}
public openSidebar(action?: Action): void {
const sidebarAction = action ?? this.action;
this._sidebarAction = sidebarAction;
private _buildSidebarConfig(sidebarAction: Action): ActionSidebarConfig {
const actionType = getAutomationActionType(sidebarAction);
fireEvent(this, "open-sidebar", {
return {
type: "action",
save: (value) => {
this._sidebarAction = value;
@@ -1323,7 +1321,19 @@ export default class HaAutomationActionRow extends LitElement {
},
uiSupported: actionType ? this._uiSupported(actionType) : false,
yamlMode: this._yamlMode,
} satisfies ActionSidebarConfig);
};
}
private _refreshSidebar(action?: Action): void {
const sidebarAction = action ?? this.action;
this._sidebarAction = sidebarAction;
fireEvent(this, "refresh-sidebar", this._buildSidebarConfig(sidebarAction));
}
public openSidebar(action?: Action): void {
const sidebarAction = action ?? this.action;
this._sidebarAction = sidebarAction;
fireEvent(this, "open-sidebar", this._buildSidebarConfig(sidebarAction));
this._selected = true;
this._collapsed = false;
@@ -617,7 +617,7 @@ export default class HaAutomationConditionRow extends LitElement {
this.optionsInSidebar &&
this.condition !== this._sidebarCondition
) {
this.openSidebar();
this._refreshSidebar();
}
}
@@ -989,10 +989,10 @@ export default class HaAutomationConditionRow extends LitElement {
}
}
public openSidebar(condition?: Condition): void {
const sidebarCondition = condition || this.condition;
this._sidebarCondition = sidebarCondition;
fireEvent(this, "open-sidebar", {
private _buildSidebarConfig(
sidebarCondition: Condition
): ConditionSidebarConfig {
return {
type: "condition",
save: (value) => {
this._sidebarCondition = value;
@@ -1034,7 +1034,23 @@ export default class HaAutomationConditionRow extends LitElement {
),
description: this.conditionDescriptions[sidebarCondition.condition],
yamlMode: this._yamlMode,
} satisfies ConditionSidebarConfig);
};
}
private _refreshSidebar(condition?: Condition): void {
const sidebarCondition = condition || this.condition;
this._sidebarCondition = sidebarCondition;
fireEvent(
this,
"refresh-sidebar",
this._buildSidebarConfig(sidebarCondition)
);
}
public openSidebar(condition?: Condition): void {
const sidebarCondition = condition || this.condition;
this._sidebarCondition = sidebarCondition;
fireEvent(this, "open-sidebar", this._buildSidebarConfig(sidebarCondition));
this._selected = true;
this._collapsed = false;
@@ -52,6 +52,8 @@ export default class HaAutomationSidebar extends LitElement {
@property({ type: Number, attribute: "sidebar-key" })
public sidebarKey?: number;
@property({ attribute: false }) public refreshKey = 0;
@state() private _yamlMode = false;
@state() private _resizing = false;
@@ -157,7 +159,7 @@ export default class HaAutomationSidebar extends LitElement {
.narrow=${this.narrow}
.disabled=${this.disabled}
.yamlMode=${this._yamlMode}
.sidebarKey=${this.sidebarKey}
.sidebarKey=${`${this.sidebarKey}-${this.refreshKey}`}
@toggle-yaml-mode=${this._toggleYamlMode}
@close-sidebar=${this.triggerCloseSidebar}
></ha-automation-sidebar-trigger>
@@ -173,7 +175,7 @@ export default class HaAutomationSidebar extends LitElement {
.narrow=${this.narrow}
.disabled=${this.disabled}
.yamlMode=${this._yamlMode}
.sidebarKey=${this.sidebarKey}
.sidebarKey=${`${this.sidebarKey}-${this.refreshKey}`}
@toggle-yaml-mode=${this._toggleYamlMode}
@close-sidebar=${this.triggerCloseSidebar}
></ha-automation-sidebar-condition>
@@ -190,7 +192,7 @@ export default class HaAutomationSidebar extends LitElement {
.narrow=${this.narrow}
.disabled=${this.disabled}
.yamlMode=${this._yamlMode}
.sidebarKey=${this.sidebarKey}
.sidebarKey=${`${this.sidebarKey}-${this.refreshKey}`}
@toggle-yaml-mode=${this._toggleYamlMode}
@close-sidebar=${this.triggerCloseSidebar}
></ha-automation-sidebar-action>
@@ -206,7 +208,7 @@ export default class HaAutomationSidebar extends LitElement {
.narrow=${this.narrow}
.disabled=${this.disabled}
.yamlMode=${this._yamlMode}
.sidebarKey=${this.sidebarKey}
.sidebarKey=${`${this.sidebarKey}-${this.refreshKey}`}
@toggle-yaml-mode=${this._toggleYamlMode}
@close-sidebar=${this.triggerCloseSidebar}
></ha-automation-sidebar-option>
@@ -222,7 +224,7 @@ export default class HaAutomationSidebar extends LitElement {
.narrow=${this.narrow}
.disabled=${this.disabled}
.yamlMode=${this._yamlMode}
.sidebarKey=${this.sidebarKey}
.sidebarKey=${`${this.sidebarKey}-${this.refreshKey}`}
@toggle-yaml-mode=${this._toggleYamlMode}
@close-sidebar=${this.triggerCloseSidebar}
></ha-automation-sidebar-script-field-selector>
@@ -238,7 +240,7 @@ export default class HaAutomationSidebar extends LitElement {
.narrow=${this.narrow}
.disabled=${this.disabled}
.yamlMode=${this._yamlMode}
.sidebarKey=${this.sidebarKey}
.sidebarKey=${`${this.sidebarKey}-${this.refreshKey}`}
@toggle-yaml-mode=${this._toggleYamlMode}
@close-sidebar=${this.triggerCloseSidebar}
></ha-automation-sidebar-script-field>
@@ -87,6 +87,8 @@ export const ManualEditorMixin = <TConfig>(
@state() protected sidebarKey = 0;
@state() private _sidebarRefreshKey = 0;
@state() private _bottomSheetHeight?: number;
@storage({
@@ -227,7 +229,7 @@ export const ManualEditorMixin = <TConfig>(
: `${this._bottomSheetHeight}px`,
})}
>
<div class="content">
<div class="content" @refresh-sidebar=${this.refreshSidebar}>
<slot name="alerts"></slot>
${this._renderUnownedErrors()} ${this.renderContent()}
</div>
@@ -254,6 +256,7 @@ export const ManualEditorMixin = <TConfig>(
.config=${this.sidebarConfig}
.disabled=${this.disabled}
.sidebarKey=${this.sidebarKey}
.refreshKey=${this._sidebarRefreshKey}
@value-changed=${this.sidebarConfigChanged}
@sidebar-resized=${this.resizeSidebar}
@sidebar-resizing-stopped=${this.stopResizeSidebar}
@@ -308,6 +311,29 @@ export const ManualEditorMixin = <TConfig>(
this.sidebarElement?.focus();
}
protected refreshSidebar(ev: HASSDomEvent<SidebarConfig>) {
ev.stopPropagation();
if (!this.sidebarConfig) {
return;
}
this.sidebarConfig = ev.detail;
this.dispatchEvent(
new CustomEvent("sidebar-config-changed", {
detail: { value: this.sidebarConfig },
bubbles: true,
composed: true,
})
);
// The YAML editor only reads its value when created, so recreate it in YAML mode
if (
("yamlMode" in this.sidebarConfig && this.sidebarConfig.yamlMode) ||
("uiSupported" in this.sidebarConfig && !this.sidebarConfig.uiSupported)
) {
this._sidebarRefreshKey++;
}
}
protected sidebarConfigChanged(ev: ValueChangedEvent<SidebarConfig>) {
ev.stopPropagation();
if (!this.sidebarConfig) {
@@ -510,6 +510,7 @@ declare global {
interface HASSDomEvents {
"open-sidebar": SidebarConfig;
"refresh-sidebar": SidebarConfig;
"request-close-sidebar": undefined;
"close-sidebar": undefined;
}
@@ -166,7 +166,7 @@ export default class HaAutomationOptionRow extends LitElement {
this.optionsInSidebar &&
this.option !== this._sidebarOption
) {
this.openSidebar();
this._refreshSidebar();
}
}
@@ -734,10 +734,8 @@ export default class HaAutomationOptionRow extends LitElement {
this.openSidebar();
}
public openSidebar(option?: Option): void {
const sidebarOption = option ?? this.option;
this._sidebarOption = sidebarOption;
fireEvent(this, "open-sidebar", {
private _buildSidebarConfig(sidebarOption?: Option): OptionSidebarConfig {
return {
type: "option",
save: (value) => {
this._saveYamlOption(value);
@@ -766,7 +764,19 @@ export default class HaAutomationOptionRow extends LitElement {
},
defaultOption: !!this.defaultActions,
note: sidebarOption?.note,
} satisfies OptionSidebarConfig);
};
}
private _refreshSidebar(option?: Option): void {
const sidebarOption = option ?? this.option;
this._sidebarOption = sidebarOption;
fireEvent(this, "refresh-sidebar", this._buildSidebarConfig(sidebarOption));
}
public openSidebar(option?: Option): void {
const sidebarOption = option ?? this.option;
this._sidebarOption = sidebarOption;
fireEvent(this, "open-sidebar", this._buildSidebarConfig(sidebarOption));
this._selected = true;
this._collapsed = false;
@@ -66,8 +66,8 @@ export default class HaAutomationSidebarAction extends LitElement {
@property({ type: Boolean }) public narrow = false;
@property({ type: Number, attribute: "sidebar-key" })
public sidebarKey?: number;
@property({ attribute: "sidebar-key" })
public sidebarKey?: string;
@state() private _warnings?: string[];
@@ -57,8 +57,8 @@ export default class HaAutomationSidebarCondition extends LitElement {
@property({ type: Boolean }) public narrow = false;
@property({ type: Number, attribute: "sidebar-key" })
public sidebarKey?: number;
@property({ attribute: "sidebar-key" })
public sidebarKey?: string;
@state() private _warnings?: string[];
@@ -41,8 +41,8 @@ export default class HaAutomationSidebarOption extends LitElement {
@property({ type: Boolean, attribute: "yaml-mode" }) public yamlMode = false;
@property({ type: Number, attribute: "sidebar-key" })
public sidebarKey?: number;
@property({ attribute: "sidebar-key" })
public sidebarKey?: string;
@state() private _warnings?: string[];
@@ -29,8 +29,8 @@ export default class HaAutomationSidebarScriptFieldSelector extends LitElement {
@property({ type: Boolean }) public narrow = false;
@property({ type: Number, attribute: "sidebar-key" })
public sidebarKey?: number;
@property({ attribute: "sidebar-key" })
public sidebarKey?: string;
@state() private _warnings?: string[];
@@ -31,8 +31,8 @@ export default class HaAutomationSidebarScriptField extends LitElement {
@property({ type: Boolean }) public narrow = false;
@property({ type: Number, attribute: "sidebar-key" })
public sidebarKey?: number;
@property({ attribute: "sidebar-key" })
public sidebarKey?: string;
@state() private _warnings?: string[];
@@ -57,8 +57,8 @@ export default class HaAutomationSidebarTrigger extends LitElement {
@property({ type: Boolean }) public narrow = false;
@property({ type: Number, attribute: "sidebar-key" })
public sidebarKey?: number;
@property({ attribute: "sidebar-key" })
public sidebarKey?: string;
@state() private _warnings?: string[];