forked from Txio-labs/txio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSidebar.tsx
More file actions
172 lines (158 loc) · 5.76 KB
/
Copy pathSidebar.tsx
File metadata and controls
172 lines (158 loc) · 5.76 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import React, { useState } from 'react';
import { motion, AnimatePresence } from 'framer-motion';
import { RequestItem, EnvironmentVariable, HistoryItem, CollectionNode, Workspace } from '../../types';
import { appStore } from '@/lib/store';
import { SidebarNav } from './SidebarNav';
import { WorkspaceHeader } from './WorkspaceHeader';
import { ContextToolbar } from './ContextToolbar';
import { CollectionTree } from './CollectionTree';
import { HistoryList } from './HistoryList';
import { EnvironmentList } from './EnvironmentList';
interface SidebarProps {
currentWorkspace: Workspace;
workspaces: Workspace[];
collections: CollectionNode[];
history: HistoryItem[];
envVariables: EnvironmentVariable[];
activeTabId: string | null;
activeTabType?: string;
onSwitchWorkspace: (ws: Workspace) => void;
onSelectRequest: (req: RequestItem) => void;
onSelectCollectionRequest: (node: CollectionNode) => void;
onNewRequest: () => void;
onUpdateEnv: (vars: EnvironmentVariable[]) => void;
onToggleExpand: (nodeId: string) => void;
onCreateCollection: (name: string) => void;
onCreateWorkspace: (name: string) => void;
}
type SidebarMode = 'collections' | 'history' | 'env';
export const Sidebar: React.FC<SidebarProps> = ({
currentWorkspace,
workspaces,
collections,
history,
envVariables,
onSwitchWorkspace,
onSelectRequest,
onSelectCollectionRequest,
onNewRequest,
onUpdateEnv,
onToggleExpand,
onCreateCollection,
onCreateWorkspace,
activeTabId,
activeTabType
}) => {
const [mode, setMode] = useState<SidebarMode>('collections');
const [isWsDropdownOpen, setIsWsDropdownOpen] = useState(false);
const [isCollectionFilterOpen, setIsCollectionFilterOpen] = useState(false);
const [collectionFilter, setCollectionFilter] = useState('');
const handleOpenFullHistory = () => {
appStore.openTab('history');
};
const handleAddCollection = () => {
// This will be handled by the CollectionTree component's internal state
// For now, we can trigger the creation txio
onCreateCollection('New Collection');
};
const handleAddEnvVar = () => {
onUpdateEnv([...envVariables, { key: '', value: '', enabled: true, network: 'all' }]);
};
const handleToggleCollectionFilter = () => {
if (isCollectionFilterOpen) {
setCollectionFilter('');
}
setIsCollectionFilterOpen(!isCollectionFilterOpen);
};
return (
<div className="flex h-full bg-slate-50 dark:bg-near-black border-r border-slate-200 dark:border-white/[0.06] font-sans select-none">
{/* Navigation Rail */}
<SidebarNav
activeMode={mode}
onModeChange={(m) => setMode(m as SidebarMode)}
activeTabType={activeTabType}
/>
{/* Main Content Panel */}
<div className="flex-1 flex flex-col min-w-0 bg-transparent relative">
{/* Workspace Header */}
<WorkspaceHeader
currentWorkspace={currentWorkspace}
workspaces={workspaces}
isDropdownOpen={isWsDropdownOpen}
onToggleDropdown={() => setIsWsDropdownOpen(!isWsDropdownOpen)}
onSwitchWorkspace={onSwitchWorkspace}
onCreateWorkspace={onCreateWorkspace}
/>
{/* Context Toolbar */}
<ContextToolbar
mode={mode}
onAddCollection={handleAddCollection}
onAddEnvVar={handleAddEnvVar}
filterQuery={collectionFilter}
isFilterOpen={isCollectionFilterOpen}
onFilterQueryChange={setCollectionFilter}
onToggleFilter={handleToggleCollectionFilter}
/>
{/* Content */}
<div className="flex-1 overflow-y-auto custom-scrollbar flex flex-col min-h-0 bg-slate-50 dark:bg-near-black relative">
<AnimatePresence mode="wait">
{/* COLLECTIONS */}
{mode === 'collections' && (
<motion.div
key="collections"
initial={{ opacity: 0, x: -10 }}
animate={{ opacity: 1, x: 0 }}
exit={{ opacity: 0, x: 10 }}
transition={{ duration: 0.15 }}
className="flex-1 flex flex-col"
>
<CollectionTree
collections={collections}
filterQuery={collectionFilter}
activeTabId={activeTabId}
onToggleExpand={onToggleExpand}
onSelectCollectionRequest={onSelectCollectionRequest}
onCreateCollection={onCreateCollection}
/>
</motion.div>
)}
{/* HISTORY */}
{mode === 'history' && (
<motion.div
key="history"
initial={{ opacity: 0, x: -10 }}
animate={{ opacity: 1, x: 0 }}
exit={{ opacity: 0, x: 10 }}
transition={{ duration: 0.15 }}
className="flex-1 flex flex-col"
>
<HistoryList
history={history}
currentWorkspace={currentWorkspace}
onSelectRequest={onSelectRequest}
onOpenFullHistory={handleOpenFullHistory}
/>
</motion.div>
)}
{/* ENVIRONMENTS */}
{mode === 'env' && (
<motion.div
key="env"
initial={{ opacity: 0, x: -10 }}
animate={{ opacity: 1, x: 0 }}
exit={{ opacity: 0, x: 10 }}
transition={{ duration: 0.15 }}
className="flex-1 flex flex-col"
>
<EnvironmentList
envVariables={envVariables}
onUpdateEnv={onUpdateEnv}
/>
</motion.div>
)}
</AnimatePresence>
</div>
</div>
</div>
);
};