Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion PMOVES-DoX
Submodule PMOVES-DoX updated 161 files
2 changes: 1 addition & 1 deletion Pmoves-hyperdimensions
13 changes: 3 additions & 10 deletions pmoves/ui/app/dashboard/chat/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
type ChatMessage,
} from "../../../lib/realtimeClient";
import { logForDebugging, getErrorMessage } from "../../../lib/errorUtils";
import { AlertBanner } from "@/components/common";

type ConnectionStatus = 'connecting' | 'connected' | 'disconnected' | 'error';

Expand Down Expand Up @@ -330,16 +331,8 @@ export default function ChatDashboardPage() {
<div className="border-t border-neutral-200 p-4">
{/* Error banner */}
{errorMsg && (
<div className="mb-3 px-3 py-2 bg-red-50 border border-red-200 rounded-lg flex items-center justify-between">
<span className="text-sm text-red-700">{errorMsg}</span>
<button
type="button"
onClick={() => setErrorMsg(null)}
className="text-red-400 hover:text-red-600 text-lg leading-none"
aria-label="Dismiss error"
>
&times;
</button>
<div className="mb-3">
<AlertBanner message={errorMsg} variant="error" onDismiss={() => setErrorMsg(null)} />
</div>
)}
<form onSubmit={handleSend} className="flex gap-2">
Expand Down
33 changes: 3 additions & 30 deletions pmoves/ui/app/dashboard/ingestion-queue/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import {
type IngestionStatus,
type IngestionSourceType,
} from "../../../lib/realtimeClient";
import { formatTimeAgo } from "@/lib/timeUtils";
import { AlertBanner } from "@/components/common";

type ConnectionStatus = 'connecting' | 'connected' | 'disconnected' | 'error';

Expand Down Expand Up @@ -52,22 +54,6 @@ function formatDuration(seconds: number | null): string {
return `${mins}:${secs.toString().padStart(2, '0')}`;
}

function formatTimeAgo(dateStr: string): string {
const date = new Date(dateStr);
const now = new Date();
const diffMs = now.getTime() - date.getTime();
const diffMins = Math.floor(diffMs / 60000);

if (diffMins < 1) return 'just now';
if (diffMins < 60) return `${diffMins}m ago`;

const diffHours = Math.floor(diffMins / 60);
if (diffHours < 24) return `${diffHours}h ago`;

const diffDays = Math.floor(diffHours / 24);
return `${diffDays}d ago`;
}

export default function IngestionQueuePage() {
const [items, setItems] = useState<IngestionQueueItem[]>([]);
const [status, setStatus] = useState<ConnectionStatus>('connecting');
Expand Down Expand Up @@ -324,20 +310,7 @@ export default function IngestionQueuePage() {
<DashboardNavigation active="ingest" />

{/* Error Display */}
{error && (
<div className="rounded border border-red-300 bg-red-50 p-4 text-sm text-red-800" role="alert" aria-live="assertive">
<div className="flex items-center justify-between">
<span>{error}</span>
<button
onClick={() => setError(null)}
className="text-red-600 hover:text-red-800"
aria-label="Dismiss error"
>
×
</button>
</div>
</div>
)}
{error && <AlertBanner message={error} variant="error" onDismiss={() => setError(null)} />}

<header className="space-y-2">
<div className="flex items-center justify-between">
Expand Down
65 changes: 65 additions & 0 deletions pmoves/ui/components/common/AlertBanner.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/* ═══════════════════════════════════════════════════════════════════════════
Alert Banner Component
Reusable alert/notification banner with variants and dismiss functionality
═══════════════════════════════════════════════════════════════════════════ */

import type { HTMLAttributes } from "react";

export interface AlertBannerProps extends HTMLAttributes<HTMLDivElement> {
/** The message to display */
message: string;
/** Visual style variant */
variant?: "error" | "warning" | "success" | "info";
/** Optional dismiss callback */
onDismiss?: () => void;
}

const VARIANT_CLASSES: Record<NonNullable<AlertBannerProps["variant"]>, string> = {
error: "bg-red-50 border-red-300 text-red-800",
warning: "bg-amber-50 border-amber-300 text-amber-800",
success: "bg-green-50 border-green-300 text-green-800",
info: "bg-blue-50 border-blue-300 text-blue-800",
};

/**
* Reusable alert banner component for displaying notifications and errors.
* Supports multiple visual variants and an optional dismiss button.
*
* @example
* // Error with dismiss
* <AlertBanner message="Something went wrong" variant="error" onDismiss={() => setError(null)} />
*
* @example
* // Success without dismiss
* <AlertBanner message="Operation completed" variant="success" />
*/
export function AlertBanner({
message,
variant = "error",
onDismiss,
className,
...props
}: AlertBannerProps) {
const baseClasses = "rounded border p-4 text-sm flex items-center justify-between";
const variantClasses = VARIANT_CLASSES[variant];

return (
<div
className={`${baseClasses} ${variantClasses} ${className || ""}`}
role="alert"
aria-live="assertive"
{...props}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
>
<span>{message}</span>
{onDismiss && (
<button
onClick={onDismiss}
className="ml-4 hover:opacity-70 transition-opacity"
aria-label="Dismiss notification"
>
×
</button>
)}
</div>
);
}
114 changes: 114 additions & 0 deletions pmoves/ui/components/common/ConfirmDialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/* ═══════════════════════════════════════════════════════════════════════════
Confirmation Dialog Component
Reusable modal for confirming destructive or critical actions
═══════════════════════════════════════════════════════════════════════════ */

export interface ConfirmDialogProps {
/** Whether the dialog is visible */
isOpen: boolean;
/** Title displayed at the top of the dialog */
title: string;
/** Message explaining the action to be confirmed */
message: string;
/** Text for the confirm button (default: "Confirm") */
confirmLabel?: string;
/** Text for the cancel button (default: "Cancel") */
cancelLabel?: string;
/** Called when user confirms */
onConfirm: () => void;
/** Called when user cancels or closes */
onCancel: () => void;
/** Visual style for the confirm button */
variant?: "danger" | "warning" | "info";
}

const VARIANT_CLASSES: Record<
NonNullable<ConfirmDialogProps["variant"]>,
string
> = {
danger: "bg-red-600 hover:bg-red-700 focus:ring-red-500",
warning: "bg-amber-600 hover:bg-amber-700 focus:ring-amber-500",
info: "bg-blue-600 hover:bg-blue-700 focus:ring-blue-500",
};

/**
* Reusable confirmation modal for critical actions.
* Replaces the native confirm() with a customizable React component.
*
* @example
* // Dangerous action deletion
* <ConfirmDialog
* isOpen={showDialog}
* title="Delete Rule"
* message="Are you sure you want to delete this rule? This action cannot be undone."
* variant="danger"
* onConfirm={() => handleDelete()}
* onCancel={() => setShowDialog(false)}
* />
*/
export function ConfirmDialog({
isOpen,
title,
message,
confirmLabel = "Confirm",
cancelLabel = "Cancel",
onConfirm,
onCancel,
variant = "danger",
}: ConfirmDialogProps) {
if (!isOpen) return null;

const handleConfirm = () => {
onConfirm();
};

return (
<div
className="fixed inset-0 z-50 flex items-center justify-center"
role="dialog"
aria-modal="true"
aria-labelledby="confirm-dialog-title"
aria-describedby="confirm-dialog-message"
>
{/* Backdrop */}
<div
className="fixed inset-0 bg-black/50 transition-opacity"
onClick={onCancel}
aria-hidden="true"
/>

{/* Dialog */}
<div className="relative z-10 bg-white rounded-lg shadow-xl max-w-md w-full mx-4 p-6">
<h3
id="confirm-dialog-title"
className="text-lg font-medium text-neutral-900 mb-2"
>
{title}
</h3>
<p
id="confirm-dialog-message"
className="text-sm text-neutral-600 mb-6"
>
{message}
</p>

<div className="flex justify-end gap-3">
<button
type="button"
onClick={onCancel}
className="px-4 py-2 rounded border border-neutral-300 text-neutral-700 hover:bg-neutral-50 focus:outline-none focus:ring-2 focus:ring-neutral-300 focus:ring-offset-2"
>
{cancelLabel}
</button>
<button
type="button"
onClick={handleConfirm}
className={`px-4 py-2 rounded text-white focus:outline-none focus:ring-2 focus:ring-offset-2 ${VARIANT_CLASSES[variant]}`}
>
{confirmLabel}
</button>
</div>
</div>
</div>
);
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
10 changes: 10 additions & 0 deletions pmoves/ui/components/common/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* ═══════════════════════════════════════════════════════════════════════════
Common Components Barrel Export
Shared UI components used across the application
═══════════════════════════════════════════════════════════════════════════ */

export { AlertBanner } from "./AlertBanner";
export type { AlertBannerProps } from "./AlertBanner";

export { ConfirmDialog } from "./ConfirmDialog";
export type { ConfirmDialogProps } from "./ConfirmDialog";
30 changes: 20 additions & 10 deletions pmoves/ui/components/ingestion/ApprovalRulesConfig.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,6 @@ describe('ApprovalRulesConfig', () => {

beforeEach(() => {
jest.clearAllMocks();
// Mock window.confirm
global.confirm = jest.fn(() => true);
});

afterEach(() => {
jest.restoreAllMocks();
});

describe('Rules list display', () => {
Expand Down Expand Up @@ -308,16 +302,23 @@ describe('ApprovalRulesConfig', () => {
/>
);

// Click the first delete button in the rules list
const deleteButtons = screen.getAllByText('Delete');
fireEvent.click(deleteButtons[0]);

expect(global.confirm).toHaveBeenCalledWith('Are you sure you want to delete this rule?');
// ConfirmDialog should be visible
expect(screen.getByText('Delete Rule')).toBeInTheDocument();

// Click confirm button - get the button inside the dialog (after the title)
const dialogTitle = screen.getByText('Delete Rule');
const dialogParent = dialogTitle.closest('div[role="dialog"]');
const confirmButton = dialogParent?.querySelector('button:last-child');
if (confirmButton) fireEvent.click(confirmButton);

expect(mockOnDeleteRule).toHaveBeenCalledWith('rule1');
});

it('should not delete rule when confirmation cancelled', () => {
global.confirm = jest.fn(() => false);

render(
<ApprovalRulesConfig
rules={mockRules}
Expand All @@ -327,10 +328,19 @@ describe('ApprovalRulesConfig', () => {
/>
);

// Click the first delete button in the rules list
const deleteButtons = screen.getAllByText('Delete');
fireEvent.click(deleteButtons[0]);

expect(global.confirm).toHaveBeenCalled();
// ConfirmDialog should be visible
expect(screen.getByText('Delete Rule')).toBeInTheDocument();

// Click cancel button - get the first button inside the dialog
const dialogTitle = screen.getByText('Delete Rule');
const dialogParent = dialogTitle.closest('div[role="dialog"]');
const cancelButton = dialogParent?.querySelector('button:first-child');
if (cancelButton) fireEvent.click(cancelButton);

expect(mockOnDeleteRule).not.toHaveBeenCalled();
});
});
Expand Down
Loading
Loading