Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
Split container update badge runtime owners
rcourtman2900176a8741
diff --git a/docs/release-control/v6/internal/subsystems/frontend-primitives.md b/docs/release-control/v6/internal/subsystems/frontend-primitives.mdindex fcbc4ae7cf..2db325ff01 100644--- a/docs/release-control/v6/internal/subsystems/frontend-primitives.md+++ b/docs/release-control/v6/internal/subsystems/frontend-primitives.md@@ -195,6 +195,16 @@ and hover state, and `frontend-modern/src/components/shared/historyChartModel.tsowns tooltip formatting, scale and axis math, and closest-point selection.Future history-chart work should extend those owners instead of pushing fetch,license, or canvas math back into the shared component shell.+The shared container update badge now follows that same owner split.+`frontend-modern/src/components/shared/ContainerUpdateBadge.tsx` stays the+render surface for the badge, icon, and update button shells,+`frontend-modern/src/components/shared/useContainerUpdateButtonState.ts` owns+Docker update mutation flow, persistent update-store state, settings gating,+and button lifecycle, and+`frontend-modern/src/components/shared/containerUpdateBadgeModel.ts` owns badge+and button tooltip formatting, class selection, and label/state presentation.+Future container-update work should extend those owners instead of pushing+store wiring, settings reads, or mutation flow back into the shared shell.The audit log settings surface now follows that same owner split.`frontend-modern/src/components/Settings/AuditLogPanel.tsx` stays the canonicaldiff --git a/docs/release-control/v6/internal/subsystems/registry.json b/docs/release-control/v6/internal/subsystems/registry.jsonindex 13d48e715b..52f88b3803 100644--- a/docs/release-control/v6/internal/subsystems/registry.json+++ b/docs/release-control/v6/internal/subsystems/registry.json@@ -2192,6 +2192,7 @@"test_prefixes": [],"exact_files": ["frontend-modern/src/components/shared/__tests__/CommandPaletteModal.test.tsx",+ "frontend-modern/src/components/shared/__tests__/ContainerUpdateBadge.test.tsx","frontend-modern/src/components/shared/__tests__/Dialog.test.tsx","frontend-modern/src/components/shared/__tests__/HistoryChart.test.tsx","frontend-modern/src/components/shared/__tests__/InfrastructureSummaryTable.test.tsx",diff --git a/frontend-modern/src/components/shared/ContainerUpdateBadge.tsx b/frontend-modern/src/components/shared/ContainerUpdateBadge.tsxindex 0e461d542b..786117beec 100644--- a/frontend-modern/src/components/shared/ContainerUpdateBadge.tsx+++ b/frontend-modern/src/components/shared/ContainerUpdateBadge.tsx@@ -1,66 +1,91 @@-import { Component, Show, createSignal, createEffect, createMemo } from 'solid-js';-import type { DockerContainerUpdateStatus } from '@/types/api';+import { Component, Match, Show, Switch } from 'solid-js';import { showTooltip, hideTooltip } from '@/components/shared/Tooltip';-import { MonitoringAPI } from '@/api/monitoring';import {- getContainerUpdateState,- markContainerQueued,- markContainerUpdateSuccess,- markContainerUpdateError,- clearContainerUpdateState,- updateStates,-} from '@/stores/containerUpdates';-import { shouldHideDockerUpdateActions, areSystemSettingsLoaded } from '@/stores/systemSettings';--interface ContainerUpdateBadgeProps {- updateStatus?: DockerContainerUpdateStatus;- compact?: boolean;-}+ getContainerUpdateBadgeTooltip,+ getContainerUpdateErrorTooltip,+ getUpdateButtonClass,+ getUpdateIconTooltip,+ hasContainerUpdate,+ hasContainerUpdateError,+ type ContainerUpdateBadgeProps,+ type UpdateButtonProps,+ type UpdateIconProps,+} from './containerUpdateBadgeModel';+import { useContainerUpdateButtonState } from './useContainerUpdateButtonState';++export type {+ ContainerUpdateBadgeProps,+ UpdateButtonProps,+ UpdateIconProps,+ UpdateState,+} from './containerUpdateBadgeModel';++const UpdateArrowIcon: Component<{ class?: string }> = (props) => (+ <svg class={props.class} fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">+ <path+ stroke-linecap="round"+ stroke-linejoin="round"+ d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-8l-4-4m0 0L8 8m4-4v12"+ />+ </svg>+);++const ErrorIndicatorIcon: Component<{ class?: string }> = (props) => (+ <svg class={props.class} fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">+ <path+ stroke-linecap="round"+ stroke-linejoin="round"+ d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"+ />+ </svg>+);++const SpinnerIcon: Component<{ class?: string }> = (props) => (+ <svg class={props.class} fill="none" viewBox="0 0 24 24">+ <circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4" />+ <path+ class="opacity-75"+ fill="currentColor"+ d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"+ />+ </svg>+);++const CheckIcon: Component<{ class?: string }> = (props) => (+ <svg class={props.class} fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">+ <path stroke-linecap="round" stroke-linejoin="round" d="M5 13l4 4L19 7" />+ </svg>+);++const XIcon: Component<{ class?: string }> = (props) => (+ <svg class={props.class} fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">+ <path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" />+ </svg>+);/*** ContainerUpdateBadge displays a visual indicator when a container image has an update available.* Uses a blue color scheme to differentiate from health/status badges.*/export const ContainerUpdateBadge: Component<ContainerUpdateBadgeProps> = (props) => {- const hasUpdate = () => props.updateStatus?.updateAvailable === true;- const hasError = () => Boolean(props.updateStatus?.error);-return (- <Show when={hasUpdate() || hasError()}>+ <Show when={hasContainerUpdate(props.updateStatus) || hasContainerUpdateError(props.updateStatus)}><Show- when={hasUpdate()}+ when={hasContainerUpdate(props.updateStatus)}fallback={- // Show subtle error indicator if check failed- <Show when={hasError()}>+ <Show when={hasContainerUpdateError(props.updateStatus)}><spanclass="inline-flex items-center gap-1 rounded-full px-1.5 py-0.5 text-xs font-medium bg-surface-alt text-muted cursor-help"onMouseEnter={(e) => {const rect = e.currentTarget.getBoundingClientRect();- showTooltip(- `Update check failed: ${props.updateStatus?.error}`,- rect.left + rect.width / 2,- rect.top,- {- align: 'center',- direction: 'up',- },- );+ showTooltip(getContainerUpdateErrorTooltip(props.updateStatus), rect.left + rect.width / 2, rect.top, {+ align: 'center',+ direction: 'up',+ });}}onMouseLeave={() => hideTooltip()}>- <svg- class="w-3 h-3"- fill="none"- viewBox="0 0 24 24"- stroke="currentColor"- stroke-width="2"- >- <path- stroke-linecap="round"- stroke-linejoin="round"- d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"- />- </svg>+ <ErrorIndicatorIcon class="w-3 h-3" /><Show when={!props.compact}><span>Check failed</span></Show>@@ -72,29 +97,14 @@ export const ContainerUpdateBadge: Component<ContainerUpdateBadgeProps> = (propsclass="inline-flex items-center gap-1 rounded-full px-1.5 py-0.5 text-xs font-medium bg-blue-100 text-blue-700 dark:bg-blue-900 dark:text-blue-300 cursor-help"onMouseEnter={(e) => {const rect = e.currentTarget.getBoundingClientRect();- const current = props.updateStatus?.currentDigest?.slice(0, 19) || 'unknown';- const latest = props.updateStatus?.latestDigest?.slice(0, 19) || 'unknown';- const content = `Image update available\nCurrent: ${current}...\nLatest: ${latest}...`;- showTooltip(content, rect.left + rect.width / 2, rect.top, {+ showTooltip(getContainerUpdateBadgeTooltip(props.updateStatus), rect.left + rect.width / 2, rect.top, {align: 'center',direction: 'up',});}}onMouseLeave={() => hideTooltip()}>- <svg- class="w-3 h-3"- fill="none"- viewBox="0 0 24 24"- stroke="currentColor"- stroke-width="2"- >- <path- stroke-linecap="round"- stroke-linejoin="round"- d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-8l-4-4m0 0L8 8m4-4v12"- />- </svg>+ <UpdateArrowIcon class="w-3 h-3" /><Show when={!props.compact}><span>Update</span></Show>@@ -108,55 +118,26 @@ export const ContainerUpdateBadge: Component<ContainerUpdateBadgeProps> = (props* Compact version of UpdateBadge - just an icon with no text.* Use this in table cells where space is limited.*/-export const UpdateIcon: Component<{ updateStatus?: DockerContainerUpdateStatus }> = (props) => {- const hasUpdate = () => props.updateStatus?.updateAvailable === true;-- const getTooltip = () => {- if (!props.updateStatus) return 'Image update available';-- const current = props.updateStatus.currentDigest?.slice(0, 12) || 'unknown';- const latest = props.updateStatus.latestDigest?.slice(0, 12) || 'unknown';-- return `Update available\nCurrent: ${current}...\nLatest: ${latest}...`;- };-+export const UpdateIcon: Component<UpdateIconProps> = (props) => {return (- <Show when={hasUpdate()}>+ <Show when={hasContainerUpdate(props.updateStatus)}><spanclass="inline-flex items-center justify-center w-5 h-5 rounded-full bg-blue-100 text-blue-700 dark:bg-blue-900 dark:text-blue-300 cursor-help"onMouseEnter={(e) => {const rect = e.currentTarget.getBoundingClientRect();- showTooltip(getTooltip(), rect.left + rect.width / 2, rect.top, {+ showTooltip(getUpdateIconTooltip(props.updateStatus), rect.left + rect.width / 2, rect.top, {align: 'center',direction: 'up',});}}onMouseLeave={() => hideTooltip()}>- <svg class="w-3 h-3" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">- <path- stroke-linecap="round"- stroke-linejoin="round"- d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-8l-4-4m0 0L8 8m4-4v12"- />- </svg>+ <UpdateArrowIcon class="w-3 h-3" /></span></Show>);};-interface UpdateButtonProps {- updateStatus?: DockerContainerUpdateStatus;- agentId: string;- containerId: string;- containerName: string;- compact?: boolean;- onUpdateTriggered?: () => void;- externalState?: 'updating' | 'queued' | 'error';-}--type UpdateState = 'idle' | 'confirming' | 'updating' | 'success' | 'error';-/*** UpdateButton displays a clickable button to trigger container updates.* Uses a persistent store to maintain state across WebSocket refreshes.@@ -169,283 +150,67 @@ type UpdateState = 'idle' | 'confirming' | 'updating' | 'success' | 'error';* to prevent premature clicks before the server configuration is known.*/export const UpdateButton: Component<UpdateButtonProps> = (props) => {- const [localState, setLocalState] = createSignal<'idle' | 'confirming'>('idle');- const [errorMessage, setErrorMessage] = createSignal<string>('');-- // Reactive check for whether settings are loaded and what they say- const settingsLoaded = () => areSystemSettingsLoaded();- const shouldHideButton = () => shouldHideDockerUpdateActions();-- // Get persistent state from store - this survives WebSocket updates- const storeState = createMemo(() => {- // Access updateStates() to create reactive dependency- updateStates();- return getContainerUpdateState(props.agentId, props.containerId);- });-- // Derived state: check store first, then external prop, then local state- const currentState = (): UpdateState => {- const stored = storeState();- if (stored) {- switch (stored.state) {- case 'queued':- case 'updating':- return 'updating';- case 'success':- return 'success';- case 'error':- return 'error';- }- }- if (props.externalState === 'updating') return 'updating';- if (props.externalState === 'queued') return 'updating';- if (props.externalState === 'error') return 'error';- return localState();- };-- // Watch for update completion - when updateAvailable becomes false, the update succeeded- createEffect(() => {- const stored = storeState();- if (stored && (stored.state === 'queued' || stored.state === 'updating')) {- // If the container no longer has an update available, the update succeeded!- if (props.updateStatus?.updateAvailable === false) {- markContainerUpdateSuccess(props.agentId, props.containerId);- }- }- });-- const hasUpdate = () => props.updateStatus?.updateAvailable === true || currentState() !== 'idle';-- const handleClick = async (e: MouseEvent) => {- e.stopPropagation();- e.preventDefault();-- const state = currentState();-- // Prevent clicking if already updating- if (state === 'updating' || state === 'success' || state === 'error') return;-- if (state === 'idle') {- // Show confirmation- setLocalState('confirming');- return;- }-- if (state === 'confirming') {- // User confirmed, trigger update- // Immediately set store state so it persists- markContainerQueued(props.agentId, props.containerId);- setLocalState('idle'); // Reset local state-- try {- await MonitoringAPI.updateDockerContainer(- props.agentId,- props.containerId,- props.containerName,- );- // Command queued successfully - store already has 'queued' state- // The effect above will detect when updateAvailable becomes false- props.onUpdateTriggered?.();- } catch (err) {- const message = (err as Error).message || 'Failed to trigger update';- setErrorMessage(message);- markContainerUpdateError(props.agentId, props.containerId, message);- }- }- };-- const handleCancel = (e: MouseEvent) => {- e.stopPropagation();- e.preventDefault();- setLocalState('idle');- // Also clear any store state if canceling- clearContainerUpdateState(props.agentId, props.containerId);- };-- const getButtonClass = () => {- const base =- 'inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-xs font-medium transition-all';- switch (currentState()) {- case 'confirming':- return `${base} bg-amber-100 text-amber-700 dark:bg-amber-900 dark:text-amber-300 cursor-pointer hover:bg-amber-200 dark:hover:bg-amber-900`;- case 'updating':- return `${base} bg-blue-100 text-blue-700 dark:bg-blue-900 dark:text-blue-300 cursor-wait`;- case 'success':- return `${base} bg-green-100 text-green-700 dark:bg-green-900 dark:text-green-300`;- case 'error':- return `${base} bg-red-100 text-red-700 dark:bg-red-900 dark:text-red-300 cursor-help`;- default:- return `${base} bg-blue-100 text-blue-700 dark:bg-blue-900 dark:text-blue-300 cursor-pointer hover:bg-blue-200 dark:hover:bg-blue-900`;- }- };-- const getTooltip = () => {- const stored = storeState();- switch (currentState()) {- case 'confirming':- return 'Click again to confirm update';- case 'updating': {- const elapsed = stored ? Math.round((Date.now() - stored.startedAt) / 1000) : 0;- // Show the current step if available from backend- const step = stored?.message || 'Processing...';- if (elapsed > 60) {- return `${step} (${Math.floor(elapsed / 60)}m ${elapsed % 60}s)`;- }- return `${step} (${elapsed}s)`;- }- case 'success':- return '✓ Update completed successfully!';- case 'error':- return `✗ Update failed: ${stored?.message || errorMessage() || 'Unknown error'}`;- default:- if (!props.updateStatus) return 'Update container';- const current = props.updateStatus.currentDigest?.slice(0, 12) || 'unknown';- const latest = props.updateStatus.latestDigest?.slice(0, 12) || 'unknown';- return `Click to update\nCurrent: ${current}...\nLatest: ${latest}...`;- }- };-- // Compute if the button should be disabled due to loading or settings- const isButtonDisabled = () => currentState() === 'updating' || !settingsLoaded();+ const state = useContainerUpdateButtonState(props);return (- <Show when={hasUpdate()}>- {/* Case 1: Settings loaded and updates are disabled - show read-only badge */}- <Show when={settingsLoaded() && shouldHideButton()}>+ <Show when={state.hasUpdate()}>+ <Show when={state.settingsLoaded() && state.shouldHideButton()}><ContainerUpdateBadge updateStatus={props.updateStatus} compact={props.compact} /></Show>- {/* Case 2: Settings loading OR settings loaded with updates enabled - show button */}- <Show when={!settingsLoaded() || !shouldHideButton()}>+ <Show when={!state.settingsLoaded() || !state.shouldHideButton()}><div class="inline-flex items-center gap-1" data-prevent-toggle><buttontype="button"- class={getButtonClass()}- onClick={handleClick}+ class={getUpdateButtonClass(state.currentState())}+ onClick={state.handleClick}onMouseDown={(e) => {e.stopPropagation();}}- disabled={isButtonDisabled()}+ disabled={state.isButtonDisabled()}data-prevent-toggleonMouseEnter={(e) => {const rect = e.currentTarget.getBoundingClientRect();- const tooltip = !settingsLoaded() ? 'Loading settings...' : getTooltip();- showTooltip(tooltip, rect.left + rect.width / 2, rect.top, {+ showTooltip(state.buttonTooltip(), rect.left + rect.width / 2, rect.top, {align: 'center',direction: 'up',});}}onMouseLeave={() => hideTooltip()}>- {/* Loading state - settings haven't loaded yet */}- <Show when={!settingsLoaded()}>- <svg- class="w-3 h-3 animate-pulse opacity-50"- fill="none"- viewBox="0 0 24 24"- stroke="currentColor"- stroke-width="2"- >- <path- stroke-linecap="round"- stroke-linejoin="round"- d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-8l-4-4m0 0L8 8m4-4v12"- />- </svg>+ <Show when={!state.settingsLoaded()}>+ <UpdateArrowIcon class="w-3 h-3 animate-pulse opacity-50" /></Show>- {/* Normal states - settings loaded */}- <Show when={settingsLoaded()}>- <Show when={currentState() === 'updating'}>- {/* Spinner */}- <svg class="w-3 h-3 animate-spin" fill="none" viewBox="0 0 24 24">- <circle- class="opacity-25"- cx="12"- cy="12"- r="10"- stroke="currentColor"- stroke-width="4"- />- <path- class="opacity-75"- fill="currentColor"- d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"- />- </svg>- </Show>- <Show when={currentState() === 'success'}>- {/* Check icon */}- <svg- class="w-3 h-3"- fill="none"- viewBox="0 0 24 24"- stroke="currentColor"- stroke-width="2"- >- <path stroke-linecap="round" stroke-linejoin="round" d="M5 13l4 4L19 7" />- </svg>- </Show>- <Show when={currentState() === 'error'}>- {/* X icon */}- <svg- class="w-3 h-3"- fill="none"- viewBox="0 0 24 24"- stroke="currentColor"- stroke-width="2"- >- <path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" />- </svg>- </Show>- <Show when={currentState() === 'idle' || currentState() === 'confirming'}>- {/* Upload/update icon */}- <svg- class="w-3 h-3"- fill="none"- viewBox="0 0 24 24"- stroke="currentColor"- stroke-width="2"- >- <path- stroke-linecap="round"- stroke-linejoin="round"- d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-8l-4-4m0 0L8 8m4-4v12"- />- </svg>- </Show>+ <Show when={state.settingsLoaded()}>+ <Switch>+ <Match when={state.currentState() === 'updating'}>+ <SpinnerIcon class="w-3 h-3 animate-spin" />+ </Match>+ <Match when={state.currentState() === 'success'}>+ <CheckIcon class="w-3 h-3" />+ </Match>+ <Match when={state.currentState() === 'error'}>+ <XIcon class="w-3 h-3" />+ </Match>+ <Match when={state.currentState() === 'idle' || state.currentState() === 'confirming'}>+ <UpdateArrowIcon class="w-3 h-3" />+ </Match>+ </Switch></Show><Show when={!props.compact}>- <span class={!settingsLoaded() ? 'opacity-50' : ''}>- {!settingsLoaded()- ? 'Update'- : currentState() === 'confirming'- ? 'Confirm?'- : currentState() === 'updating'- ? 'Updating...'- : currentState() === 'success'- ? 'Queued!'- : currentState() === 'error'- ? 'Failed'- : 'Update'}+ <span class={!state.settingsLoaded() ? 'opacity-50' : ''}>+ {state.buttonLabel()}</span></Show></button>- <Show when={settingsLoaded() && currentState() === 'confirming'}>+ <Show when={state.settingsLoaded() && state.currentState() === 'confirming'}><buttontype="button"class="inline-flex items-center justify-center w-5 h-5 rounded-full bg-surface-alt text-muted hover:bg-surface-hover transition-colors"- onClick={handleCancel}+ onClick={state.handleCancel}title="Cancel">- <svg- class="w-3 h-3"- fill="none"- viewBox="0 0 24 24"- stroke="currentColor"- stroke-width="2"- >- <path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" />- </svg>+ <XIcon class="w-3 h-3" /></button></Show></div>diff --git a/frontend-modern/src/components/shared/SharedPrimitives.guardrails.test.ts b/frontend-modern/src/components/shared/SharedPrimitives.guardrails.test.tsindex df07a272da..25e982069f 100644--- a/frontend-modern/src/components/shared/SharedPrimitives.guardrails.test.ts+++ b/frontend-modern/src/components/shared/SharedPrimitives.guardrails.test.ts@@ -1,5 +1,7 @@import { describe, expect, it } from 'vitest';import calloutCardSource from '@/components/shared/CalloutCard.tsx?raw';+import containerUpdateBadgeSource from '@/components/shared/ContainerUpdateBadge.tsx?raw';+import containerUpdateBadgeModelSource from '@/components/shared/containerUpdateBadgeModel.ts?raw';import filterButtonGroupSource from '@/components/shared/FilterButtonGroup.tsx?raw';import historyChartSource from '@/components/shared/HistoryChart.tsx?raw';import historyChartModelSource from '@/components/shared/historyChartModel.ts?raw';@@ -12,6 +14,7 @@ import infrastructureSummaryTableStateSource from '@/components/shared/useInfrasimport monitoredSystemLimitWarningBannerSource from '@/components/shared/MonitoredSystemLimitWarningBanner.tsx?raw';import selectionCardGroupSource from '@/components/shared/SelectionCardGroup.tsx?raw';import tagBadgesSource from '@/components/shared/TagBadges.tsx?raw';+import containerUpdateButtonStateSource from '@/components/shared/useContainerUpdateButtonState.ts?raw';import historyChartStateSource from '@/components/shared/useHistoryChartState.ts?raw';import interactiveSparklineStateSource from '@/components/shared/useInteractiveSparklineState.ts?raw';import guestRowSource from '@/components/Dashboard/GuestRow.tsx?raw';@@ -180,4 +183,23 @@ describe('shared primitive guardrails', () => {expect(historyChartModelSource).toContain('getHistoryChartScale');expect(historyChartModelSource).toContain('findHistoryChartClosestPoint');});++ it('keeps container update badge on shell, runtime, and model owners', () => {+ expect(containerUpdateBadgeSource).toContain('useContainerUpdateButtonState');+ expect(containerUpdateBadgeSource).toContain('getUpdateButtonClass');+ expect(containerUpdateBadgeSource).not.toContain('MonitoringAPI.updateDockerContainer');+ expect(containerUpdateBadgeSource).not.toContain('markContainerQueued');+ expect(containerUpdateBadgeSource).not.toContain('createSignal');++ expect(containerUpdateButtonStateSource).toContain('MonitoringAPI.updateDockerContainer');+ expect(containerUpdateButtonStateSource).toContain('markContainerQueued');+ expect(containerUpdateButtonStateSource).toContain('createSignal');+ expect(containerUpdateButtonStateSource).toContain(+ 'export function useContainerUpdateButtonState',+ );++ expect(containerUpdateBadgeModelSource).toContain('getUpdateButtonClass');+ expect(containerUpdateBadgeModelSource).toContain('getUpdateButtonTooltip');+ expect(containerUpdateBadgeModelSource).toContain('hasContainerUpdate');+ });});diff --git a/frontend-modern/src/components/shared/__tests__/ContainerUpdateBadge.test.tsx b/frontend-modern/src/components/shared/__tests__/ContainerUpdateBadge.test.tsxnew file mode 100644index 0000000000..ac2e851190--- /dev/null+++ b/frontend-modern/src/components/shared/__tests__/ContainerUpdateBadge.test.tsx@@ -0,0 +1,84 @@+import { describe, expect, it, vi } from 'vitest';+import { render, screen } from '@solidjs/testing-library';+import containerUpdateBadgeSource from '@/components/shared/ContainerUpdateBadge.tsx?raw';+import containerUpdateBadgeModelSource from '@/components/shared/containerUpdateBadgeModel.ts?raw';+import containerUpdateButtonStateSource from '@/components/shared/useContainerUpdateButtonState.ts?raw';+import {+ ContainerUpdateBadge,+ UpdateButton,+} from '@/components/shared/ContainerUpdateBadge';++vi.mock('@/api/monitoring', () => ({+ MonitoringAPI: {+ updateDockerContainer: vi.fn().mockResolvedValue(undefined),+ },+}));++vi.mock('@/stores/containerUpdates', () => ({+ clearContainerUpdateState: vi.fn(),+ getContainerUpdateState: vi.fn(() => undefined),+ markContainerQueued: vi.fn(),+ markContainerUpdateError: vi.fn(),+ markContainerUpdateSuccess: vi.fn(),+ updateStates: vi.fn(() => ({})),+}));++vi.mock('@/stores/systemSettings', () => ({+ areSystemSettingsLoaded: () => true,+ shouldHideDockerUpdateActions: () => false,+}));++describe('ContainerUpdateBadge', () => {+ it('keeps the badge on shell, runtime, and model owners', () => {+ expect(containerUpdateBadgeSource).toContain('useContainerUpdateButtonState');+ expect(containerUpdateBadgeSource).toContain('getUpdateButtonClass');+ expect(containerUpdateBadgeSource).not.toContain('MonitoringAPI.updateDockerContainer');+ expect(containerUpdateBadgeSource).not.toContain('markContainerQueued');+ expect(containerUpdateBadgeSource).not.toContain('createSignal');++ expect(containerUpdateButtonStateSource).toContain(+ 'MonitoringAPI.updateDockerContainer',+ );+ expect(containerUpdateButtonStateSource).toContain('markContainerQueued');+ expect(containerUpdateButtonStateSource).toContain('createSignal');+ expect(containerUpdateButtonStateSource).toContain(+ 'export function useContainerUpdateButtonState',+ );++ expect(containerUpdateBadgeModelSource).toContain('getUpdateButtonClass');+ expect(containerUpdateBadgeModelSource).toContain('getUpdateButtonTooltip');+ expect(containerUpdateBadgeModelSource).toContain('hasContainerUpdate');+ });++ it('renders the error badge fallback when update detection fails', () => {+ render(() => (+ <ContainerUpdateBadge+ updateStatus={{+ updateAvailable: false,+ lastChecked: 0,+ error: 'request timed out',+ }}+ />+ ));++ expect(screen.getByText('Check failed')).toBeInTheDocument();+ });++ it('renders the update action button when an update is available', () => {+ render(() => (+ <UpdateButton+ agentId="agent-1"+ containerId="container-1"+ containerName="web"+ updateStatus={{+ updateAvailable: true,+ currentDigest: 'sha256:current',+ latestDigest: 'sha256:latest',+ lastChecked: 0,+ }}+ />+ ));++ expect(screen.getByRole('button', { name: /update/i })).toBeInTheDocument();+ });+});diff --git a/frontend-modern/src/components/shared/containerUpdateBadgeModel.ts b/frontend-modern/src/components/shared/containerUpdateBadgeModel.tsnew file mode 100644index 0000000000..01127a885d--- /dev/null+++ b/frontend-modern/src/components/shared/containerUpdateBadgeModel.ts@@ -0,0 +1,131 @@+import type { DockerContainerUpdateStatus } from '@/types/api';++export interface ContainerUpdateBadgeProps {+ updateStatus?: DockerContainerUpdateStatus;+ compact?: boolean;+}++export interface UpdateIconProps {+ updateStatus?: DockerContainerUpdateStatus;+}++export interface UpdateButtonProps {+ updateStatus?: DockerContainerUpdateStatus;+ agentId: string;+ containerId: string;+ containerName: string;+ compact?: boolean;+ onUpdateTriggered?: () => void;+ externalState?: 'updating' | 'queued' | 'error';+}++export type UpdateState = 'idle' | 'confirming' | 'updating' | 'success' | 'error';++export interface ContainerUpdateButtonStoreState {+ startedAt: number;+ message?: string;+}++const UPDATE_BUTTON_BASE_CLASS =+ 'inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-xs font-medium transition-all';++function getDigestPreview(digest: string | undefined, length: number): string {+ return digest?.slice(0, length) || 'unknown';+}++export function hasContainerUpdate(updateStatus?: DockerContainerUpdateStatus): boolean {+ return updateStatus?.updateAvailable === true;+}++export function hasContainerUpdateError(updateStatus?: DockerContainerUpdateStatus): boolean {+ return Boolean(updateStatus?.error);+}++export function getContainerUpdateErrorTooltip(+ updateStatus?: DockerContainerUpdateStatus,+): string {+ return `Update check failed: ${updateStatus?.error || 'Unknown error'}`;+}++export function getContainerUpdateBadgeTooltip(+ updateStatus?: DockerContainerUpdateStatus,+): string {+ const current = getDigestPreview(updateStatus?.currentDigest, 19);+ const latest = getDigestPreview(updateStatus?.latestDigest, 19);+ return `Image update available\nCurrent: ${current}...\nLatest: ${latest}...`;+}++export function getUpdateIconTooltip(updateStatus?: DockerContainerUpdateStatus): string {+ if (!updateStatus) return 'Image update available';++ const current = getDigestPreview(updateStatus.currentDigest, 12);+ const latest = getDigestPreview(updateStatus.latestDigest, 12);+ return `Update available\nCurrent: ${current}...\nLatest: ${latest}...`;+}++export function getUpdateButtonClass(state: UpdateState): string {+ switch (state) {+ case 'confirming':+ return `${UPDATE_BUTTON_BASE_CLASS} bg-amber-100 text-amber-700 dark:bg-amber-900 dark:text-amber-300 cursor-pointer hover:bg-amber-200 dark:hover:bg-amber-900`;+ case 'updating':+ return `${UPDATE_BUTTON_BASE_CLASS} bg-blue-100 text-blue-700 dark:bg-blue-900 dark:text-blue-300 cursor-wait`;+ case 'success':+ return `${UPDATE_BUTTON_BASE_CLASS} bg-green-100 text-green-700 dark:bg-green-900 dark:text-green-300`;+ case 'error':+ return `${UPDATE_BUTTON_BASE_CLASS} bg-red-100 text-red-700 dark:bg-red-900 dark:text-red-300 cursor-help`;+ default:+ return `${UPDATE_BUTTON_BASE_CLASS} bg-blue-100 text-blue-700 dark:bg-blue-900 dark:text-blue-300 cursor-pointer hover:bg-blue-200 dark:hover:bg-blue-900`;+ }+}++export function getUpdateButtonLabel(state: UpdateState, settingsLoaded: boolean): string {+ if (!settingsLoaded) return 'Update';++ switch (state) {+ case 'confirming':+ return 'Confirm?';+ case 'updating':+ return 'Updating...';+ case 'success':+ return 'Queued!';+ case 'error':+ return 'Failed';+ default:+ return 'Update';+ }+}++export function getUpdateButtonTooltip(options: {+ state: UpdateState;+ updateStatus?: DockerContainerUpdateStatus;+ storeState?: ContainerUpdateButtonStoreState;+ errorMessage?: string;+ now?: number;+}): string {+ const now = options.now ?? Date.now();++ switch (options.state) {+ case 'confirming':+ return 'Click again to confirm update';+ case 'updating': {+ const elapsed = options.storeState+ ? Math.round((now - options.storeState.startedAt) / 1000)+ : 0;+ const step = options.storeState?.message || 'Processing...';+ if (elapsed > 60) {+ return `${step} (${Math.floor(elapsed / 60)}m ${elapsed % 60}s)`;+ }+ return `${step} (${elapsed}s)`;+ }+ case 'success':+ return '✓ Update completed successfully!';+ case 'error':+ return `✗ Update failed: ${options.storeState?.message || options.errorMessage || 'Unknown error'}`;+ default:+ if (!options.updateStatus) return 'Update container';++ const current = getDigestPreview(options.updateStatus.currentDigest, 12);+ const latest = getDigestPreview(options.updateStatus.latestDigest, 12);+ return `Click to update\nCurrent: ${current}...\nLatest: ${latest}...`;+ }+}diff --git a/frontend-modern/src/components/shared/useContainerUpdateButtonState.ts b/frontend-modern/src/components/shared/useContainerUpdateButtonState.tsnew file mode 100644index 0000000000..7ded35a51f--- /dev/null+++ b/frontend-modern/src/components/shared/useContainerUpdateButtonState.ts@@ -0,0 +1,124 @@+import { createEffect, createMemo, createSignal } from 'solid-js';+import { MonitoringAPI } from '@/api/monitoring';+import {+ clearContainerUpdateState,+ getContainerUpdateState,+ markContainerQueued,+ markContainerUpdateError,+ markContainerUpdateSuccess,+ updateStates,+} from '@/stores/containerUpdates';+import { areSystemSettingsLoaded, shouldHideDockerUpdateActions } from '@/stores/systemSettings';+import {+ getUpdateButtonLabel,+ getUpdateButtonTooltip,+ hasContainerUpdate,+ type UpdateButtonProps,+ type UpdateState,+} from './containerUpdateBadgeModel';++export function useContainerUpdateButtonState(props: UpdateButtonProps) {+ const [localState, setLocalState] = createSignal<'idle' | 'confirming'>('idle');+ const [errorMessage, setErrorMessage] = createSignal('');++ const settingsLoaded = () => areSystemSettingsLoaded();+ const shouldHideButton = () => shouldHideDockerUpdateActions();++ const storeState = createMemo(() => {+ updateStates();+ return getContainerUpdateState(props.agentId, props.containerId);+ });++ const currentState = (): UpdateState => {+ const stored = storeState();+ if (stored) {+ switch (stored.state) {+ case 'queued':+ case 'updating':+ return 'updating';+ case 'success':+ return 'success';+ case 'error':+ return 'error';+ }+ }++ if (props.externalState === 'updating' || props.externalState === 'queued') return 'updating';+ if (props.externalState === 'error') return 'error';+ return localState();+ };++ createEffect(() => {+ const stored = storeState();+ if (stored && (stored.state === 'queued' || stored.state === 'updating')) {+ if (props.updateStatus?.updateAvailable === false) {+ markContainerUpdateSuccess(props.agentId, props.containerId);+ }+ }+ });++ const hasUpdate = () => hasContainerUpdate(props.updateStatus) || currentState() !== 'idle';+ const isButtonDisabled = () => currentState() === 'updating' || !settingsLoaded();+ const buttonTooltip = () =>+ !settingsLoaded()+ ? 'Loading settings...'+ : getUpdateButtonTooltip({+ state: currentState(),+ updateStatus: props.updateStatus,+ storeState: storeState(),+ errorMessage: errorMessage(),+ });+ const buttonLabel = () => getUpdateButtonLabel(currentState(), settingsLoaded());++ const handleClick = async (event: MouseEvent) => {+ event.stopPropagation();+ event.preventDefault();++ const state = currentState();+ if (state === 'updating' || state === 'success' || state === 'error') return;++ if (state === 'idle') {+ setLocalState('confirming');+ return;+ }++ if (state === 'confirming') {+ markContainerQueued(props.agentId, props.containerId);+ setLocalState('idle');++ try {+ await MonitoringAPI.updateDockerContainer(+ props.agentId,+ props.containerId,+ props.containerName,+ );+ props.onUpdateTriggered?.();+ } catch (error) {+ const message = (error as Error).message || 'Failed to trigger update';+ setErrorMessage(message);+ markContainerUpdateError(props.agentId, props.containerId, message);+ }+ }+ };++ const handleCancel = (event: MouseEvent) => {+ event.stopPropagation();+ event.preventDefault();+ setLocalState('idle');+ clearContainerUpdateState(props.agentId, props.containerId);+ };++ return {+ buttonLabel,+ buttonTooltip,+ currentState,+ handleCancel,+ handleClick,+ hasUpdate,+ isButtonDisabled,+ settingsLoaded,+ shouldHideButton,+ };+}++export type ContainerUpdateButtonState = ReturnType<typeof useContainerUpdateButtonState>;diff --git a/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts b/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.tsindex 7e982a3841..9973cee505 100644--- a/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts+++ b/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts@@ -8,6 +8,8 @@ import chartsApiSource from '@/api/charts.ts?raw';import investigateAlertButtonSource from '@/components/Alerts/InvestigateAlertButton.tsx?raw';import alertTargetTypesSource from '@/utils/alertTargetTypes.ts?raw';import resourceBadgesSource from '@/components/Infrastructure/resourceBadges.ts?raw';+import containerUpdateBadgeSource from '@/components/shared/ContainerUpdateBadge.tsx?raw';+import containerUpdateBadgeModelSource from '@/components/shared/containerUpdateBadgeModel.ts?raw';import historyChartSource from '@/components/shared/HistoryChart.tsx?raw';import historyChartModelSource from '@/components/shared/historyChartModel.ts?raw';import infrastructureSummaryTableSource from '@/components/shared/InfrastructureSummaryTable.tsx?raw';@@ -15,6 +17,7 @@ import infrastructureSummaryTableRowSource from '@/components/shared/Infrastructimport interactiveSparklineSource from '@/components/shared/InteractiveSparkline.tsx?raw';import interactiveSparklineModelSource from '@/components/shared/interactiveSparklineModel.ts?raw';import sharedInfrastructureSummaryTableModelSource from '@/components/shared/infrastructureSummaryTableModel.ts?raw';+import containerUpdateButtonStateSource from '@/components/shared/useContainerUpdateButtonState.ts?raw';import historyChartStateSource from '@/components/shared/useHistoryChartState.ts?raw';import interactiveSparklineStateSource from '@/components/shared/useInteractiveSparklineState.ts?raw';import infrastructureSummaryTableStateSource from '@/components/shared/useInfrastructureSummaryTableState.ts?raw';@@ -2646,6 +2649,14 @@ describe('frontend resource type boundaries', () => {expect(historyChartStateSource).toContain('setupCanvasDPR');expect(historyChartModelSource).toContain('formatHistoryChartTooltipValue');expect(historyChartModelSource).toContain('getHistoryChartScale');+ expect(containerUpdateBadgeSource).toContain('useContainerUpdateButtonState');+ expect(containerUpdateBadgeSource).toContain('getUpdateButtonClass');+ expect(containerUpdateBadgeSource).not.toContain('MonitoringAPI.updateDockerContainer');+ expect(containerUpdateBadgeSource).not.toContain('markContainerQueued');+ expect(containerUpdateButtonStateSource).toContain('MonitoringAPI.updateDockerContainer');+ expect(containerUpdateButtonStateSource).toContain('markContainerQueued');+ expect(containerUpdateBadgeModelSource).toContain('getUpdateButtonClass');+ expect(containerUpdateBadgeModelSource).toContain('getUpdateButtonTooltip');expect(useUnifiedResourcesSource).not.toContain('normalizeResourcePolicyAISafeSummary(');expect(useUnifiedResourcesSource).not.toContain('normalizeResourcePolicy(');expect(useUnifiedResourcesSource).not.toContain('const resolvePolicySensitivity =');