Add link to the community forums to find more blueprints (#7947)

* Add link to the community forums to find more blueprints

* Apply suggestions from code review

Co-authored-by: Paulus Schoutsen <balloob@gmail.com>

Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
This commit is contained in:
Bram Kragten 2020-12-12 20:38:10 +01:00 committed by GitHub
parent 5d4121a9b4
commit 8a42e65c6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 81 additions and 21 deletions

View File

@ -98,6 +98,12 @@ export class HaDataTable extends LitElement {
@property({ type: Boolean }) public hasFab = false; @property({ type: Boolean }) public hasFab = false;
/**
* Add an extra rows at the bottom of the datatabel
* @type {TemplateResult}
*/
@property({ attribute: false }) public appendRow?;
@property({ type: Boolean, attribute: "auto-height" }) @property({ type: Boolean, attribute: "auto-height" })
public autoHeight = false; public autoHeight = false;
@ -126,6 +132,8 @@ export class HaDataTable extends LitElement {
@query("slot[name='header']") private _header!: HTMLSlotElement; @query("slot[name='header']") private _header!: HTMLSlotElement;
private _items: DataTableRowData[] = [];
private _checkableRowsCount?: number; private _checkableRowsCount?: number;
private _checkedRows: string[] = []; private _checkedRows: string[] = [];
@ -318,10 +326,13 @@ export class HaDataTable extends LitElement {
@scroll=${this._saveScrollPos} @scroll=${this._saveScrollPos}
> >
${scroll({ ${scroll({
items: !this.hasFab items: this._items,
? this._filteredData
: [...this._filteredData, ...[{ empty: true }]],
renderItem: (row: DataTableRowData, index) => { renderItem: (row: DataTableRowData, index) => {
if (row.append) {
return html`
<div class="mdc-data-table__row">${row.content}</div>
`;
}
if (row.empty) { if (row.empty) {
return html` <div class="mdc-data-table__row"></div> `; return html` <div class="mdc-data-table__row"></div> `;
} }
@ -447,6 +458,20 @@ export class HaDataTable extends LitElement {
if (this.curRequest !== curRequest) { if (this.curRequest !== curRequest) {
return; return;
} }
if (this.appendRow || this.hasFab) {
this._items = [...data];
if (this.appendRow) {
this._items.push({ append: true, content: this.appendRow });
}
if (this.hasFab) {
this._items.push({ empty: true });
}
} else {
this._items = data;
}
this._filteredData = data; this._filteredData = data;
} }

View File

@ -17,17 +17,17 @@ import "../../components/ha-switch";
import { PolymerChangedEvent } from "../../polymer-types"; import { PolymerChangedEvent } from "../../polymer-types";
import { haStyleDialog } from "../../resources/styles"; import { haStyleDialog } from "../../resources/styles";
import { HomeAssistant } from "../../types"; import { HomeAssistant } from "../../types";
import { DialogParams } from "./show-dialog-box"; import { DialogBoxParams } from "./show-dialog-box";
@customElement("dialog-box") @customElement("dialog-box")
class DialogBox extends LitElement { class DialogBox extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant; @property({ attribute: false }) public hass!: HomeAssistant;
@internalProperty() private _params?: DialogParams; @internalProperty() private _params?: DialogBoxParams;
@internalProperty() private _value?: string; @internalProperty() private _value?: string;
public async showDialog(params: DialogParams): Promise<void> { public async showDialog(params: DialogBoxParams): Promise<void> {
this._params = params; this._params = params;
if (params.prompt) { if (params.prompt) {
this._value = params.defaultValue; this._value = params.defaultValue;
@ -55,8 +55,8 @@ class DialogBox extends LitElement {
return html` return html`
<ha-dialog <ha-dialog
open open
?scrimClickAction=${this._params.prompt} ?scrimClickAction=${confirmPrompt}
?escapeKeyAction=${this._params.prompt} ?escapeKeyAction=${confirmPrompt}
@closed=${this._dialogClosed} @closed=${this._dialogClosed}
defaultAction="ignore" defaultAction="ignore"
.heading=${this._params.title .heading=${this._params.title
@ -140,10 +140,10 @@ class DialogBox extends LitElement {
} }
private _dialogClosed(ev) { private _dialogClosed(ev) {
if (ev.detail.action === "ignore") { if (this._params?.prompt && ev.detail.action === "ignore") {
return; return;
} }
this.closeDialog(); this._dismiss();
} }
private _close(): void { private _close(): void {

View File

@ -1,31 +1,31 @@
import { TemplateResult } from "lit-html"; import { TemplateResult } from "lit-html";
import { fireEvent } from "../../common/dom/fire_event"; import { fireEvent } from "../../common/dom/fire_event";
interface BaseDialogParams { interface BaseDialogBoxParams {
confirmText?: string; confirmText?: string;
text?: string | TemplateResult; text?: string | TemplateResult;
title?: string; title?: string;
warning?: boolean; warning?: boolean;
} }
export interface AlertDialogParams extends BaseDialogParams { export interface AlertDialogParams extends BaseDialogBoxParams {
confirm?: () => void; confirm?: () => void;
} }
export interface ConfirmationDialogParams extends BaseDialogParams { export interface ConfirmationDialogParams extends BaseDialogBoxParams {
dismissText?: string; dismissText?: string;
confirm?: () => void; confirm?: () => void;
cancel?: () => void; cancel?: () => void;
} }
export interface PromptDialogParams extends BaseDialogParams { export interface PromptDialogParams extends BaseDialogBoxParams {
inputLabel?: string; inputLabel?: string;
inputType?: string; inputType?: string;
defaultValue?: string; defaultValue?: string;
confirm?: (out?: string) => void; confirm?: (out?: string) => void;
} }
export interface DialogParams export interface DialogBoxParams
extends ConfirmationDialogParams, extends ConfirmationDialogParams,
PromptDialogParams { PromptDialogParams {
confirm?: (out?: string) => void; confirm?: (out?: string) => void;
@ -37,10 +37,10 @@ export const loadGenericDialog = () => import("./dialog-box");
const showDialogHelper = ( const showDialogHelper = (
element: HTMLElement, element: HTMLElement,
dialogParams: DialogParams, dialogParams: DialogBoxParams,
extra?: { extra?: {
confirmation?: DialogParams["confirmation"]; confirmation?: DialogBoxParams["confirmation"];
prompt?: DialogParams["prompt"]; prompt?: DialogBoxParams["prompt"];
} }
) => ) =>
new Promise((resolve) => { new Promise((resolve) => {

View File

@ -60,6 +60,12 @@ export class HaTabsSubpageDataTable extends LitElement {
*/ */
@property({ type: Boolean }) public hasFab = false; @property({ type: Boolean }) public hasFab = false;
/**
* Add an extra rows at the bottom of the datatabel
* @type {TemplateResult}
*/
@property({ attribute: false }) public appendRow?;
/** /**
* Field with a unique id per entry in data. * Field with a unique id per entry in data.
* @type {String} * @type {String}
@ -171,6 +177,7 @@ export class HaTabsSubpageDataTable extends LitElement {
.noDataText=${this.noDataText} .noDataText=${this.noDataText}
.dir=${computeRTLDirection(this.hass)} .dir=${computeRTLDirection(this.hass)}
.clickable=${this.clickable} .clickable=${this.clickable}
.appendRow=${this.appendRow}
> >
${!this.narrow ${!this.narrow
? html` ? html`

View File

@ -107,7 +107,16 @@ class DialogImportBlueprint extends LitElement {
<pre>${this._result.raw_data}</pre> <pre>${this._result.raw_data}</pre>
</ha-expansion-panel>` </ha-expansion-panel>`
: html`${this.hass.localize( : html`${this.hass.localize(
"ui.panel.config.blueprint.add.import_introduction" "ui.panel.config.blueprint.add.import_introduction_link",
"community_link",
html`<a
href="https://www.home-assistant.io/get-blueprints"
target="_blank"
rel="noreferrer noopener"
>${this.hass.localize(
"ui.panel.config.blueprint.add.community_forums"
)}</a
>`
)}<paper-input )}<paper-input
id="input" id="input"
.label=${this.hass.localize( .label=${this.hass.localize(

View File

@ -170,6 +170,23 @@ class HaBlueprintOverview extends LitElement {
"ui.panel.config.blueprint.overview.no_blueprints" "ui.panel.config.blueprint.overview.no_blueprints"
)} )}
hasFab hasFab
.appendRow=${html` <div
class="mdc-data-table__cell"
style="width: 100%; text-align: center;"
role="cell"
>
<a
href="https://www.home-assistant.io/get-blueprints"
target="_blank"
rel="noreferrer noopener"
>
<mwc-button
>${this.hass.localize(
"ui.panel.config.blueprint.overview.discover_more"
)}</mwc-button
>
</a>
</div>`}
> >
<mwc-icon-button slot="toolbar-icon" @click=${this._showHelp}> <mwc-icon-button slot="toolbar-icon" @click=${this._showHelp}>
<ha-svg-icon .path=${mdiHelpCircle}></ha-svg-icon> <ha-svg-icon .path=${mdiHelpCircle}></ha-svg-icon>

View File

@ -1472,12 +1472,14 @@
"confirm_delete_text": "Are you sure you want to delete this blueprint?", "confirm_delete_text": "Are you sure you want to delete this blueprint?",
"add_blueprint": "Import blueprint", "add_blueprint": "Import blueprint",
"use_blueprint": "Create automation", "use_blueprint": "Create automation",
"delete_blueprint": "Delete blueprint" "delete_blueprint": "Delete blueprint",
"discover_more": "Discover more Blueprints"
}, },
"add": { "add": {
"header": "Import a blueprint", "header": "Import a blueprint",
"import_header": "Blueprint \"{name}\"", "import_header": "Blueprint \"{name}\"",
"import_introduction": "You can import blueprints of other users from Github and the community forums. Enter the URL of the blueprint below.", "import_introduction_link": "You can import blueprints of other users from Github and the {community_link}. Enter the URL of the blueprint below.",
"community_forums": "community forums",
"url": "URL of the blueprint", "url": "URL of the blueprint",
"raw_blueprint": "Blueprint content", "raw_blueprint": "Blueprint content",
"importing": "Loading blueprint...", "importing": "Loading blueprint...",