From 8a42e65c6ad632f4a440e5271f590beec366df59 Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Sat, 12 Dec 2020 20:38:10 +0100 Subject: [PATCH] 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 Co-authored-by: Paulus Schoutsen --- src/components/data-table/ha-data-table.ts | 31 +++++++++++++++++-- src/dialogs/generic/dialog-box.ts | 14 ++++----- src/dialogs/generic/show-dialog-box.ts | 16 +++++----- src/layouts/hass-tabs-subpage-data-table.ts | 7 +++++ .../blueprint/dialog-import-blueprint.ts | 11 ++++++- .../config/blueprint/ha-blueprint-overview.ts | 17 ++++++++++ src/translations/en.json | 6 ++-- 7 files changed, 81 insertions(+), 21 deletions(-) diff --git a/src/components/data-table/ha-data-table.ts b/src/components/data-table/ha-data-table.ts index 1b8530dcec..04eebc36a1 100644 --- a/src/components/data-table/ha-data-table.ts +++ b/src/components/data-table/ha-data-table.ts @@ -98,6 +98,12 @@ export class HaDataTable extends LitElement { @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" }) public autoHeight = false; @@ -126,6 +132,8 @@ export class HaDataTable extends LitElement { @query("slot[name='header']") private _header!: HTMLSlotElement; + private _items: DataTableRowData[] = []; + private _checkableRowsCount?: number; private _checkedRows: string[] = []; @@ -318,10 +326,13 @@ export class HaDataTable extends LitElement { @scroll=${this._saveScrollPos} > ${scroll({ - items: !this.hasFab - ? this._filteredData - : [...this._filteredData, ...[{ empty: true }]], + items: this._items, renderItem: (row: DataTableRowData, index) => { + if (row.append) { + return html` +
${row.content}
+ `; + } if (row.empty) { return html`
`; } @@ -447,6 +458,20 @@ export class HaDataTable extends LitElement { if (this.curRequest !== curRequest) { 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; } diff --git a/src/dialogs/generic/dialog-box.ts b/src/dialogs/generic/dialog-box.ts index e905f0c3ff..059fff683b 100644 --- a/src/dialogs/generic/dialog-box.ts +++ b/src/dialogs/generic/dialog-box.ts @@ -17,17 +17,17 @@ import "../../components/ha-switch"; import { PolymerChangedEvent } from "../../polymer-types"; import { haStyleDialog } from "../../resources/styles"; import { HomeAssistant } from "../../types"; -import { DialogParams } from "./show-dialog-box"; +import { DialogBoxParams } from "./show-dialog-box"; @customElement("dialog-box") class DialogBox extends LitElement { @property({ attribute: false }) public hass!: HomeAssistant; - @internalProperty() private _params?: DialogParams; + @internalProperty() private _params?: DialogBoxParams; @internalProperty() private _value?: string; - public async showDialog(params: DialogParams): Promise { + public async showDialog(params: DialogBoxParams): Promise { this._params = params; if (params.prompt) { this._value = params.defaultValue; @@ -55,8 +55,8 @@ class DialogBox extends LitElement { return html` void; } -export interface ConfirmationDialogParams extends BaseDialogParams { +export interface ConfirmationDialogParams extends BaseDialogBoxParams { dismissText?: string; confirm?: () => void; cancel?: () => void; } -export interface PromptDialogParams extends BaseDialogParams { +export interface PromptDialogParams extends BaseDialogBoxParams { inputLabel?: string; inputType?: string; defaultValue?: string; confirm?: (out?: string) => void; } -export interface DialogParams +export interface DialogBoxParams extends ConfirmationDialogParams, PromptDialogParams { confirm?: (out?: string) => void; @@ -37,10 +37,10 @@ export const loadGenericDialog = () => import("./dialog-box"); const showDialogHelper = ( element: HTMLElement, - dialogParams: DialogParams, + dialogParams: DialogBoxParams, extra?: { - confirmation?: DialogParams["confirmation"]; - prompt?: DialogParams["prompt"]; + confirmation?: DialogBoxParams["confirmation"]; + prompt?: DialogBoxParams["prompt"]; } ) => new Promise((resolve) => { diff --git a/src/layouts/hass-tabs-subpage-data-table.ts b/src/layouts/hass-tabs-subpage-data-table.ts index 9af3dd8317..d11d01dafe 100644 --- a/src/layouts/hass-tabs-subpage-data-table.ts +++ b/src/layouts/hass-tabs-subpage-data-table.ts @@ -60,6 +60,12 @@ export class HaTabsSubpageDataTable extends LitElement { */ @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. * @type {String} @@ -171,6 +177,7 @@ export class HaTabsSubpageDataTable extends LitElement { .noDataText=${this.noDataText} .dir=${computeRTLDirection(this.hass)} .clickable=${this.clickable} + .appendRow=${this.appendRow} > ${!this.narrow ? html` diff --git a/src/panels/config/blueprint/dialog-import-blueprint.ts b/src/panels/config/blueprint/dialog-import-blueprint.ts index ed65a04157..31f190c2f2 100644 --- a/src/panels/config/blueprint/dialog-import-blueprint.ts +++ b/src/panels/config/blueprint/dialog-import-blueprint.ts @@ -107,7 +107,16 @@ class DialogImportBlueprint extends LitElement {
${this._result.raw_data}
` : html`${this.hass.localize( - "ui.panel.config.blueprint.add.import_introduction" + "ui.panel.config.blueprint.add.import_introduction_link", + "community_link", + html`${this.hass.localize( + "ui.panel.config.blueprint.add.community_forums" + )}` )} + + ${this.hass.localize( + "ui.panel.config.blueprint.overview.discover_more" + )} + + `} > diff --git a/src/translations/en.json b/src/translations/en.json index aa10caf715..2d0f79b7ca 100755 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -1472,12 +1472,14 @@ "confirm_delete_text": "Are you sure you want to delete this blueprint?", "add_blueprint": "Import blueprint", "use_blueprint": "Create automation", - "delete_blueprint": "Delete blueprint" + "delete_blueprint": "Delete blueprint", + "discover_more": "Discover more Blueprints" }, "add": { "header": "Import a blueprint", "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", "raw_blueprint": "Blueprint content", "importing": "Loading blueprint...",