Allow sharing blueprints (#8565)

This commit is contained in:
Paulus Schoutsen 2021-03-06 05:19:56 -08:00 committed by GitHub
parent 35f776284b
commit d784a30d42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 1 deletions

View File

@ -1,5 +1,11 @@
import "@material/mwc-icon-button";
import { mdiDelete, mdiDownload, mdiHelpCircle, mdiRobot } from "@mdi/js";
import {
mdiDelete,
mdiDownload,
mdiHelpCircle,
mdiRobot,
mdiShareVariant,
} from "@mdi/js";
import "@polymer/paper-tooltip/paper-tooltip";
import {
CSSResult,
@ -140,6 +146,24 @@ class HaBlueprintOverview extends LitElement {
)}
</mwc-button>`,
},
share: {
title: "",
type: "icon-button",
template: (_, blueprint: any) =>
blueprint.error
? ""
: html`<mwc-icon-button
.blueprint=${blueprint}
.disabled=${!blueprint.source_url}
.label=${this.hass.localize(
blueprint.source_url
? "ui.panel.config.blueprint.overview.share_blueprint"
: "ui.panel.config.blueprint.overview.share_blueprint_no_url"
)}
@click=${(ev) => this._share(ev)}
><ha-svg-icon .path=${mdiShareVariant}></ha-svg-icon
></mwc-icon-button>`,
},
delete: {
title: "",
type: "icon-button",
@ -262,6 +286,16 @@ class HaBlueprintOverview extends LitElement {
createNewFunctions[blueprint.domain](this, blueprint);
}
private _share(ev) {
const blueprint = ev.currentTarget.blueprint;
const params = new URLSearchParams();
params.append("redirect", "blueprint_import");
params.append("blueprint_url", blueprint.source_url);
window.open(
`https://my.home-assistant.io/create-link/?${params.toString()}`
);
}
private async _delete(ev) {
const blueprint = ev.currentTarget.blueprint;
if (

View File

@ -1531,6 +1531,8 @@
"add_blueprint": "Import blueprint",
"use_blueprint": "Create automation",
"delete_blueprint": "Delete blueprint",
"share_blueprint": "Share blueprint",
"share_blueprint_no_url": "Unable to share blueprint: no source url",
"discover_more": "Discover more blueprints"
},
"add": {