mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-23 17:26:42 +00:00
Open Application Credentials from integration configuration flow (#12708)
This commit is contained in:
parent
067c2fdfa8
commit
e1fd7244a5
@ -309,7 +309,7 @@ class DataEntryFlowDialog extends LitElement {
|
|||||||
: this._step.type === "abort"
|
: this._step.type === "abort"
|
||||||
? html`
|
? html`
|
||||||
<step-flow-abort
|
<step-flow-abort
|
||||||
.flowConfig=${this._params.flowConfig}
|
.params=${this._params}
|
||||||
.step=${this._step}
|
.step=${this._step}
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.domain=${this._step.handler}
|
.domain=${this._step.handler}
|
||||||
|
@ -131,6 +131,7 @@ export interface DataEntryFlowDialogParams {
|
|||||||
}) => void;
|
}) => void;
|
||||||
flowConfig: FlowConfig;
|
flowConfig: FlowConfig;
|
||||||
showAdvanced?: boolean;
|
showAdvanced?: boolean;
|
||||||
|
dialogParentElement?: HTMLElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const loadDataEntryFlowDialog = () => import("./dialog-data-entry-flow");
|
export const loadDataEntryFlowDialog = () => import("./dialog-data-entry-flow");
|
||||||
@ -146,6 +147,7 @@ export const showFlowDialog = (
|
|||||||
dialogParams: {
|
dialogParams: {
|
||||||
...dialogParams,
|
...dialogParams,
|
||||||
flowConfig,
|
flowConfig,
|
||||||
|
dialogParentElement: element,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -1,15 +1,25 @@
|
|||||||
import "@material/mwc-button";
|
import "@material/mwc-button";
|
||||||
import { CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
import {
|
||||||
|
CSSResultGroup,
|
||||||
|
html,
|
||||||
|
LitElement,
|
||||||
|
TemplateResult,
|
||||||
|
PropertyValues,
|
||||||
|
} from "lit";
|
||||||
import { customElement, property } from "lit/decorators";
|
import { customElement, property } from "lit/decorators";
|
||||||
import { fireEvent } from "../../common/dom/fire_event";
|
import { fireEvent } from "../../common/dom/fire_event";
|
||||||
import { DataEntryFlowStepAbort } from "../../data/data_entry_flow";
|
import { DataEntryFlowStepAbort } from "../../data/data_entry_flow";
|
||||||
import { HomeAssistant } from "../../types";
|
import { HomeAssistant } from "../../types";
|
||||||
import { FlowConfig } from "./show-dialog-data-entry-flow";
|
import { showAddApplicationCredentialDialog } from "../../panels/config/application_credentials/show-dialog-add-application-credential";
|
||||||
import { configFlowContentStyles } from "./styles";
|
import { configFlowContentStyles } from "./styles";
|
||||||
|
import { showConfirmationDialog } from "../generic/show-dialog-box";
|
||||||
|
import { domainToName } from "../../data/integration";
|
||||||
|
import { DataEntryFlowDialogParams } from "./show-dialog-data-entry-flow";
|
||||||
|
import { showConfigFlowDialog } from "./show-dialog-config-flow";
|
||||||
|
|
||||||
@customElement("step-flow-abort")
|
@customElement("step-flow-abort")
|
||||||
class StepFlowAbort extends LitElement {
|
class StepFlowAbort extends LitElement {
|
||||||
@property({ attribute: false }) public flowConfig!: FlowConfig;
|
@property({ attribute: false }) public params!: DataEntryFlowDialogParams;
|
||||||
|
|
||||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||||
|
|
||||||
@ -17,11 +27,21 @@ class StepFlowAbort extends LitElement {
|
|||||||
|
|
||||||
@property({ attribute: false }) public domain!: string;
|
@property({ attribute: false }) public domain!: string;
|
||||||
|
|
||||||
|
protected firstUpdated(changed: PropertyValues) {
|
||||||
|
super.firstUpdated(changed);
|
||||||
|
if (this.step.reason === "missing_credentials") {
|
||||||
|
this._handleMissingCreds();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult {
|
||||||
|
if (this.step.reason === "missing_credentials") {
|
||||||
|
return html``;
|
||||||
|
}
|
||||||
return html`
|
return html`
|
||||||
<h2>${this.hass.localize(`component.${this.domain}.title`)}</h2>
|
<h2>${this.hass.localize(`component.${this.domain}.title`)}</h2>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
${this.flowConfig.renderAbortDescription(this.hass, this.step)}
|
${this.params.flowConfig.renderAbortDescription(this.hass, this.step)}
|
||||||
</div>
|
</div>
|
||||||
<div class="buttons">
|
<div class="buttons">
|
||||||
<mwc-button @click=${this._flowDone}
|
<mwc-button @click=${this._flowDone}
|
||||||
@ -33,6 +53,32 @@ class StepFlowAbort extends LitElement {
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async _handleMissingCreds() {
|
||||||
|
const confirm = await showConfirmationDialog(this, {
|
||||||
|
title: this.hass.localize(
|
||||||
|
"ui.panel.config.integrations.config_flow.missing_credentials",
|
||||||
|
{
|
||||||
|
integration: domainToName(this.hass.localize, this.domain),
|
||||||
|
}
|
||||||
|
),
|
||||||
|
});
|
||||||
|
this._flowDone();
|
||||||
|
if (!confirm) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Prompt to enter credentials and restart integration setup
|
||||||
|
showAddApplicationCredentialDialog(this.params.dialogParentElement!, {
|
||||||
|
selectedDomain: this.domain,
|
||||||
|
applicationCredentialAddedCallback: () => {
|
||||||
|
showConfigFlowDialog(this.params.dialogParentElement!, {
|
||||||
|
dialogClosedCallback: this.params.dialogClosedCallback,
|
||||||
|
startFlowHandler: this.domain,
|
||||||
|
showAdvanced: this.hass.userData?.showAdvanced,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private _flowDone(): void {
|
private _flowDone(): void {
|
||||||
fireEvent(this, "flow-update", { step: undefined });
|
fireEvent(this, "flow-update", { step: undefined });
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,8 @@ export class DialogAddApplicationCredential extends LitElement {
|
|||||||
|
|
||||||
public showDialog(params: AddApplicationCredentialDialogParams) {
|
public showDialog(params: AddApplicationCredentialDialogParams) {
|
||||||
this._params = params;
|
this._params = params;
|
||||||
this._domain = "";
|
this._domain =
|
||||||
|
params.selectedDomain !== undefined ? params.selectedDomain : "";
|
||||||
this._name = "";
|
this._name = "";
|
||||||
this._clientId = "";
|
this._clientId = "";
|
||||||
this._clientSecret = "";
|
this._clientSecret = "";
|
||||||
@ -75,7 +76,7 @@ export class DialogAddApplicationCredential extends LitElement {
|
|||||||
return html`
|
return html`
|
||||||
<ha-dialog
|
<ha-dialog
|
||||||
open
|
open
|
||||||
@closed=${this.closeDialog}
|
@closed=${this._abortDialog}
|
||||||
scrimClickAction
|
scrimClickAction
|
||||||
escapeKeyAction
|
escapeKeyAction
|
||||||
.heading=${createCloseHeading(
|
.heading=${createCloseHeading(
|
||||||
@ -90,6 +91,7 @@ export class DialogAddApplicationCredential extends LitElement {
|
|||||||
<ha-combo-box
|
<ha-combo-box
|
||||||
name="domain"
|
name="domain"
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
|
.disabled=${!!this._params.selectedDomain}
|
||||||
.label=${this.hass.localize(
|
.label=${this.hass.localize(
|
||||||
"ui.panel.config.application_credentials.editor.domain"
|
"ui.panel.config.application_credentials.editor.domain"
|
||||||
)}
|
)}
|
||||||
@ -181,6 +183,13 @@ export class DialogAddApplicationCredential extends LitElement {
|
|||||||
this[`_${name}`] = value;
|
this[`_${name}`] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _abortDialog() {
|
||||||
|
if (this._params && this._params.dialogAbortedCallback) {
|
||||||
|
this._params.dialogAbortedCallback();
|
||||||
|
}
|
||||||
|
this.closeDialog();
|
||||||
|
}
|
||||||
|
|
||||||
private async _createApplicationCredential(ev) {
|
private async _createApplicationCredential(ev) {
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
if (!this._domain || !this._clientId || !this._clientSecret) {
|
if (!this._domain || !this._clientId || !this._clientSecret) {
|
||||||
|
@ -5,6 +5,8 @@ export interface AddApplicationCredentialDialogParams {
|
|||||||
applicationCredentialAddedCallback: (
|
applicationCredentialAddedCallback: (
|
||||||
applicationCredential: ApplicationCredential
|
applicationCredential: ApplicationCredential
|
||||||
) => void;
|
) => void;
|
||||||
|
dialogAbortedCallback?: () => void;
|
||||||
|
selectedDomain?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const loadAddApplicationCredentialDialog = () =>
|
export const loadAddApplicationCredentialDialog = () =>
|
||||||
|
@ -2825,7 +2825,8 @@
|
|||||||
},
|
},
|
||||||
"error": "Error",
|
"error": "Error",
|
||||||
"could_not_load": "Config flow could not be loaded",
|
"could_not_load": "Config flow could not be loaded",
|
||||||
"not_loaded": "The integration could not be loaded, try to restart Home Assistant."
|
"not_loaded": "The integration could not be loaded, try to restart Home Assistant.",
|
||||||
|
"missing_credentials": "Setting up {integration} requires configuring application credentials. Do you want to do that now?"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"users": {
|
"users": {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user