A modern and easy to use dashboard. 80+ integrations. 20K+ icons built in. Authentication out of the box. No YAML, drag and drop configuration.
feat(releases): persist section collapse state (#7401)
Octopus-98e3a25d54a520
diff --git a/apps/docs/docs/widgets/releases/index.ts b/apps/docs/docs/widgets/releases/index.tsindex c8097d00f..3060e1882 100644--- a/apps/docs/docs/widgets/releases/index.ts+++ b/apps/docs/docs/widgets/releases/index.ts@@ -27,12 +27,6 @@ export const releasesWidget: WidgetDefinition = {values: { type: "select", options: ["New", "Needs attention", "Up to date", "Quiet"] },defaultValue: "All",},- {- name: "Collapsed sections",- description: "Groups that start collapsed.",- values: { type: "select", options: ["New", "Needs attention", "Up to date", "Quiet"] },- defaultValue: "Quiet",- },{name: "Highlight new releases for",description: "Releases published within this period are listed under New until you mark them as viewed.",diff --git a/packages/translation/src/lang/en.json b/packages/translation/src/lang/en.jsonindex 5243be101..ea9936372 100644--- a/packages/translation/src/lang/en.json+++ b/packages/translation/src/lang/en.json@@ -4797,10 +4797,6 @@"label": "Sections","description": "Groups of repositories to show. Hidden groups are not listed at all."},- "collapsedSections": {- "label": "Collapsed sections",- "description": "Groups that start collapsed. Click a group title to expand it."- },"newReleaseWithin": {"label": "Highlight new releases for","description": "Releases published within this period are listed under New until you mark them as viewed.",@@ -5005,7 +5001,11 @@"runningVersions": "Running Versions","upToDate": "Up to date","updateAvailable": "Update available",- "unknownStatus": "Unknown"+ "unknownStatus": "Unknown",+ "error": {+ "collapsedSaveTitle": "Collapsed sections were not saved",+ "collapsedSaveMessage": "The section could not be updated. Try again."+ }},"networkControllerSummary": {"advanced": {diff --git a/packages/widgets/src/releases/component.tsx b/packages/widgets/src/releases/component.tsxindex a212d326a..b88e1d24d 100644--- a/packages/widgets/src/releases/component.tsx+++ b/packages/widgets/src/releases/component.tsx@@ -14,7 +14,11 @@ import {} from "@tabler/icons-react";import { useFormatter } from "next-intl";+import { clientApi } from "@homarr/api/client";+import { useSession } from "@homarr/auth/client";+import { constructBoardPermissions } from "@homarr/auth/shared";import { useRequiredBoard } from "@homarr/boards/context";+import { showErrorNotification } from "@homarr/notifications";import { useI18n } from "@homarr/translation/client";import { zoomCompensatedSize } from "@homarr/ui";@@ -104,7 +108,9 @@ const getInboxDisplay = (export default function ReleasesWidget({options,+ setOptions,itemId,+ boardId,integrationIds,width,height,@@ -115,6 +121,8 @@ export default function ReleasesWidget({}: WidgetComponentProps<"releases">) {const t = useI18n("widget.releases");const board = useRequiredBoard();+ const { data: session } = useSession();+ const hasChangeAccess = constructBoardPermissions(board, session ?? null).hasChangeAccess;const { entries, isInitialLoading, isFetching, serviceVersionsQuery, markViewed, markAllViewed } = useReleaseEntries({options,itemId,@@ -145,6 +153,10 @@ export default function ReleasesWidget({collapsedSections={options.collapsedSections}showChangelogPreview={options.showChangelogPreview}groupReleases={options.groupReleases}+ setOptions={setOptions}+ boardId={boardId}+ itemId={itemId}+ hasChangeAccess={hasChangeAccess}/>);}@@ -164,6 +176,10 @@ interface ReleasesInboxProps {collapsedSections: ReleaseSectionKey[];showChangelogPreview: boolean;groupReleases: boolean;+ setOptions: WidgetComponentProps<"releases">["setOptions"];+ boardId: string | undefined;+ itemId: string | undefined;+ hasChangeAccess: boolean;}const ReleasesInbox = ({@@ -181,10 +197,22 @@ const ReleasesInbox = ({collapsedSections,showChangelogPreview,groupReleases,+ setOptions,+ boardId,+ itemId,+ hasChangeAccess,}: ReleasesInboxProps) => {const t = useI18n("widget.releases");const formatter = useFormatter();const board = useRequiredBoard();+ const savePendingRef = useRef(false);+ const { mutate: saveCollapsedSections } = clientApi.widget.options.saveItemOptions.useMutation({+ onError: () =>+ showErrorNotification({+ title: t("error.collapsedSaveTitle"),+ message: t("error.collapsedSaveMessage"),+ }),+ });const now = useWidgetNow();const rootRef = useRef<HTMLDivElement>(null);@@ -221,8 +249,43 @@ const ReleasesInbox = ({const isOpen = (key: ReleaseSectionKey) =>sectionOpen[key] ?? (!collapsedSections.includes(key) && (density === "regular" || key === "new"));- const toggleSection = (key: ReleaseSectionKey) =>- setSectionOpen((previous) => ({ ...previous, [key]: !isOpen(key) }));+ const toggleSection = (key: ReleaseSectionKey) => {+ if (savePendingRef.current) return;+ const nextOpen = !isOpen(key);+ const previousOpen = sectionOpen[key];+ setSectionOpen((previous) => ({ ...previous, [key]: nextOpen }));++ // Density closes some sections without recording them. Only a toggle that changes the saved list is stored.+ const persistedCollapsed = collapsedSections.includes(key);+ if (persistedCollapsed !== nextOpen) return;++ const nextCollapsed = nextOpen+ ? collapsedSections.filter((section) => section !== key)+ : [...collapsedSections, key];+ setOptions({ newOptions: { collapsedSections: nextCollapsed } });+ if (!hasChangeAccess || !boardId || !itemId) return;++ savePendingRef.current = true;+ saveCollapsedSections(+ { boardId, itemId, newOptions: { collapsedSections: nextCollapsed } },+ {+ onError: () => {+ setSectionOpen((current) => {+ if (previousOpen === undefined) {+ const next = { ...current };+ delete next[key];+ return next;+ }+ return { ...current, [key]: previousOpen };+ });+ setOptions({ newOptions: { collapsedSections } });+ },+ onSettled: () => {+ savePendingRef.current = false;+ },+ },+ );+ };useEffect(() => {if (!scrollTarget) return;diff --git a/packages/widgets/src/releases/index.ts b/packages/widgets/src/releases/index.tsindex e4ed40d91..b19e719c5 100644--- a/packages/widgets/src/releases/index.ts+++ b/packages/widgets/src/releases/index.ts@@ -6,6 +6,7 @@ import { getWidgetIntegrationConfig, releaseProviderKinds } from "@homarr/definiimport { createWidgetDefinition, matchesWidgetRuntimeQuery, widgetQueryInputMatches } from "../definition";import { optionsBuilder } from "../options";+import type { ReleaseSectionKey } from "./release-options";import {newReleaseWithinOptions,releaseLayouts,@@ -54,14 +55,8 @@ export const { definition, componentLoader } = createWidgetDefinition("releases"label: (t) => t(`widget.releases.section.${value}.label`),})),}),- collapsedSections: factory.multiSelect({- defaultValue: ["quiet"],- withDescription: true,- options: releaseSectionKeys.map((value) => ({- value,- label: (t) => t(`widget.releases.section.${value}.label`),- })),- }),+ // Saved from the widget itself, like the Beszel system switcher and Wazuh view.+ collapsedSections: factory.internal({ defaultValue: ["quiet"] as ReleaseSectionKey[] }),newReleaseWithin: factory.select({defaultValue: "1w",withDescription: true,