diff --git a/src/data/repairs.ts b/src/data/repairs.ts index b7264379a5..efb724847a 100644 --- a/src/data/repairs.ts +++ b/src/data/repairs.ts @@ -27,14 +27,16 @@ export const fetchRepairsIssues = async (hass: HomeAssistant) => type: "repairs/list_issues", }); -export const dismissRepairsIssue = async ( +export const ignoreRepairsIssue = async ( hass: HomeAssistant, - issue: RepairsIssue + issue: RepairsIssue, + ignore: boolean ) => hass.callWS({ - type: "repairs/dismiss_issue", + type: "repairs/ignore_issue", issue_id: issue.issue_id, domain: issue.domain, + ignore, }); export const createRepairsFlow = ( diff --git a/src/panels/config/repairs/dialog-repairs-issue.ts b/src/panels/config/repairs/dialog-repairs-issue.ts index 890bc456f4..b241837807 100644 --- a/src/panels/config/repairs/dialog-repairs-issue.ts +++ b/src/panels/config/repairs/dialog-repairs-issue.ts @@ -4,7 +4,7 @@ import { customElement, property, state } from "lit/decorators"; import { fireEvent } from "../../../common/dom/fire_event"; import { createCloseHeading } from "../../../components/ha-dialog"; import "../../../components/ha-markdown"; -import type { RepairsIssue } from "../../../data/repairs"; +import { ignoreRepairsIssue, RepairsIssue } from "../../../data/repairs"; import { haStyleDialog } from "../../../resources/styles"; import type { HomeAssistant } from "../../../types"; import type { RepairsIssueDialogParams } from "./show-repair-issue-dialog"; @@ -23,6 +23,10 @@ class DialogRepairsIssue extends LitElement { } public closeDialog() { + if (this._params?.dialogClosedCallback) { + this._params.dialogClosedCallback(); + } + this._params = undefined; this._issue = undefined; fireEvent(this, "dialog-closed", { dialog: this.localName }); @@ -50,6 +54,24 @@ class DialogRepairsIssue extends LitElement { )} >
+ ${this.hass.localize( + "ui.panel.config.repairs.dialog.alert_not_fixable" + )} + ${this._issue.breaks_in_ha_version + ? this.hass.localize( + "ui.panel.config.repairs.dialog.breaks_in_version", + { version: this._issue.breaks_in_ha_version } + ) + : ""} + - - ${this._issue.breaks_in_ha_version - ? html` -
This will no longer work as of the - ${this._issue.breaks_in_ha_version} release of Home Assistant. - ` - : ""} -
The issue is ${this._issue.severity} severity.
We can not - automatically repair this issue for you. ${this._issue.dismissed_version ? html` -
This issue has been dismissed in version - ${this._issue.dismissed_version}. +
+ ${this.hass.localize( + "ui.panel.config.repairs.dialog.dismissed_in_version", + { version: this._issue.dismissed_version } + )} ` : ""}
@@ -84,20 +101,43 @@ class DialogRepairsIssue extends LitElement { slot="primaryAction" rel="noopener noreferrer" > - + ` : ""} + `; } + private _ignoreIssue() { + ignoreRepairsIssue(this.hass, this._issue!, !this._issue!.ignored); + this.closeDialog(); + } + static styles: CSSResultGroup = [ haStyleDialog, css` + ha-alert { + margin-bottom: 16px; + display: block; + } a { text-decoration: none; } + .dismissed { + font-style: italic; + } `, ]; } diff --git a/src/panels/config/repairs/ha-config-repairs-dashboard.ts b/src/panels/config/repairs/ha-config-repairs-dashboard.ts index 5d6c913058..21f46e0db0 100644 --- a/src/panels/config/repairs/ha-config-repairs-dashboard.ts +++ b/src/panels/config/repairs/ha-config-repairs-dashboard.ts @@ -1,8 +1,14 @@ +import type { ActionDetail } from "@material/mwc-list"; +import { mdiDotsVertical } from "@mdi/js"; import { css, html, LitElement, PropertyValues, TemplateResult } from "lit"; import { customElement, property, state } from "lit/decorators"; +import memoizeOne from "memoize-one"; import "../../../components/ha-card"; -import type { RepairsIssue } from "../../../data/repairs"; -import { fetchRepairsIssues } from "../../../data/repairs"; +import { + fetchRepairsIssues, + RepairsIssue, + severitySort, +} from "../../../data/repairs"; import "../../../layouts/hass-subpage"; import type { HomeAssistant } from "../../../types"; import "./ha-config-repairs"; @@ -15,12 +21,25 @@ class HaConfigRepairsDashboard extends LitElement { @state() private _repairsIssues: RepairsIssue[] = []; + @state() private _showIgnored = false; + + private _getFilteredIssues = memoizeOne( + (showIgnored: boolean, repairsIssues: RepairsIssue[]) => + showIgnored + ? repairsIssues + : repairsIssues.filter((issue) => !issue.ignored) + ); + protected firstUpdated(changedProps: PropertyValues): void { super.firstUpdated(changedProps); this._fetchIssues(); } protected render(): TemplateResult { + const issues = this._getFilteredIssues( + this._showIgnored, + this._repairsIssues + ); return html` +
+ + + + ${this._showIgnored + ? this.hass.localize("ui.panel.config.repairs.hide_ignored") + : this.hass.localize("ui.panel.config.repairs.show_ignored")} + + +
@@ -36,7 +69,7 @@ class HaConfigRepairsDashboard extends LitElement { ` @@ -55,7 +88,9 @@ class HaConfigRepairsDashboard extends LitElement { } private async _fetchIssues(): Promise { - this._repairsIssues = (await fetchRepairsIssues(this.hass)).issues; + this._repairsIssues = (await fetchRepairsIssues(this.hass)).issues.sort( + (a, b) => severitySort[a.severity] - severitySort[b.severity] + ); const integrations: Set = new Set(); for (const issue of this._repairsIssues) { integrations.add(issue.domain); @@ -63,6 +98,14 @@ class HaConfigRepairsDashboard extends LitElement { this.hass.loadBackendTranslation("issues", [...integrations]); } + private _handleAction(ev: CustomEvent) { + switch (ev.detail.index) { + case 0: + this._showIgnored = !this._showIgnored; + break; + } + } + static styles = css` .content { padding: 28px 20px 0; diff --git a/src/panels/config/repairs/ha-config-repairs.ts b/src/panels/config/repairs/ha-config-repairs.ts index 6a6fa8f168..cc05efb0cb 100644 --- a/src/panels/config/repairs/ha-config-repairs.ts +++ b/src/panels/config/repairs/ha-config-repairs.ts @@ -41,43 +41,41 @@ class HaConfigRepairs extends LitElement { })}
- ${issues.map((issue) => - issue.ignored - ? "" - : html` - - - ${this.hass.localize( - `component.${issue.domain}.issues.${ - issue.translation_key || issue.issue_id - }.title` - )} - - ${issue.created - ? relativeTime(new Date(issue.created), this.hass.locale) - : ""} - - - ` + ${issues.map( + (issue) => html` + + + ${this.hass.localize( + `component.${issue.domain}.issues.${ + issue.translation_key || issue.issue_id + }.title` + )} + + ${issue.created + ? relativeTime(new Date(issue.created), this.hass.locale) + : ""} + + + ` )} `; @@ -91,7 +89,13 @@ class HaConfigRepairs extends LitElement { fireEvent(this, "update-issues"); }); } else { - showRepairsIssueDialog(this, { issue: (ev.currentTarget as any).issue }); + showRepairsIssueDialog(this, { + issue, + dialogClosedCallback: () => { + // @ts-ignore + fireEvent(this, "update-issues"); + }, + }); } } diff --git a/src/panels/config/repairs/show-repair-issue-dialog.ts b/src/panels/config/repairs/show-repair-issue-dialog.ts index 4591591c7c..566d301b77 100644 --- a/src/panels/config/repairs/show-repair-issue-dialog.ts +++ b/src/panels/config/repairs/show-repair-issue-dialog.ts @@ -3,6 +3,7 @@ import type { RepairsIssue } from "../../../data/repairs"; export interface RepairsIssueDialogParams { issue: RepairsIssue; + dialogClosedCallback: () => void; } export const loadRepairsIssueDialog = () => import("./dialog-repairs-issue"); diff --git a/src/translations/en.json b/src/translations/en.json index 292c97078f..f44b6a851a 100755 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -1232,10 +1232,20 @@ "title": "{count} {count, plural,\n one {repair}\n other {repairs}\n}", "no_repairs": "There are currently no repairs available", "more_repairs": "+{count} repairs", + "show_ignored": "Show ignored", + "hide_ignored": "Hide ignored", + "critical": "Critical", + "error": "Error", + "warning": "Warning", "dialog": { "title": "Repair", "fix": "Repair", - "learn": "Learn more" + "learn": "Learn more", + "ignore": "Ignore", + "unignore": "Unignore", + "alert_not_fixable": "We can not repair this issue for you.", + "breaks_in_version": "This will break in version {version}. Please fix this issue before upgrading.", + "dismissed_in_version": "This issue was dismissed in version {version}." } }, "areas": {