Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions src/panels/config/entities/ha-config-entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export class HaConfigEntities extends SubscribeMixin(LitElement) {
@property() private _filter = "";
@property() private _selectedEntities: string[] = [];
@query("ha-data-table") private _dataTable!: HaDataTable;
private getDialog?: () => DialogEntityRegistryDetail | undefined;

private _columns = memoize(
(narrow, _language): DataTableColumnContainer => {
Expand Down Expand Up @@ -206,14 +207,14 @@ export class HaConfigEntities extends SubscribeMixin(LitElement) {

public disconnectedCallback() {
super.disconnectedCallback();
const dialog = document
.querySelector("home-assistant")!
.shadowRoot!.querySelector("dialog-entity-registry-detail") as
| DialogEntityRegistryDetail
| undefined;
if (dialog) {
dialog.closeDialog();
if (!this.getDialog) {
return;
}
const dialog = this.getDialog();
if (!dialog) {
return;
}
dialog.closeDialog();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that we should just return a closeDialog function from the show function instead of a getDialog function. By exposing getDialog, the user still needs to know about the implementation details? maybe that's ok… I dunno.

}

protected render(): TemplateResult | void {
Expand Down Expand Up @@ -482,7 +483,7 @@ export class HaConfigEntities extends SubscribeMixin(LitElement) {
if (!entry) {
return;
}
showEntityRegistryDetailDialog(this, {
this.getDialog = showEntityRegistryDetailDialog(this, {
entry,
});
}
Expand Down
12 changes: 11 additions & 1 deletion src/panels/config/entities/show-dialog-entity-registry-detail.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { fireEvent } from "../../../common/dom/fire_event";
import { EntityRegistryEntry } from "../../../data/entity_registry";
import { DialogEntityRegistryDetail } from "./dialog-entity-registry-detail";

export interface EntityRegistryDetailDialogParams {
entry: EntityRegistryEntry;
Expand All @@ -10,13 +11,22 @@ export const loadEntityRegistryDetailDialog = () =>
/* webpackChunkName: "entity-registry-detail-dialog" */ "./dialog-entity-registry-detail"
);

const getDialog = () => {
return document
.querySelector("home-assistant")!
.shadowRoot!.querySelector("dialog-entity-registry-detail") as
| DialogEntityRegistryDetail
| undefined;
};

export const showEntityRegistryDetailDialog = (
element: HTMLElement,
systemLogDetailParams: EntityRegistryDetailDialogParams
): void => {
): (() => DialogEntityRegistryDetail | undefined) => {
fireEvent(element, "show-dialog", {
dialogTag: "dialog-entity-registry-detail",
dialogImport: loadEntityRegistryDetailDialog,
dialogParams: systemLogDetailParams,
});
return getDialog;
};