mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-21 08:16:36 +00:00
Add application credentials description placeholder (#12869)
This commit is contained in:
parent
4ad49ef07f
commit
5baa975632
@ -1,7 +1,11 @@
|
|||||||
import { HomeAssistant } from "../types";
|
import { HomeAssistant } from "../types";
|
||||||
|
|
||||||
|
export interface ApplicationCredentialsDomainConfig {
|
||||||
|
description_placeholders: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface ApplicationCredentialsConfig {
|
export interface ApplicationCredentialsConfig {
|
||||||
domains: string[];
|
integrations: Record<string, ApplicationCredentialsDomainConfig>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ApplicationCredential {
|
export interface ApplicationCredential {
|
||||||
|
@ -38,7 +38,8 @@ export type TranslationCategory =
|
|||||||
| "device_automation"
|
| "device_automation"
|
||||||
| "mfa_setup"
|
| "mfa_setup"
|
||||||
| "system_health"
|
| "system_health"
|
||||||
| "device_class";
|
| "device_class"
|
||||||
|
| "application_credentials";
|
||||||
|
|
||||||
export const fetchTranslationPreferences = (hass: HomeAssistant) =>
|
export const fetchTranslationPreferences = (hass: HomeAssistant) =>
|
||||||
fetchFrontendUserData(hass.connection, "language");
|
fetchFrontendUserData(hass.connection, "language");
|
||||||
|
@ -7,10 +7,12 @@ import { fireEvent } from "../../../common/dom/fire_event";
|
|||||||
import "../../../components/ha-circular-progress";
|
import "../../../components/ha-circular-progress";
|
||||||
import "../../../components/ha-combo-box";
|
import "../../../components/ha-combo-box";
|
||||||
import { createCloseHeading } from "../../../components/ha-dialog";
|
import { createCloseHeading } from "../../../components/ha-dialog";
|
||||||
|
import "../../../components/ha-markdown";
|
||||||
import "../../../components/ha-textfield";
|
import "../../../components/ha-textfield";
|
||||||
import {
|
import {
|
||||||
fetchApplicationCredentialsConfig,
|
fetchApplicationCredentialsConfig,
|
||||||
createApplicationCredential,
|
createApplicationCredential,
|
||||||
|
ApplicationCredentialsConfig,
|
||||||
ApplicationCredential,
|
ApplicationCredential,
|
||||||
} from "../../../data/application_credential";
|
} from "../../../data/application_credential";
|
||||||
import { domainToName } from "../../../data/integration";
|
import { domainToName } from "../../../data/integration";
|
||||||
@ -42,17 +44,22 @@ export class DialogAddApplicationCredential extends LitElement {
|
|||||||
|
|
||||||
@state() private _name?: string;
|
@state() private _name?: string;
|
||||||
|
|
||||||
|
@state() private _description?: string;
|
||||||
|
|
||||||
@state() private _clientId?: string;
|
@state() private _clientId?: string;
|
||||||
|
|
||||||
@state() private _clientSecret?: string;
|
@state() private _clientSecret?: string;
|
||||||
|
|
||||||
@state() private _domains?: Domain[];
|
@state() private _domains?: Domain[];
|
||||||
|
|
||||||
|
@state() private _config?: ApplicationCredentialsConfig;
|
||||||
|
|
||||||
public showDialog(params: AddApplicationCredentialDialogParams) {
|
public showDialog(params: AddApplicationCredentialDialogParams) {
|
||||||
this._params = params;
|
this._params = params;
|
||||||
this._domain =
|
this._domain =
|
||||||
params.selectedDomain !== undefined ? params.selectedDomain : "";
|
params.selectedDomain !== undefined ? params.selectedDomain : "";
|
||||||
this._name = "";
|
this._name = "";
|
||||||
|
this._description = "";
|
||||||
this._clientId = "";
|
this._clientId = "";
|
||||||
this._clientSecret = "";
|
this._clientSecret = "";
|
||||||
this._error = undefined;
|
this._error = undefined;
|
||||||
@ -61,11 +68,12 @@ export class DialogAddApplicationCredential extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async _fetchConfig() {
|
private async _fetchConfig() {
|
||||||
const config = await fetchApplicationCredentialsConfig(this.hass);
|
this._config = await fetchApplicationCredentialsConfig(this.hass);
|
||||||
this._domains = config.domains.map((domain) => ({
|
this._domains = Object.keys(this._config.integrations).map((domain) => ({
|
||||||
id: domain,
|
id: domain,
|
||||||
name: domainToName(this.hass.localize, domain),
|
name: domainToName(this.hass.localize, domain),
|
||||||
}));
|
}));
|
||||||
|
this.hass.loadBackendTranslation("application_credentials");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult {
|
||||||
@ -103,6 +111,12 @@ export class DialogAddApplicationCredential extends LitElement {
|
|||||||
required
|
required
|
||||||
@value-changed=${this._handleDomainPicked}
|
@value-changed=${this._handleDomainPicked}
|
||||||
></ha-combo-box>
|
></ha-combo-box>
|
||||||
|
${this._description
|
||||||
|
? html`<ha-markdown
|
||||||
|
breaks
|
||||||
|
.content=${this._description}
|
||||||
|
></ha-markdown>`
|
||||||
|
: ""}
|
||||||
<ha-textfield
|
<ha-textfield
|
||||||
class="name"
|
class="name"
|
||||||
name="name"
|
name="name"
|
||||||
@ -171,6 +185,11 @@ export class DialogAddApplicationCredential extends LitElement {
|
|||||||
private async _handleDomainPicked(ev: CustomEvent) {
|
private async _handleDomainPicked(ev: CustomEvent) {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
this._domain = ev.detail.value;
|
this._domain = ev.detail.value;
|
||||||
|
const info = this._config!.integrations[this._domain!];
|
||||||
|
this._description = this.hass.localize(
|
||||||
|
`component.${this._domain}.application_credentials.description`,
|
||||||
|
info.description_placeholders
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private _handleValueChanged(ev: CustomEvent) {
|
private _handleValueChanged(ev: CustomEvent) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user