From 029185cbbc89fdfdb64df491be7a268c727e7fdc Mon Sep 17 00:00:00 2001
From: Jan-Philipp Benecke
Date: Mon, 12 Feb 2024 20:55:56 +0100
Subject: [PATCH] Rename dialog and re-add button
---
.../integrations/dialog-add-integration.ts | 4 +--
....ts => dialog-single-config-entry-only.ts} | 14 +++++-----
.../ha-config-integration-page.ts | 28 +++++++++++--------
.../ha-config-integrations-dashboard.ts | 4 +--
.../show-add-integration-dialog.ts | 14 ++++------
5 files changed, 34 insertions(+), 30 deletions(-)
rename src/panels/config/integrations/{dialog-single-instance-only.ts => dialog-single-config-entry-only.ts} (78%)
diff --git a/src/panels/config/integrations/dialog-add-integration.ts b/src/panels/config/integrations/dialog-add-integration.ts
index 722cc7b5a4e4..afb176a4aa8f 100644
--- a/src/panels/config/integrations/dialog-add-integration.ts
+++ b/src/panels/config/integrations/dialog-add-integration.ts
@@ -52,7 +52,7 @@ import "./ha-domain-integrations";
import "./ha-integration-list-item";
import {
AddIntegrationDialogParams,
- showSingleInstanceOnlyDialog,
+ showSingleConfigEntryOnlyDialog,
showYamlIntegrationDialog,
} from "./show-add-integration-dialog";
import { getConfigEntries } from "../../../data/config_entries";
@@ -582,7 +582,7 @@ class AddIntegrationDialog extends LitElement {
});
if (configEntries.length > 0) {
this.closeDialog();
- showSingleInstanceOnlyDialog(this, { integration });
+ showSingleConfigEntryOnlyDialog(this, { name: integration.name });
return;
}
}
diff --git a/src/panels/config/integrations/dialog-single-instance-only.ts b/src/panels/config/integrations/dialog-single-config-entry-only.ts
similarity index 78%
rename from src/panels/config/integrations/dialog-single-instance-only.ts
rename to src/panels/config/integrations/dialog-single-config-entry-only.ts
index 4b985696d17f..bd20f8924038 100644
--- a/src/panels/config/integrations/dialog-single-instance-only.ts
+++ b/src/panels/config/integrations/dialog-single-config-entry-only.ts
@@ -3,15 +3,15 @@ import { css, CSSResultGroup, html, LitElement, nothing } from "lit";
import { customElement, property, state } from "lit/decorators";
import { fireEvent } from "../../../common/dom/fire_event";
import { HomeAssistant } from "../../../types";
-import { SingleInstanceOnlyDialogParams } from "./show-add-integration-dialog";
+import { SingleConfigEntryOnlyDialogParams } from "./show-add-integration-dialog";
-@customElement("dialog-single-instance-only")
-export class DialogSingleInstanceOnly extends LitElement {
+@customElement("dialog-single-config-entry-only")
+export class DialogSingleConfigEntryOnly extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;
- @state() private _params?: SingleInstanceOnlyDialogParams;
+ @state() private _params?: SingleConfigEntryOnlyDialogParams;
- public showDialog(params: SingleInstanceOnlyDialogParams): void {
+ public showDialog(params: SingleConfigEntryOnlyDialogParams): void {
this._params = params;
}
@@ -36,7 +36,7 @@ export class DialogSingleInstanceOnly extends LitElement {
${this.hass.localize(
"ui.panel.config.integrations.config_flow.single_config_entry",
{
- integration_name: this._params.integration.name,
+ integration_name: this._params.name,
}
)}
@@ -71,6 +71,6 @@ export class DialogSingleInstanceOnly extends LitElement {
declare global {
interface HTMLElementTagNameMap {
- "dialog-single-instance-only": DialogSingleInstanceOnly;
+ "dialog-single-config-entry-only": DialogSingleConfigEntryOnly;
}
}
diff --git a/src/panels/config/integrations/ha-config-integration-page.ts b/src/panels/config/integrations/ha-config-integration-page.ts
index a0c6edf1a895..a706efedd01a 100644
--- a/src/panels/config/integrations/ha-config-integration-page.ts
+++ b/src/panels/config/integrations/ha-config-integration-page.ts
@@ -37,6 +37,7 @@ import {
import { customElement, property, state } from "lit/decorators";
import { classMap } from "lit/directives/class-map";
import memoizeOne from "memoize-one";
+import { ifDefined } from "lit/directives/if-defined";
import { isComponentLoaded } from "../../../common/config/is_component_loaded";
import { isDevVersion } from "../../../common/config/version";
import { shouldHandleRequestSelectedEvent } from "../../../common/mwc/handle-request-selected-event";
@@ -242,6 +243,8 @@ class HaConfigIntegrationPage extends SubscribeMixin(LitElement) {
const entities = this._getEntities(configEntries, this._entities);
const services = !devices.some((device) => device.entry_type !== "service");
+ const single_config_entry_only =
+ this._manifest?.single_config_entry && configEntries.length > 0;
return html`
this._renderConfigEntry(item))}
- ${this._manifest?.single_config_entry &&
- this.configEntries.length > 0
+
+ ${this._manifest?.integration_type
+ ? this.hass.localize(
+ `ui.panel.config.integrations.integration_page.add_${this._manifest.integration_type}`
+ )
+ : this.hass.localize(
+ `ui.panel.config.integrations.integration_page.add_entry`
+ )}
+
+ ${single_config_entry_only
? html`${this.hass.localize(
`ui.panel.config.integrations.integration_page.single_config_entry_only`
)}`
- : html`
- ${this._manifest?.integration_type
- ? this.hass.localize(
- `ui.panel.config.integrations.integration_page.add_${this._manifest.integration_type}`
- )
- : this.hass.localize(
- `ui.panel.config.integrations.integration_page.add_entry`
- )}
- `}
+ : ``}
diff --git a/src/panels/config/integrations/ha-config-integrations-dashboard.ts b/src/panels/config/integrations/ha-config-integrations-dashboard.ts
index 39cdf7e0eccd..a067b05f9282 100644
--- a/src/panels/config/integrations/ha-config-integrations-dashboard.ts
+++ b/src/panels/config/integrations/ha-config-integrations-dashboard.ts
@@ -69,7 +69,7 @@ import type { HaIntegrationCard } from "./ha-integration-card";
import "./ha-integration-overflow-menu";
import {
showAddIntegrationDialog,
- showSingleInstanceOnlyDialog,
+ showSingleConfigEntryOnlyDialog,
} from "./show-add-integration-dialog";
import "./ha-disabled-config-entry-card";
import { caseInsensitiveStringCompare } from "../../../common/string/compare";
@@ -664,7 +664,7 @@ class HaConfigIntegrationsDashboard extends SubscribeMixin(LitElement) {
if (integration.single_config_entry) {
const configEntries = await getConfigEntries(this.hass, { domain });
if (configEntries.length > 0) {
- showSingleInstanceOnlyDialog(this, { integration });
+ showSingleConfigEntryOnlyDialog(this, { name: integration.name });
return;
}
}
diff --git a/src/panels/config/integrations/show-add-integration-dialog.ts b/src/panels/config/integrations/show-add-integration-dialog.ts
index 3a01ce403a36..bdb05c8c6716 100644
--- a/src/panels/config/integrations/show-add-integration-dialog.ts
+++ b/src/panels/config/integrations/show-add-integration-dialog.ts
@@ -1,7 +1,5 @@
import { fireEvent } from "../../../common/dom/fire_event";
import { IntegrationManifest } from "../../../data/integration";
-import { IntegrationListItem } from "./dialog-add-integration";
-import { Integration } from "../../../data/integrations";
export interface AddIntegrationDialogParams {
brand?: string;
@@ -13,8 +11,8 @@ export interface YamlIntegrationDialogParams {
manifest: IntegrationManifest;
}
-export interface SingleInstanceOnlyDialogParams {
- integration: IntegrationListItem | Integration;
+export interface SingleConfigEntryOnlyDialogParams {
+ name: string;
}
export const showAddIntegrationDialog = (
@@ -39,13 +37,13 @@ export const showYamlIntegrationDialog = (
});
};
-export const showSingleInstanceOnlyDialog = (
+export const showSingleConfigEntryOnlyDialog = (
element: HTMLElement,
- dialogParams?: SingleInstanceOnlyDialogParams
+ dialogParams?: SingleConfigEntryOnlyDialogParams
): void => {
fireEvent(element, "show-dialog", {
- dialogTag: "dialog-single-instance-only",
- dialogImport: () => import("./dialog-single-instance-only"),
+ dialogTag: "dialog-single-config-entry-only",
+ dialogImport: () => import("./dialog-single-config-entry-only"),
dialogParams: dialogParams,
});
};