mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Update webhook dialog (#13774)
This commit is contained in:
parent
5a5f31b32c
commit
0ba4a07b92
@ -1,18 +1,19 @@
|
|||||||
import "@material/mwc-button";
|
import "@material/mwc-button";
|
||||||
|
import { mdiContentCopy, mdiOpenInNew } from "@mdi/js";
|
||||||
import { css, CSSResultGroup, html, LitElement } from "lit";
|
import { css, CSSResultGroup, html, LitElement } from "lit";
|
||||||
import { query, state } from "lit/decorators";
|
import { query, state } from "lit/decorators";
|
||||||
import { fireEvent } from "../../../../common/dom/fire_event";
|
import { fireEvent } from "../../../../common/dom/fire_event";
|
||||||
import { copyToClipboard } from "../../../../common/util/copy-clipboard";
|
import { copyToClipboard } from "../../../../common/util/copy-clipboard";
|
||||||
import type { HaTextField } from "../../../../components/ha-textfield";
|
import { createCloseHeading } from "../../../../components/ha-dialog";
|
||||||
import "../../../../components/ha-textfield";
|
import "../../../../components/ha-textfield";
|
||||||
|
import type { HaTextField } from "../../../../components/ha-textfield";
|
||||||
import { showConfirmationDialog } from "../../../../dialogs/generic/show-dialog-box";
|
import { showConfirmationDialog } from "../../../../dialogs/generic/show-dialog-box";
|
||||||
import { haStyle, haStyleDialog } from "../../../../resources/styles";
|
import { haStyle, haStyleDialog } from "../../../../resources/styles";
|
||||||
import { HomeAssistant } from "../../../../types";
|
import { HomeAssistant } from "../../../../types";
|
||||||
import { documentationUrl } from "../../../../util/documentation-url";
|
import { documentationUrl } from "../../../../util/documentation-url";
|
||||||
|
import { showToast } from "../../../../util/toast";
|
||||||
import { WebhookDialogParams } from "./show-dialog-manage-cloudhook";
|
import { WebhookDialogParams } from "./show-dialog-manage-cloudhook";
|
||||||
|
|
||||||
const inputLabel = "Public URL – Click to copy to clipboard";
|
|
||||||
|
|
||||||
export class DialogManageCloudhook extends LitElement {
|
export class DialogManageCloudhook extends LitElement {
|
||||||
protected hass?: HomeAssistant;
|
protected hass?: HomeAssistant;
|
||||||
|
|
||||||
@ -44,26 +45,19 @@ export class DialogManageCloudhook extends LitElement {
|
|||||||
return html`
|
return html`
|
||||||
<ha-dialog
|
<ha-dialog
|
||||||
open
|
open
|
||||||
.heading=${this.hass!.localize(
|
hideActions
|
||||||
"ui.panel.config.cloud.dialog_cloudhook.webhook_for",
|
@closed=${this.closeDialog}
|
||||||
"name",
|
.heading=${createCloseHeading(
|
||||||
webhook.name
|
this.hass!,
|
||||||
|
this.hass!.localize(
|
||||||
|
"ui.panel.config.cloud.dialog_cloudhook.webhook_for",
|
||||||
|
{ name: webhook.name }
|
||||||
|
)
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<div>
|
<div>
|
||||||
<p>
|
<p>
|
||||||
${this.hass!.localize(
|
${!cloudhook.managed
|
||||||
"ui.panel.config.cloud.dialog_cloudhook.available_at"
|
|
||||||
)}
|
|
||||||
</p>
|
|
||||||
<ha-textfield
|
|
||||||
.label=${inputLabel}
|
|
||||||
.value=${cloudhook.cloudhook_url}
|
|
||||||
@click=${this._copyClipboard}
|
|
||||||
@blur=${this._restoreLabel}
|
|
||||||
></ha-textfield>
|
|
||||||
<p>
|
|
||||||
${cloudhook.managed
|
|
||||||
? html`
|
? html`
|
||||||
${this.hass!.localize(
|
${this.hass!.localize(
|
||||||
"ui.panel.config.cloud.dialog_cloudhook.managed_by_integration"
|
"ui.panel.config.cloud.dialog_cloudhook.managed_by_integration"
|
||||||
@ -79,7 +73,29 @@ export class DialogManageCloudhook extends LitElement {
|
|||||||
)}</button
|
)}</button
|
||||||
>.
|
>.
|
||||||
`}
|
`}
|
||||||
|
<br />
|
||||||
|
<a href=${docsUrl} target="_blank" rel="noreferrer">
|
||||||
|
${this.hass!.localize(
|
||||||
|
"ui.panel.config.cloud.dialog_cloudhook.view_documentation"
|
||||||
|
)}
|
||||||
|
<ha-svg-icon .path=${mdiOpenInNew}></ha-svg-icon>
|
||||||
|
</a>
|
||||||
</p>
|
</p>
|
||||||
|
<ha-textfield
|
||||||
|
.label=${this.hass!.localize(
|
||||||
|
"ui.panel.config.cloud.dialog_cloudhook.public_url"
|
||||||
|
)}
|
||||||
|
.value=${cloudhook.cloudhook_url}
|
||||||
|
iconTrailing
|
||||||
|
readOnly
|
||||||
|
@click=${this.focusInput}
|
||||||
|
>
|
||||||
|
<ha-icon-button
|
||||||
|
@click=${this._copyUrl}
|
||||||
|
slot="trailingIcon"
|
||||||
|
.path=${mdiContentCopy}
|
||||||
|
></ha-icon-button>
|
||||||
|
</ha-textfield>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<a
|
<a
|
||||||
@ -102,33 +118,40 @@ export class DialogManageCloudhook extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async _disableWebhook() {
|
private async _disableWebhook() {
|
||||||
showConfirmationDialog(this, {
|
const confirmed = await showConfirmationDialog(this, {
|
||||||
|
title: this.hass!.localize(
|
||||||
|
"ui.panel.config.cloud.dialog_cloudhook.confirm_disable_title"
|
||||||
|
),
|
||||||
text: this.hass!.localize(
|
text: this.hass!.localize(
|
||||||
"ui.panel.config.cloud.dialog_cloudhook.confirm_disable"
|
"ui.panel.config.cloud.dialog_cloudhook.confirm_disable_text",
|
||||||
|
{ name: this._params!.webhook.name }
|
||||||
),
|
),
|
||||||
dismissText: this.hass!.localize("ui.common.cancel"),
|
dismissText: this.hass!.localize("ui.common.cancel"),
|
||||||
confirmText: this.hass!.localize("ui.common.disable"),
|
confirmText: this.hass!.localize("ui.common.disable"),
|
||||||
confirm: () => {
|
destructive: true,
|
||||||
this._params!.disableHook();
|
|
||||||
this.closeDialog();
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
}
|
if (confirmed) {
|
||||||
|
this._params!.disableHook();
|
||||||
private _copyClipboard(ev: FocusEvent) {
|
this.closeDialog();
|
||||||
const textField = ev.currentTarget as HaTextField;
|
|
||||||
try {
|
|
||||||
copyToClipboard(textField.value);
|
|
||||||
textField.label = this.hass!.localize(
|
|
||||||
"ui.panel.config.cloud.dialog_cloudhook.copied_to_clipboard"
|
|
||||||
);
|
|
||||||
} catch (err: any) {
|
|
||||||
// Copying failed. Oh no
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private _restoreLabel() {
|
private focusInput(ev) {
|
||||||
this._input.label = inputLabel;
|
const inputElement = ev.currentTarget as HaTextField;
|
||||||
|
inputElement.select();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async _copyUrl(ev): Promise<void> {
|
||||||
|
if (!this.hass) return;
|
||||||
|
ev.stopPropagation();
|
||||||
|
const inputElement = ev.target.parentElement as HaTextField;
|
||||||
|
inputElement.select();
|
||||||
|
const url = this.hass.hassUrl(inputElement.value);
|
||||||
|
|
||||||
|
await copyToClipboard(url);
|
||||||
|
showToast(this, {
|
||||||
|
message: this.hass.localize("ui.common.copied_clipboard"),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static get styles(): CSSResultGroup {
|
static get styles(): CSSResultGroup {
|
||||||
@ -142,12 +165,24 @@ export class DialogManageCloudhook extends LitElement {
|
|||||||
ha-textfield {
|
ha-textfield {
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
ha-textfield > ha-icon-button {
|
||||||
|
--mdc-icon-button-size: 24px;
|
||||||
|
--mdc-icon-size: 18px;
|
||||||
|
}
|
||||||
button.link {
|
button.link {
|
||||||
color: var(--primary-color);
|
color: var(--primary-color);
|
||||||
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
a {
|
a {
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
|
a ha-svg-icon {
|
||||||
|
--mdc-icon-size: 16px;
|
||||||
|
}
|
||||||
|
p {
|
||||||
|
margin-top: 0;
|
||||||
|
margin-bottom: 16px;
|
||||||
|
}
|
||||||
`,
|
`,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -2558,14 +2558,14 @@
|
|||||||
},
|
},
|
||||||
"dialog_cloudhook": {
|
"dialog_cloudhook": {
|
||||||
"webhook_for": "Webhook for {name}",
|
"webhook_for": "Webhook for {name}",
|
||||||
"available_at": "The webhook is available at the following URL:",
|
|
||||||
"managed_by_integration": "This webhook is managed by an integration and cannot be disabled.",
|
"managed_by_integration": "This webhook is managed by an integration and cannot be disabled.",
|
||||||
"info_disable_webhook": "If you no longer want to use this webhook, you can",
|
"info_disable_webhook": "If you no longer want to use this webhook, you can",
|
||||||
"link_disable_webhook": "disable it",
|
"link_disable_webhook": "disable it",
|
||||||
|
"public_url": "Public address",
|
||||||
"view_documentation": "View documentation",
|
"view_documentation": "View documentation",
|
||||||
"close": "Close",
|
"close": "Close",
|
||||||
"confirm_disable": "Are you sure you want to disable this webhook?",
|
"confirm_disable_title": "Disable webhook",
|
||||||
"copied_to_clipboard": "Copied to clipboard"
|
"confirm_disable_text": "Webhook for {name} will be disabled."
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"devices": {
|
"devices": {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user