Files
supervisor-ui/app/processes/page.tsx
Sebastian Krüger 9fd38aaacb
All checks were successful
Build and Push Docker Image to Gitea / build-and-push (push) Successful in 1m6s
feat: implement Phase 6 - Search and Filtering
Features added:
- Advanced search and filtering for processes
- Real-time search by name, group, or description
- Filter by process state (All, Running, Stopped, Fatal, Starting, Stopping)
- Filter by process group
- Collapsible filter panel
- Clear all filters button
- Filter count indicator

Implementation details:
- Created ProcessFilters component with:
  - Search input with clear button and search icon
  - State filter buttons with color indicators
  - Group filter buttons (auto-generated from available groups)
  - Toggle filters panel button
  - Active filters detection and clear button

Processes page enhancements:
- Integrated ProcessFilters component
- Real-time filtering with useEffect
- Display count shows "X of Y processes (filtered)"
- Select All works on filtered results
- Empty state when no matches: "No processes match the current filters"
- Filters apply to both flat and grouped views

Filter features:
- Search: Live filtering as you type (name, group, description)
- State filter: 6 filter options with colored dots
- Group filter: Dynamic buttons for each unique group
- Clear filters: Single button to reset all filters
- Collapsible panel: Show/hide filters to save space
- Active filter indicator: Clear button appears when filters active

UX improvements:
- Search input with X button to clear
- Filter button toggles panel (highlighted when active)
- Color-coded state buttons matching process states
- Responsive layout with flex-wrap for many groups
- Maintains selection state across filter changes

Phase 6 complete (2-3 hours estimated)
2025-11-23 19:29:23 +01:00

155 lines
5.5 KiB
TypeScript

'use client';
import { useState, useCallback } from 'react';
import { useProcesses } from '@/lib/hooks/useSupervisor';
import { ProcessCard } from '@/components/process/ProcessCard';
import { GroupView } from '@/components/groups/GroupView';
import { GroupSelector } from '@/components/groups/GroupSelector';
import { BatchActions } from '@/components/process/BatchActions';
import { ProcessFilters } from '@/components/process/ProcessFilters';
import { RefreshCw, AlertCircle, CheckSquare } from 'lucide-react';
import { Button } from '@/components/ui/button';
import type { ProcessInfo } from '@/lib/supervisor/types';
export default function ProcessesPage() {
const [viewMode, setViewMode] = useState<'flat' | 'grouped'>('flat');
const [selectedProcesses, setSelectedProcesses] = useState<Set<string>>(new Set());
const [filteredProcesses, setFilteredProcesses] = useState<ProcessInfo[]>([]);
const { data: processes, isLoading, isError, refetch } = useProcesses();
const handleFilterChange = useCallback((filtered: ProcessInfo[]) => {
setFilteredProcesses(filtered);
}, []);
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 = () => {
const displayedProcesses = filteredProcesses.length > 0 ? filteredProcesses : (processes || []);
if (displayedProcesses) {
if (selectedProcesses.size === displayedProcesses.length) {
setSelectedProcesses(new Set());
} else {
setSelectedProcesses(new Set(displayedProcesses.map((p) => `${p.group}:${p.name}`)));
}
}
};
const handleClearSelection = () => {
setSelectedProcesses(new Set());
};
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>
);
}
const displayedProcesses = filteredProcesses.length > 0 || !processes ? filteredProcesses : processes;
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">
{displayedProcesses.length} of {processes?.length ?? 0} processes
{displayedProcesses.length !== (processes?.length ?? 0) && ' (filtered)'}
</p>
</div>
<div className="flex items-center gap-4">
{viewMode === 'flat' && displayedProcesses.length > 0 && (
<Button
variant="outline"
size="sm"
onClick={handleSelectAll}
className="gap-2"
>
<CheckSquare className="h-4 w-4" />
{selectedProcesses.size === displayedProcesses.length ? 'Deselect All' : 'Select All'}
</Button>
)}
<GroupSelector viewMode={viewMode} onViewModeChange={setViewMode} />
<Button variant="outline" onClick={() => refetch()}>
<RefreshCw className="h-4 w-4 mr-2" />
Refresh
</Button>
</div>
</div>
{/* Filters */}
{processes && processes.length > 0 && (
<ProcessFilters processes={processes} onFilterChange={handleFilterChange} />
)}
{/* Process Display */}
{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>
) : 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>
) : viewMode === 'grouped' ? (
<GroupView processes={displayedProcesses} />
) : (
<div className="grid gap-6 md:grid-cols-2 lg:grid-cols-3">
{displayedProcesses.map((process) => {
const fullName = `${process.group}:${process.name}`;
return (
<ProcessCard
key={fullName}
process={process}
isSelected={selectedProcesses.has(fullName)}
onSelectionChange={handleSelectionChange}
/>
);
})}
</div>
)}
<BatchActions
selectedProcesses={selectedProcesses}
processes={displayedProcesses}
onClearSelection={handleClearSelection}
/>
</div>
);
}