Skip to content

armgit / Pulse

Public Imported from GitHub
0

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.

Canonicalize command copy buttons

rcourtman4d5ee10ef7b1
diff --git a/frontend-modern/scripts/shared-template-registry.json b/frontend-modern/scripts/shared-template-registry.json
index 53b0459a98..37607caf94 100644
--- a/frontend-modern/scripts/shared-template-registry.json
+++ b/frontend-modern/scripts/shared-template-registry.json
@@ -194,6 +194,7 @@
{ "path": "src/components/Settings/AgentProfilesPanel.tsx" },
{ "path": "src/components/Settings/AvailabilitySettingsPanel.tsx" },
{ "path": "src/components/Settings/ConnectionEditor/ConnectionEditor.tsx" },
+ { "path": "src/components/Settings/CopyCommandBlock.tsx" },
{ "path": "src/components/Settings/DataHandlingPanel.tsx" },
{ "path": "src/components/Settings/InfrastructureAgentUpdatesDialog.tsx" },
{ "path": "src/components/Settings/InfrastructureDiscoverySettingsDialog.tsx" },
@@ -1065,6 +1066,30 @@
"scripts/shared-template-audit.mjs"
]
},
+ {
+ "id": "button-command-copy-local-shell",
+ "category": "action-button",
+ "summary": "Command-copy controls must not recreate the absolute top-right icon-button shell; use CommandCopyButton from the shared Button primitive family.",
+ "canonical": {
+ "path": "src/components/shared/Button.tsx",
+ "export": "CommandCopyButton"
+ },
+ "scopes": ["src/components", "src/features", "src/pages"],
+ "extensions": [".tsx"],
+ "allPatterns": [
+ "absolute right-2 top-2",
+ "items-center justify-center",
+ "bg-surface-hover p-2"
+ ],
+ "legacyReason": "Retired migration debt. Command-copy icon buttons belong to CommandCopyButton so position, sizing, icon, focus, disabled, and aria behavior stay canonical.",
+ "allowedPaths": [],
+ "ignoredPaths": ["src/components/shared/Button.test.tsx"],
+ "proof": [
+ "src/components/shared/SharedPrimitives.guardrails.test.ts",
+ "src/components/shared/Button.test.tsx",
+ "scripts/shared-template-audit.mjs"
+ ]
+ },
{
"id": "button-secondary-settings-action-local-shell",
"category": "action-button",
diff --git a/frontend-modern/src/components/Settings/CopyCommandBlock.tsx b/frontend-modern/src/components/Settings/CopyCommandBlock.tsx
index b5ae36f572..617a9bc4f2 100644
--- a/frontend-modern/src/components/Settings/CopyCommandBlock.tsx
+++ b/frontend-modern/src/components/Settings/CopyCommandBlock.tsx
@@ -1,4 +1,4 @@
-import Copy from 'lucide-solid/icons/copy';
+import { CommandCopyButton } from '@/components/shared/Button';
interface CopyCommandBlockProps {
command: string;
@@ -11,8 +11,6 @@ interface CopyCommandBlockProps {
const DEFAULT_CONTAINER_CLASS = 'relative group';
const DEFAULT_CODE_CLASS =
'block rounded-md border border-border bg-base p-3 font-mono text-sm text-base-content';
-const DEFAULT_BUTTON_CLASS =
- 'absolute right-2 top-2 inline-flex min-h-9 min-w-9 items-center justify-center rounded bg-surface-hover p-2 text-slate-300 opacity-70 transition-opacity hover:bg-slate-600 hover:opacity-100';
export function CopyCommandBlock(props: CopyCommandBlockProps) {
const handleCopy = () => {
@@ -26,15 +24,12 @@ export function CopyCommandBlock(props: CopyCommandBlockProps) {
return (
<div class={props.containerClass ?? DEFAULT_CONTAINER_CLASS}>
<code class={props.codeClass ?? DEFAULT_CODE_CLASS}>{props.command}</code>
- <button
- type="button"
+ <CommandCopyButton
onClick={handleCopy}
- class={props.buttonClass ?? DEFAULT_BUTTON_CLASS}
+ class={props.buttonClass}
title="Copy to clipboard"
- aria-label="Copy to clipboard"
- >
- <Copy class="h-4 w-4" />
- </button>
+ label="Copy to clipboard"
+ />
</div>
);
}
diff --git a/frontend-modern/src/components/Settings/InfrastructureAgentUpdatesDialog.tsx b/frontend-modern/src/components/Settings/InfrastructureAgentUpdatesDialog.tsx
index eb7287fcec..a0b96298d9 100644
--- a/frontend-modern/src/components/Settings/InfrastructureAgentUpdatesDialog.tsx
+++ b/frontend-modern/src/components/Settings/InfrastructureAgentUpdatesDialog.tsx
@@ -1,7 +1,7 @@
import { For, Show, createMemo, type Component } from 'solid-js';
-import { Copy, X } from 'lucide-solid';
+import { X } from 'lucide-solid';
import { Dialog } from '@/components/shared/Dialog';
-import { Button } from '@/components/shared/Button';
+import { Button, CommandCopyButton } from '@/components/shared/Button';
import { copyToClipboard } from '@/utils/clipboard';
import { notificationStore } from '@/stores/notifications';
import {
@@ -17,9 +17,6 @@ interface InfrastructureAgentUpdatesDialogProps {
onClose: () => void;
}
-const copyButtonClass =
- 'absolute right-2 top-2 inline-flex min-h-10 min-w-10 items-center justify-center rounded-md bg-surface-hover p-2 text-muted transition-colors hover:text-base-content disabled:cursor-not-allowed disabled:opacity-50 sm:min-h-9 sm:min-w-9';
-
export const InfrastructureAgentUpdatesDialog: Component<InfrastructureAgentUpdatesDialogProps> = (
props,
) => {
@@ -191,15 +188,11 @@ export const InfrastructureAgentUpdatesDialog: Component<InfrastructureAgentUpda
}
>
<div class="relative">
- <button
- type="button"
+ <CommandCopyButton
onClick={() => void copyCommand(command())}
- class={copyButtonClass}
title="Copy update command"
- aria-label={`Copy update command for ${target.displayName}`}
- >
- <Copy class="h-4 w-4" />
- </button>
+ label={`Copy update command for ${target.displayName}`}
+ />
<pre class="overflow-x-auto rounded-md bg-base p-3 pr-12 text-xs text-base-content">
<code>{command()}</code>
</pre>
diff --git a/frontend-modern/src/components/Settings/InfrastructureInstallerSection.tsx b/frontend-modern/src/components/Settings/InfrastructureInstallerSection.tsx
index 9328ce7cec..01b162026d 100644
--- a/frontend-modern/src/components/Settings/InfrastructureInstallerSection.tsx
+++ b/frontend-modern/src/components/Settings/InfrastructureInstallerSection.tsx
@@ -1,6 +1,6 @@
import type { Component } from 'solid-js';
import { For, Show, createEffect, createMemo, createSignal } from 'solid-js';
-import { Button } from '@/components/shared/Button';
+import { Button, CommandCopyButton } from '@/components/shared/Button';
import { FormSelect } from '@/components/shared/FormSelect';
import SettingsPanel from '@/components/shared/SettingsPanel';
import { copyToClipboard } from '@/utils/clipboard';
@@ -649,8 +649,7 @@ export const InfrastructureInstallerSection: Component<InfrastructureInstallerSe
{snippet.label}
</h6>
<div class="relative">
- <button
- type="button"
+ <CommandCopyButton
onClick={async () => {
const success = await copyToClipboard(copyCommand());
if (success) {
@@ -663,21 +662,9 @@ export const InfrastructureInstallerSection: Component<InfrastructureInstallerSe
);
}
}}
- class="absolute right-2 top-2 inline-flex min-h-10 min-w-10 items-center justify-center rounded-md bg-surface-hover p-2 transition-colors hover:text-slate-200 sm:min-h-9 sm:min-w-9"
title="Copy command"
- >
- <svg
- width="16"
- height="16"
- viewBox="0 0 24 24"
- fill="none"
- stroke="currentColor"
- stroke-width="2"
- >
- <rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect>
- <path d="M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"></path>
- </svg>
- </button>
+ label={`Copy ${snippet.label} command`}
+ />
<pre class="overflow-x-auto rounded-md bg-base p-3 pr-12 text-xs text-base-content">
<code>{copyCommand()}</code>
</pre>
@@ -875,8 +862,7 @@ export const InfrastructureInstallerSection: Component<InfrastructureInstallerSe
<div class="space-y-1">
<span class="text-xs font-medium text-muted">Linux / macOS / FreeBSD</span>
<div class="relative">
- <button
- type="button"
+ <CommandCopyButton
onClick={async () => {
const success = await copyToClipboard(state.getUninstallCommand());
if (success) {
@@ -885,21 +871,9 @@ export const InfrastructureInstallerSection: Component<InfrastructureInstallerSe
notificationStore.error(getUnifiedAgentClipboardCopyErrorMessage());
}
}}
- class="absolute right-2 top-2 inline-flex min-h-10 min-w-10 items-center justify-center rounded-md bg-surface-hover p-2 text-slate-400 transition-colors hover:bg-slate-700 hover:text-slate-200 sm:min-h-9 sm:min-w-9"
title="Copy command"
- >
- <svg
- width="16"
- height="16"
- viewBox="0 0 24 24"
- fill="none"
- stroke="currentColor"
- stroke-width="2"
- >
- <rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect>
- <path d="M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"></path>
- </svg>
- </button>
+ label="Copy Linux macOS FreeBSD uninstall command"
+ />
<pre class="overflow-x-auto rounded-md bg-slate-950 p-3 pr-12 font-mono text-xs text-red-400">
<code>{state.getUninstallCommand()}</code>
</pre>
@@ -925,8 +899,7 @@ export const InfrastructureInstallerSection: Component<InfrastructureInstallerSe
Windows (PowerShell as Administrator)
</span>
<div class="relative">
- <button
- type="button"
+ <CommandCopyButton
onClick={async () => {
const success = await copyToClipboard(state.getWindowsUninstallCommand());
if (success) {
@@ -935,21 +908,9 @@ export const InfrastructureInstallerSection: Component<InfrastructureInstallerSe
notificationStore.error(getUnifiedAgentClipboardCopyErrorMessage());
}
}}
- class="absolute right-2 top-2 inline-flex min-h-10 min-w-10 items-center justify-center rounded-md bg-surface-hover p-2 text-slate-400 transition-colors hover:bg-slate-700 hover:text-slate-200 sm:min-h-9 sm:min-w-9"
title="Copy command"
- >
- <svg
- width="16"
- height="16"
- viewBox="0 0 24 24"
- fill="none"
- stroke="currentColor"
- stroke-width="2"
- >
- <rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect>
- <path d="M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"></path>
- </svg>
- </button>
+ label="Copy Windows uninstall command"
+ />
<pre class="overflow-x-auto rounded-md bg-slate-950 p-3 pr-12 font-mono text-xs text-red-400">
<code>{state.getWindowsUninstallCommand()}</code>
</pre>
diff --git a/frontend-modern/src/components/shared/Button.test.tsx b/frontend-modern/src/components/shared/Button.test.tsx
index 0822ce01c2..339391042f 100644
--- a/frontend-modern/src/components/shared/Button.test.tsx
+++ b/frontend-modern/src/components/shared/Button.test.tsx
@@ -1,7 +1,7 @@
import { Route, Router } from '@solidjs/router';
import { cleanup, render, screen } from '@solidjs/testing-library';
import { afterEach, describe, expect, it, vi } from 'vitest';
-import { Button, ButtonLink } from './Button';
+import { Button, ButtonLink, CommandCopyButton } from './Button';
import buttonSource from './Button.tsx?raw';
import buttonModelSource from './buttonModel.ts?raw';
@@ -52,6 +52,26 @@ describe('Button', () => {
expect(screen.getByRole('button', { name: 'Refresh' })).toBeDisabled();
});
+ it('renders command-copy icon buttons through the shared primitive', () => {
+ const onClick = vi.fn();
+
+ render(() => <CommandCopyButton onClick={onClick} label="Copy install command" />);
+
+ const button = screen.getByRole('button', { name: 'Copy install command' });
+ expect(button).toHaveAttribute('type', 'button');
+ expect(button).toHaveAttribute('title', 'Copy install command');
+ expect(button).toHaveClass('absolute');
+ expect(button).toHaveClass('right-2');
+ expect(button).toHaveClass('top-2');
+ expect(button).toHaveClass('min-h-10');
+ expect(button).toHaveClass('min-w-10');
+ expect(button).toHaveClass('bg-surface-hover');
+ expect(button).toHaveClass('p-2');
+
+ button.click();
+ expect(onClick).toHaveBeenCalledTimes(1);
+ });
+
it('renders in-app button links through the router', () => {
render(() => (
<Router>
diff --git a/frontend-modern/src/components/shared/Button.tsx b/frontend-modern/src/components/shared/Button.tsx
index de1c9d6190..3a462258d9 100644
--- a/frontend-modern/src/components/shared/Button.tsx
+++ b/frontend-modern/src/components/shared/Button.tsx
@@ -1,4 +1,5 @@
import { A } from '@solidjs/router';
+import CopyIcon from 'lucide-solid/icons/copy';
import { JSX, Show, mergeProps, splitProps } from 'solid-js';
import { getButtonClass, type ButtonSize, type ButtonVariant } from './buttonModel';
@@ -17,6 +18,11 @@ export interface ButtonLinkProps extends JSX.AnchorHTMLAttributes<HTMLAnchorElem
hardNavigation?: boolean;
}
+export interface CommandCopyButtonProps
+ extends Omit<ButtonProps, 'children' | 'isLoading' | 'size' | 'variant'> {
+ label?: string;
+}
+
export function Button(props: ButtonProps) {
const merged = mergeProps(
{ variant: 'secondary' as ButtonVariant, size: 'md' as ButtonSize, type: 'button' as const },
@@ -68,6 +74,29 @@ export function Button(props: ButtonProps) {
);
}
+export function CommandCopyButton(props: CommandCopyButtonProps) {
+ const merged = mergeProps({ label: 'Copy command', type: 'button' as const }, props);
+ const [local, rest] = splitProps(merged, ['label', 'class', 'title', 'aria-label']);
+
+ return (
+ <Button
+ {...rest}
+ variant="ghost"
+ size="icon"
+ class={[
+ 'absolute right-2 top-2 min-h-10 min-w-10 bg-surface-hover text-muted hover:text-base-content sm:min-h-9 sm:min-w-9',
+ local.class,
+ ]
+ .filter(Boolean)
+ .join(' ')}
+ title={local.title ?? local.label}
+ aria-label={local['aria-label'] ?? local.label}
+ >
+ <CopyIcon class="h-4 w-4" />
+ </Button>
+ );
+}
+
export function ButtonLink(props: ButtonLinkProps) {
const merged = mergeProps(
{ variant: 'secondary' as ButtonVariant, size: 'md' as ButtonSize },
diff --git a/frontend-modern/src/components/shared/SharedPrimitives.guardrails.test.ts b/frontend-modern/src/components/shared/SharedPrimitives.guardrails.test.ts
index 362a4f1832..db04047466 100644
--- a/frontend-modern/src/components/shared/SharedPrimitives.guardrails.test.ts
+++ b/frontend-modern/src/components/shared/SharedPrimitives.guardrails.test.ts
@@ -108,6 +108,7 @@ import webhookConfigFormSource from '@/components/Alerts/WebhookConfigForm.tsx?r
import reportMergeModalSource from '@/components/Infrastructure/ReportMergeModal.tsx?raw';
import availabilitySettingsPanelSource from '@/components/Settings/AvailabilitySettingsPanel.tsx?raw';
import connectionEditorSource from '@/components/Settings/ConnectionEditor/ConnectionEditor.tsx?raw';
+import copyCommandBlockSource from '@/components/Settings/CopyCommandBlock.tsx?raw';
import infrastructureAgentUpdatesDialogSource from '@/components/Settings/InfrastructureAgentUpdatesDialog.tsx?raw';
import infrastructureDiscoverySettingsDialogSource from '@/components/Settings/InfrastructureDiscoverySettingsDialog.tsx?raw';
import selfHostedCommercialRecoverySectionSource from '@/components/Settings/SelfHostedCommercialRecoverySection.tsx?raw';
@@ -1511,6 +1512,9 @@ describe('shared primitive guardrails', () => {
const registeredGuard = registry.patternGuards?.find(
(guard) => guard.id === 'button-secondary-command-local-shell',
);
+ const commandCopyGuard = registry.patternGuards?.find(
+ (guard) => guard.id === 'button-command-copy-local-shell',
+ );
const settingsActionGuard = registry.patternGuards?.find(
(guard) => guard.id === 'button-secondary-settings-action-local-shell',
);
@@ -1529,6 +1533,7 @@ describe('shared primitive guardrails', () => {
'src/components/Settings/AgentProfilesPanel.tsx',
'src/components/Settings/AvailabilitySettingsPanel.tsx',
'src/components/Settings/ConnectionEditor/ConnectionEditor.tsx',
+ 'src/components/Settings/CopyCommandBlock.tsx',
'src/components/Settings/DataHandlingPanel.tsx',
'src/components/Settings/InfrastructureAgentUpdatesDialog.tsx',
'src/components/Settings/InfrastructureDiscoverySettingsDialog.tsx',
@@ -1546,6 +1551,16 @@ describe('shared primitive guardrails', () => {
expect(registeredGuard?.scopes).toEqual(['src/components', 'src/features', 'src/pages']);
expect(registeredGuard?.allowedPaths ?? []).toHaveLength(0);
expect(registeredGuard?.ignoredPaths).toEqual(['src/components/shared/Button.test.tsx']);
+ expect(commandCopyGuard?.canonical?.path).toBe('src/components/shared/Button.tsx');
+ expect(commandCopyGuard?.canonical?.export).toBe('CommandCopyButton');
+ expect(commandCopyGuard?.allPatterns).toEqual([
+ 'absolute right-2 top-2',
+ 'items-center justify-center',
+ 'bg-surface-hover p-2',
+ ]);
+ expect(commandCopyGuard?.scopes).toEqual(['src/components', 'src/features', 'src/pages']);
+ expect(commandCopyGuard?.allowedPaths ?? []).toHaveLength(0);
+ expect(commandCopyGuard?.ignoredPaths).toEqual(['src/components/shared/Button.test.tsx']);
expect(settingsActionGuard?.canonical?.path).toBe('src/components/shared/buttonModel.ts');
expect(settingsActionGuard?.canonical?.export).toBe('getButtonClass');
expect(settingsActionGuard?.allPatterns).toEqual([
@@ -1588,6 +1603,7 @@ describe('shared primitive guardrails', () => {
]);
expect(buttonSource).toContain('export function Button');
+ expect(buttonSource).toContain('export function CommandCopyButton');
expect(buttonSource).toContain('export function ButtonLink');
expect(buttonSource).toContain('getButtonClass');
expect(buttonModelSource).toContain('BUTTON_VARIANT_CLASSES');
@@ -1618,16 +1634,26 @@ describe('shared primitive guardrails', () => {
expect(connectionEditorSource).not.toContain(
'rounded-md border border-border px-2.5 py-1 text-xs font-medium text-base-content',
);
+ expect(copyCommandBlockSource).toContain('@/components/shared/Button');
+ expect(copyCommandBlockSource).toContain('CommandCopyButton');
+ expect(copyCommandBlockSource).not.toContain('absolute right-2 top-2');
+ expect(copyCommandBlockSource).not.toContain('bg-surface-hover p-2');
expect(dataHandlingPanelSource).toContain('@/components/shared/Button');
expect(dataHandlingPanelSource).toContain('ButtonLink');
expect(dataHandlingPanelSource).not.toContain(
'rounded-md border border-border bg-surface px-3 py-2 text-sm font-medium text-base-content',
);
expect(infrastructureInstallerSectionSource).toContain('@/components/shared/Button');
+ expect(infrastructureInstallerSectionSource).toContain('CommandCopyButton');
expect(infrastructureInstallerSectionSource).not.toContain(
'rounded-md border border-border bg-surface px-3 py-2 text-sm font-medium text-base-content',
);
+ expect(infrastructureInstallerSectionSource).not.toContain('absolute right-2 top-2');
+ expect(infrastructureInstallerSectionSource).not.toContain('bg-surface-hover p-2');
expect(infrastructureAgentUpdatesDialogSource).toContain('@/components/shared/Button');
+ expect(infrastructureAgentUpdatesDialogSource).toContain('CommandCopyButton');
+ expect(infrastructureAgentUpdatesDialogSource).not.toContain('absolute right-2 top-2');
+ expect(infrastructureAgentUpdatesDialogSource).not.toContain('bg-surface-hover p-2');
expect(infrastructureAgentUpdatesDialogSource).not.toContain(
'h-9 w-9 items-center justify-center rounded-md border border-border text-base-content transition-colors hover:bg-surface-hover',
);