2025-11-23 18:23:51 +01:00
|
|
|
'use client';
|
|
|
|
|
|
2025-11-23 19:50:17 +01:00
|
|
|
import { useState, useCallback, useRef, useEffect } from 'react';
|
2025-11-23 18:23:51 +01:00
|
|
|
import { useProcesses } from '@/lib/hooks/useSupervisor';
|
|
|
|
|
import { ProcessCard } from '@/components/process/ProcessCard';
|
feat: implement Phase 2 - Process Groups Management
Features added:
- Group-based process organization with collapsible cards
- Batch operations for groups (Start All, Stop All, Restart All)
- Group statistics display (running, stopped, fatal counts)
- Dedicated /groups page for group-centric management
- View toggle in /processes page (Flat view | Grouped view)
Implementation details:
- Created group API routes: /api/supervisor/groups/[name]/{start,stop,restart}
- Added React Query hooks: useStartProcessGroup, useStopProcessGroup, useRestartProcessGroup
- Created components: GroupCard, GroupView, GroupSelector
- Updated Navbar with Groups navigation link
- Integrated grouped view in processes page with toggle
Phase 2 complete (6-8 hours estimated)
2025-11-23 19:08:10 +01:00
|
|
|
import { GroupView } from '@/components/groups/GroupView';
|
|
|
|
|
import { GroupSelector } from '@/components/groups/GroupSelector';
|
2025-11-23 19:14:04 +01:00
|
|
|
import { BatchActions } from '@/components/process/BatchActions';
|
2025-11-23 19:29:23 +01:00
|
|
|
import { ProcessFilters } from '@/components/process/ProcessFilters';
|
2025-11-23 19:50:17 +01:00
|
|
|
import { RefreshCw, AlertCircle, CheckSquare, Keyboard } from 'lucide-react';
|
2025-11-23 18:23:51 +01:00
|
|
|
import { Button } from '@/components/ui/button';
|
2025-11-23 19:50:17 +01:00
|
|
|
import { useKeyboardShortcuts } from '@/lib/hooks/useKeyboardShortcuts';
|
|
|
|
|
import { KeyboardShortcutsHelp } from '@/components/ui/KeyboardShortcutsHelp';
|
2025-11-23 19:29:23 +01:00
|
|
|
import type { ProcessInfo } from '@/lib/supervisor/types';
|
2025-11-23 18:23:51 +01:00
|
|
|
|
|
|
|
|
export default function ProcessesPage() {
|
feat: implement Phase 2 - Process Groups Management
Features added:
- Group-based process organization with collapsible cards
- Batch operations for groups (Start All, Stop All, Restart All)
- Group statistics display (running, stopped, fatal counts)
- Dedicated /groups page for group-centric management
- View toggle in /processes page (Flat view | Grouped view)
Implementation details:
- Created group API routes: /api/supervisor/groups/[name]/{start,stop,restart}
- Added React Query hooks: useStartProcessGroup, useStopProcessGroup, useRestartProcessGroup
- Created components: GroupCard, GroupView, GroupSelector
- Updated Navbar with Groups navigation link
- Integrated grouped view in processes page with toggle
Phase 2 complete (6-8 hours estimated)
2025-11-23 19:08:10 +01:00
|
|
|
const [viewMode, setViewMode] = useState<'flat' | 'grouped'>('flat');
|
2025-11-23 19:14:04 +01:00
|
|
|
const [selectedProcesses, setSelectedProcesses] = useState<Set<string>>(new Set());
|
2025-11-23 19:29:23 +01:00
|
|
|
const [filteredProcesses, setFilteredProcesses] = useState<ProcessInfo[]>([]);
|
2025-11-23 19:50:17 +01:00
|
|
|
const [showShortcutsHelp, setShowShortcutsHelp] = useState(false);
|
|
|
|
|
const [focusedIndex, setFocusedIndex] = useState<number>(-1);
|
|
|
|
|
const searchInputRef = useRef<HTMLInputElement>(null);
|
2025-11-23 18:23:51 +01:00
|
|
|
const { data: processes, isLoading, isError, refetch } = useProcesses();
|
|
|
|
|
|
2025-11-23 19:29:23 +01:00
|
|
|
const handleFilterChange = useCallback((filtered: ProcessInfo[]) => {
|
|
|
|
|
setFilteredProcesses(filtered);
|
|
|
|
|
}, []);
|
|
|
|
|
|
2025-11-23 19:14:04 +01:00
|
|
|
const handleSelectionChange = (processId: string, selected: boolean) => {
|
|
|
|
|
setSelectedProcesses((prev) => {
|
|
|
|
|
const newSet = new Set(prev);
|
|
|
|
|
if (selected) {
|
|
|
|
|
newSet.add(processId);
|
|
|
|
|
} else {
|
|
|
|
|
newSet.delete(processId);
|
|
|
|
|
}
|
|
|
|
|
return newSet;
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleSelectAll = () => {
|
2025-11-23 19:29:23 +01:00
|
|
|
const displayedProcesses = filteredProcesses.length > 0 ? filteredProcesses : (processes || []);
|
|
|
|
|
if (displayedProcesses) {
|
|
|
|
|
if (selectedProcesses.size === displayedProcesses.length) {
|
2025-11-23 19:14:04 +01:00
|
|
|
setSelectedProcesses(new Set());
|
|
|
|
|
} else {
|
2025-11-23 19:29:23 +01:00
|
|
|
setSelectedProcesses(new Set(displayedProcesses.map((p) => `${p.group}:${p.name}`)));
|
2025-11-23 19:14:04 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleClearSelection = () => {
|
|
|
|
|
setSelectedProcesses(new Set());
|
|
|
|
|
};
|
|
|
|
|
|
2025-11-23 19:50:17 +01:00
|
|
|
// Get displayedProcesses for keyboard navigation
|
|
|
|
|
const displayedProcesses = filteredProcesses.length > 0 || !processes ? filteredProcesses : (processes || []);
|
|
|
|
|
|
|
|
|
|
// Keyboard shortcuts
|
|
|
|
|
useKeyboardShortcuts({
|
|
|
|
|
shortcuts: [
|
|
|
|
|
{
|
|
|
|
|
key: '/',
|
|
|
|
|
description: 'Focus search',
|
|
|
|
|
action: () => {
|
|
|
|
|
// Find and focus the search input
|
|
|
|
|
const searchInput = document.querySelector('input[type="text"]') as HTMLInputElement;
|
|
|
|
|
if (searchInput) {
|
|
|
|
|
searchInput.focus();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
key: 'r',
|
|
|
|
|
description: 'Refresh',
|
|
|
|
|
action: () => {
|
|
|
|
|
refetch();
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
key: 'a',
|
|
|
|
|
description: 'Select all',
|
|
|
|
|
action: () => {
|
|
|
|
|
if (viewMode === 'flat') {
|
|
|
|
|
handleSelectAll();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
enabled: viewMode === 'flat' && displayedProcesses.length > 0,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
key: 'Escape',
|
|
|
|
|
description: 'Clear selection',
|
|
|
|
|
action: () => {
|
|
|
|
|
if (selectedProcesses.size > 0) {
|
|
|
|
|
handleClearSelection();
|
|
|
|
|
}
|
|
|
|
|
setFocusedIndex(-1);
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
key: '?',
|
|
|
|
|
shift: true,
|
|
|
|
|
description: 'Show keyboard shortcuts',
|
|
|
|
|
action: () => {
|
|
|
|
|
setShowShortcutsHelp(true);
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
key: 'j',
|
|
|
|
|
description: 'Next process',
|
|
|
|
|
action: () => {
|
|
|
|
|
if (viewMode === 'flat' && displayedProcesses.length > 0) {
|
|
|
|
|
setFocusedIndex((prev) => {
|
|
|
|
|
const next = prev + 1;
|
|
|
|
|
return next >= displayedProcesses.length ? 0 : next;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
enabled: viewMode === 'flat' && displayedProcesses.length > 0,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
key: 'k',
|
|
|
|
|
description: 'Previous process',
|
|
|
|
|
action: () => {
|
|
|
|
|
if (viewMode === 'flat' && displayedProcesses.length > 0) {
|
|
|
|
|
setFocusedIndex((prev) => {
|
|
|
|
|
const next = prev - 1;
|
|
|
|
|
return next < 0 ? displayedProcesses.length - 1 : next;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
enabled: viewMode === 'flat' && displayedProcesses.length > 0,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
key: ' ',
|
|
|
|
|
description: 'Toggle selection',
|
|
|
|
|
action: () => {
|
|
|
|
|
if (viewMode === 'flat' && focusedIndex >= 0 && focusedIndex < displayedProcesses.length) {
|
|
|
|
|
const process = displayedProcesses[focusedIndex];
|
|
|
|
|
const fullName = `${process.group}:${process.name}`;
|
|
|
|
|
handleSelectionChange(fullName, !selectedProcesses.has(fullName));
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
enabled: viewMode === 'flat' && focusedIndex >= 0 && displayedProcesses.length > 0,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Auto-select focused process
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (focusedIndex >= 0 && focusedIndex < displayedProcesses.length) {
|
|
|
|
|
const process = displayedProcesses[focusedIndex];
|
|
|
|
|
const fullName = `${process.group}:${process.name}`;
|
|
|
|
|
const element = document.querySelector(`[data-process-id="${fullName}"]`);
|
|
|
|
|
if (element) {
|
|
|
|
|
element.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}, [focusedIndex, displayedProcesses]);
|
|
|
|
|
|
2025-11-23 18:23:51 +01:00
|
|
|
if (isLoading) {
|
|
|
|
|
return (
|
|
|
|
|
<div className="space-y-6">
|
|
|
|
|
<h1 className="text-3xl font-bold">Processes</h1>
|
|
|
|
|
<div className="grid gap-6 md:grid-cols-2 lg:grid-cols-3">
|
|
|
|
|
{[1, 2, 3, 4, 5, 6].map((i) => (
|
|
|
|
|
<div key={i} className="h-64 bg-muted rounded-lg animate-pulse" />
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isError) {
|
|
|
|
|
return (
|
|
|
|
|
<div className="space-y-6">
|
|
|
|
|
<h1 className="text-3xl font-bold">Processes</h1>
|
|
|
|
|
<div className="flex flex-col items-center justify-center p-12 text-center">
|
|
|
|
|
<AlertCircle className="h-12 w-12 text-destructive mb-4" />
|
|
|
|
|
<h2 className="text-xl font-semibold mb-2">Failed to load processes</h2>
|
|
|
|
|
<p className="text-muted-foreground mb-4">
|
|
|
|
|
Could not connect to Supervisor. Please check your configuration.
|
|
|
|
|
</p>
|
|
|
|
|
<Button onClick={() => refetch()}>
|
|
|
|
|
<RefreshCw className="h-4 w-4 mr-2" />
|
|
|
|
|
Retry
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="space-y-6 animate-fade-in">
|
|
|
|
|
<div className="flex items-center justify-between">
|
|
|
|
|
<div>
|
|
|
|
|
<h1 className="text-3xl font-bold">Processes</h1>
|
|
|
|
|
<p className="text-muted-foreground mt-1">
|
2025-11-23 19:29:23 +01:00
|
|
|
{displayedProcesses.length} of {processes?.length ?? 0} processes
|
|
|
|
|
{displayedProcesses.length !== (processes?.length ?? 0) && ' (filtered)'}
|
2025-11-23 18:23:51 +01:00
|
|
|
</p>
|
|
|
|
|
</div>
|
feat: implement Phase 2 - Process Groups Management
Features added:
- Group-based process organization with collapsible cards
- Batch operations for groups (Start All, Stop All, Restart All)
- Group statistics display (running, stopped, fatal counts)
- Dedicated /groups page for group-centric management
- View toggle in /processes page (Flat view | Grouped view)
Implementation details:
- Created group API routes: /api/supervisor/groups/[name]/{start,stop,restart}
- Added React Query hooks: useStartProcessGroup, useStopProcessGroup, useRestartProcessGroup
- Created components: GroupCard, GroupView, GroupSelector
- Updated Navbar with Groups navigation link
- Integrated grouped view in processes page with toggle
Phase 2 complete (6-8 hours estimated)
2025-11-23 19:08:10 +01:00
|
|
|
<div className="flex items-center gap-4">
|
2025-11-23 19:29:23 +01:00
|
|
|
{viewMode === 'flat' && displayedProcesses.length > 0 && (
|
2025-11-23 19:14:04 +01:00
|
|
|
<Button
|
|
|
|
|
variant="outline"
|
|
|
|
|
size="sm"
|
|
|
|
|
onClick={handleSelectAll}
|
|
|
|
|
className="gap-2"
|
|
|
|
|
>
|
|
|
|
|
<CheckSquare className="h-4 w-4" />
|
2025-11-23 19:29:23 +01:00
|
|
|
{selectedProcesses.size === displayedProcesses.length ? 'Deselect All' : 'Select All'}
|
2025-11-23 19:14:04 +01:00
|
|
|
</Button>
|
|
|
|
|
)}
|
feat: implement Phase 2 - Process Groups Management
Features added:
- Group-based process organization with collapsible cards
- Batch operations for groups (Start All, Stop All, Restart All)
- Group statistics display (running, stopped, fatal counts)
- Dedicated /groups page for group-centric management
- View toggle in /processes page (Flat view | Grouped view)
Implementation details:
- Created group API routes: /api/supervisor/groups/[name]/{start,stop,restart}
- Added React Query hooks: useStartProcessGroup, useStopProcessGroup, useRestartProcessGroup
- Created components: GroupCard, GroupView, GroupSelector
- Updated Navbar with Groups navigation link
- Integrated grouped view in processes page with toggle
Phase 2 complete (6-8 hours estimated)
2025-11-23 19:08:10 +01:00
|
|
|
<GroupSelector viewMode={viewMode} onViewModeChange={setViewMode} />
|
|
|
|
|
<Button variant="outline" onClick={() => refetch()}>
|
|
|
|
|
<RefreshCw className="h-4 w-4 mr-2" />
|
|
|
|
|
Refresh
|
|
|
|
|
</Button>
|
2025-11-23 19:50:17 +01:00
|
|
|
<Button
|
|
|
|
|
variant="outline"
|
|
|
|
|
size="sm"
|
|
|
|
|
onClick={() => setShowShortcutsHelp(true)}
|
|
|
|
|
title="Keyboard Shortcuts (Shift+?)"
|
|
|
|
|
>
|
|
|
|
|
<Keyboard className="h-4 w-4" />
|
|
|
|
|
</Button>
|
feat: implement Phase 2 - Process Groups Management
Features added:
- Group-based process organization with collapsible cards
- Batch operations for groups (Start All, Stop All, Restart All)
- Group statistics display (running, stopped, fatal counts)
- Dedicated /groups page for group-centric management
- View toggle in /processes page (Flat view | Grouped view)
Implementation details:
- Created group API routes: /api/supervisor/groups/[name]/{start,stop,restart}
- Added React Query hooks: useStartProcessGroup, useStopProcessGroup, useRestartProcessGroup
- Created components: GroupCard, GroupView, GroupSelector
- Updated Navbar with Groups navigation link
- Integrated grouped view in processes page with toggle
Phase 2 complete (6-8 hours estimated)
2025-11-23 19:08:10 +01:00
|
|
|
</div>
|
2025-11-23 18:23:51 +01:00
|
|
|
</div>
|
|
|
|
|
|
2025-11-23 19:29:23 +01:00
|
|
|
{/* Filters */}
|
|
|
|
|
{processes && processes.length > 0 && (
|
|
|
|
|
<ProcessFilters processes={processes} onFilterChange={handleFilterChange} />
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{/* Process Display */}
|
2025-11-23 18:23:51 +01:00
|
|
|
{processes && processes.length === 0 ? (
|
|
|
|
|
<div className="flex flex-col items-center justify-center p-12 text-center border-2 border-dashed rounded-lg">
|
|
|
|
|
<p className="text-muted-foreground">No processes configured</p>
|
|
|
|
|
</div>
|
2025-11-23 19:29:23 +01:00
|
|
|
) : displayedProcesses.length === 0 ? (
|
|
|
|
|
<div className="flex flex-col items-center justify-center p-12 text-center border-2 border-dashed rounded-lg">
|
|
|
|
|
<p className="text-muted-foreground">No processes match the current filters</p>
|
|
|
|
|
</div>
|
feat: implement Phase 2 - Process Groups Management
Features added:
- Group-based process organization with collapsible cards
- Batch operations for groups (Start All, Stop All, Restart All)
- Group statistics display (running, stopped, fatal counts)
- Dedicated /groups page for group-centric management
- View toggle in /processes page (Flat view | Grouped view)
Implementation details:
- Created group API routes: /api/supervisor/groups/[name]/{start,stop,restart}
- Added React Query hooks: useStartProcessGroup, useStopProcessGroup, useRestartProcessGroup
- Created components: GroupCard, GroupView, GroupSelector
- Updated Navbar with Groups navigation link
- Integrated grouped view in processes page with toggle
Phase 2 complete (6-8 hours estimated)
2025-11-23 19:08:10 +01:00
|
|
|
) : viewMode === 'grouped' ? (
|
2025-11-23 19:29:23 +01:00
|
|
|
<GroupView processes={displayedProcesses} />
|
2025-11-23 18:23:51 +01:00
|
|
|
) : (
|
|
|
|
|
<div className="grid gap-6 md:grid-cols-2 lg:grid-cols-3">
|
2025-11-23 19:50:17 +01:00
|
|
|
{displayedProcesses.map((process, index) => {
|
2025-11-23 19:14:04 +01:00
|
|
|
const fullName = `${process.group}:${process.name}`;
|
2025-11-23 19:50:17 +01:00
|
|
|
const isFocused = index === focusedIndex;
|
2025-11-23 19:14:04 +01:00
|
|
|
return (
|
2025-11-23 19:50:17 +01:00
|
|
|
<div key={fullName} data-process-id={fullName}>
|
|
|
|
|
<ProcessCard
|
|
|
|
|
process={process}
|
|
|
|
|
isSelected={selectedProcesses.has(fullName)}
|
|
|
|
|
onSelectionChange={handleSelectionChange}
|
|
|
|
|
isFocused={isFocused}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2025-11-23 19:14:04 +01:00
|
|
|
);
|
|
|
|
|
})}
|
2025-11-23 18:23:51 +01:00
|
|
|
</div>
|
|
|
|
|
)}
|
2025-11-23 19:14:04 +01:00
|
|
|
|
|
|
|
|
<BatchActions
|
|
|
|
|
selectedProcesses={selectedProcesses}
|
2025-11-23 19:29:23 +01:00
|
|
|
processes={displayedProcesses}
|
2025-11-23 19:14:04 +01:00
|
|
|
onClearSelection={handleClearSelection}
|
|
|
|
|
/>
|
2025-11-23 19:50:17 +01:00
|
|
|
|
|
|
|
|
{/* Keyboard Shortcuts Help */}
|
|
|
|
|
{showShortcutsHelp && (
|
|
|
|
|
<KeyboardShortcutsHelp onClose={() => setShowShortcutsHelp(false)} />
|
|
|
|
|
)}
|
2025-11-23 18:23:51 +01:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|