Skip to content

Commit

Permalink
Rename dialog and re-add button
Browse files Browse the repository at this point in the history
  • Loading branch information
jpbede committed Feb 12, 2024
1 parent 1d4e08e commit 029185c
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 30 deletions.
4 changes: 2 additions & 2 deletions src/panels/config/integrations/dialog-add-integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -582,7 +582,7 @@ class AddIntegrationDialog extends LitElement {
});
if (configEntries.length > 0) {
this.closeDialog();
showSingleInstanceOnlyDialog(this, { integration });
showSingleConfigEntryOnlyDialog(this, { name: integration.name });
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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,
}
)}
</p>
Expand Down Expand Up @@ -71,6 +71,6 @@ export class DialogSingleInstanceOnly extends LitElement {

declare global {
interface HTMLElementTagNameMap {
"dialog-single-instance-only": DialogSingleInstanceOnly;
"dialog-single-config-entry-only": DialogSingleConfigEntryOnly;
}
}
28 changes: 17 additions & 11 deletions src/panels/config/integrations/ha-config-integration-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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`
<hass-subpage
Expand Down Expand Up @@ -504,22 +507,25 @@ class HaConfigIntegrationPage extends SubscribeMixin(LitElement) {
${normalEntries.map((item) => this._renderConfigEntry(item))}
</mwc-list>
<div class="card-actions">
${this._manifest?.single_config_entry &&
this.configEntries.length > 0
<ha-button
@click=${this._addIntegration}
disabled=${ifDefined(single_config_entry_only)}
>
${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`
)}
</ha-button>
${single_config_entry_only
? html`<ha-alert alert-type="info"
>${this.hass.localize(
`ui.panel.config.integrations.integration_page.single_config_entry_only`
)}</ha-alert
>`
: html`<ha-button @click=${this._addIntegration}>
${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`
)}
</ha-button>`}
: ``}
</div>
</ha-card>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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 });

Check failure on line 667 in src/panels/config/integrations/ha-config-integrations-dashboard.ts

View workflow job for this annotation

GitHub Actions / Lint and check format

Type 'string | undefined' is not assignable to type 'string'.
return;
}
}
Expand Down
14 changes: 6 additions & 8 deletions src/panels/config/integrations/show-add-integration-dialog.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -13,8 +11,8 @@ export interface YamlIntegrationDialogParams {
manifest: IntegrationManifest;
}

export interface SingleInstanceOnlyDialogParams {
integration: IntegrationListItem | Integration;
export interface SingleConfigEntryOnlyDialogParams {
name: string;
}

export const showAddIntegrationDialog = (
Expand All @@ -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,
});
};

0 comments on commit 029185c

Please sign in to comment.