-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathNetworkControls.tsx
More file actions
78 lines (71 loc) · 2.06 KB
/
NetworkControls.tsx
File metadata and controls
78 lines (71 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import {
Button,
Group,
Stack,
Text,
TextInput,
Title,
UnstyledButton,
} from "@mantine/core";
import type { FetchRequestCategory } from "@inspector/core/mcp/types.js";
const NETWORK_CATEGORIES: FetchRequestCategory[] = ["auth", "transport"];
const CATEGORY_COLORS: Record<FetchRequestCategory, string> = {
auth: "violet",
transport: "blue",
};
const SubtleButton = Button.withProps({
variant: "subtle",
size: "xs",
});
export interface NetworkControlsProps {
filterText: string;
visibleCategories: Record<FetchRequestCategory, boolean>;
onFilterChange: (text: string) => void;
onToggleCategory: (category: FetchRequestCategory, visible: boolean) => void;
onToggleAllCategories: () => void;
}
export function NetworkControls({
filterText,
visibleCategories,
onFilterChange,
onToggleCategory,
onToggleAllCategories,
}: NetworkControlsProps) {
const allSelected = NETWORK_CATEGORIES.every((c) => visibleCategories[c]);
return (
<Stack gap="md">
<Title order={4}>Network</Title>
<TextInput
placeholder="Search..."
value={filterText}
onChange={(e) => onFilterChange(e.currentTarget.value)}
/>
<Group justify="space-between">
<Title order={5}>Filter by Category</Title>
<SubtleButton onClick={onToggleAllCategories}>
{allSelected ? "Deselect All" : "Select All"}
</SubtleButton>
</Group>
<Stack gap="xs">
{NETWORK_CATEGORIES.map((category) => {
const active = visibleCategories[category];
return (
<UnstyledButton
key={category}
w="100%"
p="sm"
variant="listItem"
aria-pressed={active}
bg={active ? "var(--mantine-primary-color-light)" : undefined}
onClick={() => onToggleCategory(category, !active)}
>
<Text c={CATEGORY_COLORS[category]} ta="center" fw={500}>
{category}
</Text>
</UnstyledButton>
);
})}
</Stack>
</Stack>
);
}