link to updates page (#12423)

This commit is contained in:
Bram Kragten 2022-04-25 22:56:34 +02:00 committed by GitHub
parent ca28178b86
commit 490f84a7b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 25 deletions

View File

@ -131,9 +131,8 @@ class HaConfigDashboard extends LitElement {
}); });
protected render(): TemplateResult { protected render(): TemplateResult {
const canInstallUpdates = this._filterUpdateEntitiesWithInstall( const [canInstallUpdates, totalUpdates] =
this.hass.states this._filterUpdateEntitiesWithInstall(this.hass.states);
);
return html` return html`
<ha-app-layout> <ha-app-layout>
@ -177,8 +176,19 @@ class HaConfigDashboard extends LitElement {
<ha-config-updates <ha-config-updates
.hass=${this.hass} .hass=${this.hass}
.narrow=${this.narrow} .narrow=${this.narrow}
.total=${totalUpdates}
.updateEntities=${canInstallUpdates} .updateEntities=${canInstallUpdates}
></ha-config-updates> ></ha-config-updates>
${totalUpdates > canInstallUpdates.length
? html`<a class="button" href="/config/updates">
${this.hass.localize(
"ui.panel.config.updates.more_updates",
{
count: totalUpdates - canInstallUpdates.length,
}
)}
</a>`
: ""}
</ha-card>` </ha-card>`
: ""} : ""}
<ha-card outlined> <ha-card outlined>
@ -259,10 +269,15 @@ class HaConfigDashboard extends LitElement {
); );
private _filterUpdateEntitiesWithInstall = memoizeOne( private _filterUpdateEntitiesWithInstall = memoizeOne(
(entities: HassEntities) => (entities: HassEntities): [UpdateEntity[], number] => {
this._filterUpdateEntities(entities).filter((entity) => const updates = this._filterUpdateEntities(entities).filter((entity) =>
updateCanInstall(entity) updateCanInstall(entity)
) );
return [
updates.slice(0, updates.length === 3 ? updates.length : 2),
updates.length,
];
}
); );
private _showQuickBar(): void { private _showQuickBar(): void {
@ -320,6 +335,11 @@ class HaConfigDashboard extends LitElement {
text-decoration: none; text-decoration: none;
color: var(--primary-text-color); color: var(--primary-text-color);
} }
a.button {
display: block;
color: var(--primary-color);
padding: 16px;
}
.title { .title {
font-size: 16px; font-size: 16px;
padding: 16px; padding: 16px;

View File

@ -19,22 +19,20 @@ class HaConfigUpdates extends LitElement {
@property({ attribute: false }) @property({ attribute: false })
public updateEntities?: UpdateEntity[]; public updateEntities?: UpdateEntity[];
@property({ type: Boolean, reflect: true }) showAll = false; @property({ type: Number })
public total?: number;
protected render(): TemplateResult { protected render(): TemplateResult {
if (!this.updateEntities?.length) { if (!this.updateEntities?.length) {
return html``; return html``;
} }
const updates = const updates = this.updateEntities;
this.showAll || this.updateEntities.length <= 3
? this.updateEntities
: this.updateEntities.slice(0, 2);
return html` return html`
<div class="title"> <div class="title">
${this.hass.localize("ui.panel.config.updates.title", { ${this.hass.localize("ui.panel.config.updates.title", {
count: this.updateEntities.length, count: this.total || this.updateEntities.length,
})} })}
</div> </div>
${updates.map( ${updates.map(
@ -70,15 +68,6 @@ class HaConfigUpdates extends LitElement {
</paper-icon-item> </paper-icon-item>
` `
)} )}
${!this.showAll && this.updateEntities.length >= 4
? html`
<button class="show-more" @click=${this._showAllClicked}>
${this.hass.localize("ui.panel.config.updates.more_updates", {
count: this.updateEntities!.length - updates.length,
})}
</button>
`
: ""}
`; `;
} }
@ -88,10 +77,6 @@ class HaConfigUpdates extends LitElement {
}); });
} }
private _showAllClicked() {
this.showAll = true;
}
static get styles(): CSSResultGroup[] { static get styles(): CSSResultGroup[] {
return [ return [
css` css`