From be4081e223eaead798d821f42a016b0642483973 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Fri, 26 Jan 2024 09:19:12 +0100 Subject: [PATCH] Add dismiss new to overflow menu (#706) --- .../hacs-repository-owerflow-menu.ts | 19 ++++++++++++++++--- src/dashboards/hacs-dashboard.ts | 19 ++++++++----------- src/data/websocket.ts | 8 +++++++- src/localize/languages/en.json | 1 + 4 files changed, 32 insertions(+), 15 deletions(-) diff --git a/src/components/hacs-repository-owerflow-menu.ts b/src/components/hacs-repository-owerflow-menu.ts index 789c5f19..914a1fd2 100644 --- a/src/components/hacs-repository-owerflow-menu.ts +++ b/src/components/hacs-repository-owerflow-menu.ts @@ -6,6 +6,7 @@ import { mdiGithub, mdiInformation, mdiLanguageJavascript, + mdiMoonNew, mdiReload, } from "@mdi/js"; import memoizeOne from "memoize-one"; @@ -18,14 +19,18 @@ import { } from "../../homeassistant-frontend/src/data/lovelace/resource"; import { showConfirmationDialog } from "../../homeassistant-frontend/src/dialogs/generic/show-dialog-box"; import type { RepositoryBase } from "../data/repository"; -import { repositoryUninstall, repositoryUpdate } from "../data/websocket"; +import { + repositoriesClearNewRepository, + repositoryUninstall, + repositoryUpdate, +} from "../data/websocket"; import type { HacsDashboard } from "../dashboards/hacs-dashboard"; import type { HacsRepositoryDashboard } from "../dashboards/hacs-repository-dashboard"; import { showHacsDownloadDialog, showHacsFormDialog } from "./dialogs/show-hacs-dialog"; export const repositoryMenuItems = memoizeOne( (element: HacsRepositoryDashboard | HacsDashboard, repository: RepositoryBase) => [ - ...(element.nodeName === "HACS-EXPERIMENTAL-PANEL" + ...(element.nodeName === "HACS-DASHBOARD" ? [ { path: mdiInformation, @@ -58,7 +63,15 @@ export const repositoryMenuItems = memoizeOne( hideForUninstalled: true, }, ] - : []), + : repository.new + ? [ + { + path: mdiMoonNew, + label: element.hacs.localize("repository_card.dismiss_new"), + action: () => repositoriesClearNewRepository(element.hass, repository.id), + }, + ] + : []), ...(repository.category === "plugin" && repository.installed_version ? [ { diff --git a/src/dashboards/hacs-dashboard.ts b/src/dashboards/hacs-dashboard.ts index 2e9b7d10..bd935d7c 100644 --- a/src/dashboards/hacs-dashboard.ts +++ b/src/dashboards/hacs-dashboard.ts @@ -536,17 +536,14 @@ export class HacsDashboard extends LitElement { title: "", width: this.narrow ? undefined : "10%", type: "overflow-menu", - template: (repository: RepositoryBase) => - repository.installed - ? html` - - - ` - : "", + template: (repository: RepositoryBase) => html` + + + `, }, }), ); diff --git a/src/data/websocket.ts b/src/data/websocket.ts index c396d2ea..da292a04 100644 --- a/src/data/websocket.ts +++ b/src/data/websocket.ts @@ -51,10 +51,16 @@ export const repositoriesClearNew = async (hass: HomeAssistant, hacs: Hacs) => categories: hacs.info.categories, }); +export const repositoriesClearNewRepository = async (hass: HomeAssistant, repository: string) => + hass.connection.sendMessagePromise({ + type: "hacs/repositories/clear_new", + repository, + }); + export const websocketSubscription = ( hass: HomeAssistant, onChange: (result: Record | null) => void, - event: HacsDispatchEvent + event: HacsDispatchEvent, ) => hass.connection.subscribeMessage(onChange, { type: "hacs/subscribe", diff --git a/src/localize/languages/en.json b/src/localize/languages/en.json index a69d3ef7..07922310 100644 --- a/src/localize/languages/en.json +++ b/src/localize/languages/en.json @@ -120,6 +120,7 @@ }, "repository_card": { "dismiss": "dismiss", + "dismiss_new": "Dismiss new", "information": "Information", "new_repository": "New repository", "not_loaded": "Not loaded",