Skip to content

Commit

Permalink
20240403.1 (#20380)
Browse files Browse the repository at this point in the history
  • Loading branch information
bramkragten authored Apr 3, 2024
2 parents 962b30a + 00837ac commit 4326519
Show file tree
Hide file tree
Showing 7 changed files with 241 additions and 59 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "home-assistant-frontend"
version = "20240403.0"
version = "20240403.1"
license = {text = "Apache-2.0"}
description = "The Home Assistant frontend"
readme = "README.md"
Expand Down
51 changes: 40 additions & 11 deletions src/panels/config/automation/ha-automation-picker.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { consume } from "@lit-labs/context";
import { ResizeController } from "@lit-labs/observers/resize-controller";
import "@lrnwebcomponents/simple-tooltip/simple-tooltip";
import "@material/web/divider/divider";
import {
Expand Down Expand Up @@ -153,6 +154,10 @@ class HaAutomationPicker extends SubscribeMixin(LitElement) {

@query("#overflow-menu") private _overflowMenu!: HaMenu;

private _sizeController = new ResizeController(this, {
callback: (entries) => entries[0]?.contentRect.width,
});

private _automations = memoizeOne(
(
automations: AutomationEntity[],
Expand Down Expand Up @@ -373,7 +378,7 @@ class HaAutomationPicker extends SubscribeMixin(LitElement) {
</div>
</ha-menu-item>
<md-divider role="separator" tabindex="-1"></md-divider>
<ha-menu-item @click=${this._createCategory}>
<ha-menu-item @click=${this._bulkCreateCategory}>
<div slot="headline">
${this.hass.localize("ui.panel.config.category.editor.add")}
</div>
Expand Down Expand Up @@ -409,12 +414,14 @@ class HaAutomationPicker extends SubscribeMixin(LitElement) {
</ha-menu-item>`;
})}
<md-divider role="separator" tabindex="-1"></md-divider>
<ha-menu-item @click=${this._createLabel}>
<ha-menu-item @click=${this._bulkCreateLabel}>
<div slot="headline">
${this.hass.localize("ui.panel.config.labels.add_label")}
</div></ha-menu-item
>`;

const labelsInOverflow =
(this._sizeController.value && this._sizeController.value < 700) ||
(!this._sizeController.value && this.hass.dockedSidebar === "docked");
return html`
<hass-tabs-subpage-data-table
.hass=${this.hass}
Expand Down Expand Up @@ -538,7 +545,7 @@ class HaAutomationPicker extends SubscribeMixin(LitElement) {
</ha-assist-chip>
${categoryItems}
</ha-button-menu-new>
${this.hass.dockedSidebar === "docked"
${labelsInOverflow
? nothing
: html`<ha-button-menu-new slot="selection-bar">
<ha-assist-chip
Expand Down Expand Up @@ -600,8 +607,8 @@ class HaAutomationPicker extends SubscribeMixin(LitElement) {
: nothing
}
${
this.narrow || this.hass.dockedSidebar === "docked"
? html` <ha-sub-menu>
this.narrow || labelsInOverflow
? html`<ha-sub-menu>
<ha-menu-item slot="item">
<div slot="headline">
${this.hass.localize(
Expand Down Expand Up @@ -1082,6 +1089,10 @@ class HaAutomationPicker extends SubscribeMixin(LitElement) {

private async _handleBulkCategory(ev) {
const category = ev.currentTarget.value;
this._bulkAddCategory(category);
}

private async _bulkAddCategory(category: string) {
const promises: Promise<UpdateEntityRegistryEntryResult>[] = [];
this._selected.forEach((entityId) => {
promises.push(
Expand All @@ -1096,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<UpdateEntityRegistryEntryResult>[] = [];
this._selected.forEach((entityId) => {
promises.push(
Expand Down Expand Up @@ -1128,24 +1143,38 @@ 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;
},
});
}

static get styles(): CSSResultGroup {
return [
haStyle,
css`
:host {
display: block;
}
hass-tabs-subpage-data-table {
--data-table-row-height: 60px;
}
Expand Down
14 changes: 11 additions & 3 deletions src/panels/config/devices/ha-config-devices-dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ export class HaConfigDeviceDashboard extends SubscribeMixin(LitElement) {
</ha-menu-item>`;
})}
<md-divider role="separator" tabindex="-1"></md-divider>
<ha-menu-item @click=${this._createLabel}>
<ha-menu-item @click=${this._bulkCreateLabel}>
<div slot="headline">
${this.hass.localize("ui.panel.config.labels.add_label")}
</div></ha-menu-item
Expand Down Expand Up @@ -801,6 +801,10 @@ export class HaConfigDeviceDashboard 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<DeviceRegistryEntry>[] = [];
this._selected.forEach((deviceId) => {
promises.push(
Expand All @@ -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;
},
});
}

Expand Down
49 changes: 37 additions & 12 deletions src/panels/config/entities/ha-config-entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ import { configSections } from "../ha-panel-config";
import "../integrations/ha-integration-overflow-menu";
import { showAddIntegrationDialog } from "../integrations/show-add-integration-dialog";
import { showLabelDetailDialog } from "../labels/show-dialog-label-detail";
import {
EntitySources,
fetchEntitySourcesWithCache,
} from "../../../data/entity_sources";

export interface StateEntity
extends Omit<EntityRegistryEntry, "id" | "unique_id"> {
Expand Down Expand Up @@ -141,6 +145,8 @@ export class HaConfigEntities extends SubscribeMixin(LitElement) {
@state()
_labels!: LabelRegistryEntry[];

@state() private _entitySources?: EntitySources;

@query("hass-tabs-subpage-data-table", true)
private _dataTable!: HaTabsSubpageDataTable;

Expand Down Expand Up @@ -405,10 +411,12 @@ export class HaConfigEntities extends SubscribeMixin(LitElement) {
const entryIds = entries
.filter((entry) => filter.value!.includes(entry.domain))
.map((entry) => entry.entry_id);

filteredEntities = filteredEntities.filter(
(entity) =>
entity.config_entry_id &&
entryIds.includes(entity.config_entry_id)
filter.value?.includes(entity.platform) ||
(entity.config_entry_id &&
entryIds.includes(entity.config_entry_id))
);
filter.value!.forEach((domain) => filteredDomains.add(domain));
} else if (key === "ha-filter-labels" && filter.value?.length) {
Expand Down Expand Up @@ -547,7 +555,7 @@ export class HaConfigEntities extends SubscribeMixin(LitElement) {
</ha-menu-item>`;
})}
<md-divider role="separator" tabindex="-1"></md-divider>
<ha-menu-item @click=${this._createLabel}>
<ha-menu-item @click=${this._bulkCreateLabel}>
<div slot="headline">
${this.hass.localize("ui.panel.config.labels.add_label")}
</div></ha-menu-item
Expand Down Expand Up @@ -807,6 +815,9 @@ ${
},
};
this._setFiltersFromUrl();
fetchEntitySourcesWithCache(this.hass).then((sources) => {
this._entitySources = sources;
});
}

private _setFiltersFromUrl() {
Expand Down Expand Up @@ -865,14 +876,18 @@ ${
this._filters = {};
}

public willUpdate(changedProps: PropertyValues<this>): void {
public willUpdate(changedProps: PropertyValues): void {
super.willUpdate(changedProps);
const oldHass = changedProps.get("hass");
let changed = false;
if (!this.hass || !this._entities) {
return;
}
if (changedProps.has("hass") || changedProps.has("_entities")) {
if (
changedProps.has("hass") ||
changedProps.has("_entities") ||
changedProps.has("_entitySources")
) {
const stateEntities: StateEntity[] = [];
const regEntityIds = new Set(
this._entities.map((entity) => entity.entity_id)
Expand All @@ -883,14 +898,16 @@ ${
}
if (
!oldHass ||
changedProps.has("_entitySources") ||
this.hass.states[entityId] !== oldHass.states[entityId]
) {
changed = true;
}
stateEntities.push({
name: computeStateName(this.hass.states[entityId]),
entity_id: entityId,
platform: computeDomain(entityId),
platform:
this._entitySources?.[entityId]?.domain || computeDomain(entityId),
disabled_by: null,
hidden_by: null,
area_id: null,
Expand Down Expand Up @@ -1027,6 +1044,10 @@ ${
private async _handleBulkLabel(ev) {
const label = ev.currentTarget.value;
const action = ev.currentTarget.action;
await this._bulkLabel(label, action);
}

private async _bulkLabel(label: string, action: "add" | "remove") {
const promises: Promise<UpdateEntityRegistryEntryResult>[] = [];
this._selected.forEach((entityId) => {
const entityReg =
Expand All @@ -1047,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];
Expand Down Expand Up @@ -1123,12 +1154,6 @@ ${
});
}

private _createLabel() {
showLabelDetailDialog(this, {
createEntry: (values) => createLabelRegistryEntry(this.hass, values),
});
}

static get styles(): CSSResultGroup {
return [
haStyle,
Expand Down
Loading

0 comments on commit 4326519

Please sign in to comment.