diff --git a/src/panels/config/automation/ha-automation-picker.ts b/src/panels/config/automation/ha-automation-picker.ts index 2da5c4ec56..ecb40f5b71 100644 --- a/src/panels/config/automation/ha-automation-picker.ts +++ b/src/panels/config/automation/ha-automation-picker.ts @@ -378,7 +378,7 @@ class HaAutomationPicker extends SubscribeMixin(LitElement) { - + ${this.hass.localize("ui.panel.config.category.editor.add")} @@ -414,7 +414,7 @@ class HaAutomationPicker extends SubscribeMixin(LitElement) { `; })} - + ${this.hass.localize("ui.panel.config.labels.add_label")} [] = []; this._selected.forEach((entityId) => { promises.push( @@ -1103,6 +1107,10 @@ class HaAutomationPicker extends SubscribeMixin(LitElement) { private async _handleBulkLabel(ev) { const label = ev.currentTarget.value; const action = ev.currentTarget.action; + this._bulkLabel(label, action); + } + + private async _bulkLabel(label: string, action: "add" | "remove") { const promises: Promise[] = []; this._selected.forEach((entityId) => { promises.push( @@ -1135,17 +1143,28 @@ class HaAutomationPicker extends SubscribeMixin(LitElement) { await Promise.all(promises); } - private _createCategory() { + private async _bulkCreateCategory() { showCategoryRegistryDetailDialog(this, { scope: "automation", - createEntry: (values) => - createCategoryRegistryEntry(this.hass, "automation", values), + createEntry: async (values) => { + const category = await createCategoryRegistryEntry( + this.hass, + "automation", + values + ); + this._bulkAddCategory(category.category_id); + return category; + }, }); } - private _createLabel() { + private _bulkCreateLabel() { showLabelDetailDialog(this, { - createEntry: (values) => createLabelRegistryEntry(this.hass, values), + createEntry: async (values) => { + const label = await createLabelRegistryEntry(this.hass, values); + this._bulkLabel(label.label_id, "add"); + return label; + }, }); } diff --git a/src/panels/config/devices/ha-config-devices-dashboard.ts b/src/panels/config/devices/ha-config-devices-dashboard.ts index ba9630e2fa..f9f2fd16e6 100644 --- a/src/panels/config/devices/ha-config-devices-dashboard.ts +++ b/src/panels/config/devices/ha-config-devices-dashboard.ts @@ -575,7 +575,7 @@ export class HaConfigDeviceDashboard extends SubscribeMixin(LitElement) { `; })} - + ${this.hass.localize("ui.panel.config.labels.add_label")} [] = []; this._selected.forEach((deviceId) => { promises.push( @@ -817,9 +821,13 @@ export class HaConfigDeviceDashboard extends SubscribeMixin(LitElement) { await Promise.all(promises); } - private _createLabel() { + private _bulkCreateLabel() { showLabelDetailDialog(this, { - createEntry: (values) => createLabelRegistryEntry(this.hass, values), + createEntry: async (values) => { + const label = await createLabelRegistryEntry(this.hass, values); + this._bulkLabel(label.label_id, "add"); + return label; + }, }); } diff --git a/src/panels/config/entities/ha-config-entities.ts b/src/panels/config/entities/ha-config-entities.ts index 1ec59d4d14..5a7f5461aa 100644 --- a/src/panels/config/entities/ha-config-entities.ts +++ b/src/panels/config/entities/ha-config-entities.ts @@ -555,7 +555,7 @@ export class HaConfigEntities extends SubscribeMixin(LitElement) { `; })} - + ${this.hass.localize("ui.panel.config.labels.add_label")} [] = []; this._selected.forEach((entityId) => { const entityReg = @@ -1064,6 +1068,16 @@ ${ await Promise.all(promises); } + private _bulkCreateLabel() { + showLabelDetailDialog(this, { + createEntry: async (values) => { + const label = await createLabelRegistryEntry(this.hass, values); + this._bulkLabel(label.label_id, "add"); + return label; + }, + }); + } + private _removeSelected() { const removeableEntities = this._selected.filter((entity) => { const stateObj = this.hass.states[entity]; @@ -1140,12 +1154,6 @@ ${ }); } - private _createLabel() { - showLabelDetailDialog(this, { - createEntry: (values) => createLabelRegistryEntry(this.hass, values), - }); - } - static get styles(): CSSResultGroup { return [ haStyle, diff --git a/src/panels/config/helpers/ha-config-helpers.ts b/src/panels/config/helpers/ha-config-helpers.ts index fa89081415..b32fa20750 100644 --- a/src/panels/config/helpers/ha-config-helpers.ts +++ b/src/panels/config/helpers/ha-config-helpers.ts @@ -443,7 +443,7 @@ export class HaConfigHelpers extends SubscribeMixin(LitElement) { - + ${this.hass.localize("ui.panel.config.category.editor.add")} @@ -478,7 +478,7 @@ export class HaConfigHelpers extends SubscribeMixin(LitElement) { `; })} - + ${this.hass.localize("ui.panel.config.labels.add_label")} @@ -779,6 +779,10 @@ export class HaConfigHelpers extends SubscribeMixin(LitElement) { private async _handleBulkCategory(ev) { const category = ev.currentTarget.value; + this._bulkAddCategory(category); + } + + private async _bulkAddCategory(category: string) { const promises: Promise[] = []; this._selected.forEach((entityId) => { promises.push( @@ -793,6 +797,10 @@ export class HaConfigHelpers extends SubscribeMixin(LitElement) { private async _handleBulkLabel(ev) { const label = ev.currentTarget.value; const action = ev.currentTarget.action; + this._bulkLabel(label, action); + } + + private async _bulkLabel(label: string, action: "add" | "remove") { const promises: Promise[] = []; this._selected.forEach((entityId) => { promises.push( @@ -947,17 +955,28 @@ export class HaConfigHelpers extends SubscribeMixin(LitElement) { showHelperDetailDialog(this, {}); } - private _createCategory() { + private async _bulkCreateCategory() { showCategoryRegistryDetailDialog(this, { scope: "helpers", - createEntry: (values) => - createCategoryRegistryEntry(this.hass, "helpers", values), + createEntry: async (values) => { + const category = await createCategoryRegistryEntry( + this.hass, + "helpers", + values + ); + this._bulkAddCategory(category.category_id); + return category; + }, }); } - private _createLabel() { + private _bulkCreateLabel() { showLabelDetailDialog(this, { - createEntry: (values) => createLabelRegistryEntry(this.hass, values), + createEntry: async (values) => { + const label = await createLabelRegistryEntry(this.hass, values); + this._bulkLabel(label.label_id, "add"); + return label; + }, }); } diff --git a/src/panels/config/scene/ha-scene-dashboard.ts b/src/panels/config/scene/ha-scene-dashboard.ts index ee79904c47..c07d31f7be 100644 --- a/src/panels/config/scene/ha-scene-dashboard.ts +++ b/src/panels/config/scene/ha-scene-dashboard.ts @@ -381,7 +381,7 @@ class HaSceneDashboard extends SubscribeMixin(LitElement) { - + ${this.hass.localize("ui.panel.config.category.editor.add")} @@ -417,7 +417,7 @@ class HaSceneDashboard extends SubscribeMixin(LitElement) { `; })} - + ${this.hass.localize("ui.panel.config.labels.add_label")} [] = []; this._selected.forEach((entityId) => { promises.push( @@ -790,6 +794,10 @@ class HaSceneDashboard extends SubscribeMixin(LitElement) { private async _handleBulkLabel(ev) { const label = ev.currentTarget.value; const action = ev.currentTarget.action; + this._bulkLabel(label, action); + } + + private async _bulkLabel(label: string, action: "add" | "remove") { const promises: Promise[] = []; this._selected.forEach((entityId) => { promises.push( @@ -901,17 +909,28 @@ class HaSceneDashboard extends SubscribeMixin(LitElement) { }); } - private _createCategory() { + private async _bulkCreateCategory() { showCategoryRegistryDetailDialog(this, { scope: "scene", - createEntry: (values) => - createCategoryRegistryEntry(this.hass, "scene", values), + createEntry: async (values) => { + const category = await createCategoryRegistryEntry( + this.hass, + "scene", + values + ); + this._bulkAddCategory(category.category_id); + return category; + }, }); } - private _createLabel() { + private _bulkCreateLabel() { showLabelDetailDialog(this, { - createEntry: (values) => createLabelRegistryEntry(this.hass, values), + createEntry: async (values) => { + const label = await createLabelRegistryEntry(this.hass, values); + this._bulkLabel(label.label_id, "add"); + return label; + }, }); } diff --git a/src/panels/config/script/ha-script-picker.ts b/src/panels/config/script/ha-script-picker.ts index 8e9d5dd566..2e769e8371 100644 --- a/src/panels/config/script/ha-script-picker.ts +++ b/src/panels/config/script/ha-script-picker.ts @@ -393,7 +393,7 @@ class HaScriptPicker extends SubscribeMixin(LitElement) { )} - + ${this.hass.localize("ui.panel.config.category.editor.add")} @@ -429,7 +429,7 @@ class HaScriptPicker extends SubscribeMixin(LitElement) { `; })} - + ${this.hass.localize("ui.panel.config.labels.add_label")} [] = []; this._selected.forEach((entityId) => { promises.push( @@ -859,6 +863,10 @@ class HaScriptPicker extends SubscribeMixin(LitElement) { private async _handleBulkLabel(ev) { const label = ev.currentTarget.value; const action = ev.currentTarget.action; + this._bulkLabel(label, action); + } + + private async _bulkLabel(label: string, action: "add" | "remove") { const promises: Promise[] = []; this._selected.forEach((entityId) => { promises.push( @@ -1017,17 +1025,28 @@ class HaScriptPicker extends SubscribeMixin(LitElement) { } } - private _createCategory() { + private async _bulkCreateCategory() { showCategoryRegistryDetailDialog(this, { scope: "script", - createEntry: (values) => - createCategoryRegistryEntry(this.hass, "script", values), + createEntry: async (values) => { + const category = await createCategoryRegistryEntry( + this.hass, + "script", + values + ); + this._bulkAddCategory(category.category_id); + return category; + }, }); } - private _createLabel() { + private _bulkCreateLabel() { showLabelDetailDialog(this, { - createEntry: (values) => createLabelRegistryEntry(this.hass, values), + createEntry: async (values) => { + const label = await createLabelRegistryEntry(this.hass, values); + this._bulkLabel(label.label_id, "add"); + return label; + }, }); }