forked from curiouscoder-cmd/ENV_Storage
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjectView.jsx
More file actions
313 lines (294 loc) · 8.5 KB
/
ProjectView.jsx
File metadata and controls
313 lines (294 loc) · 8.5 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
import { useState, useEffect } from 'react';
import { Table, Button, Space, Typography, Tag, Skeleton, Empty, Modal, message, Tooltip } from 'antd';
import {
PlusOutlined,
DownloadOutlined,
EditOutlined,
DeleteOutlined,
EyeOutlined,
EyeInvisibleOutlined,
CopyOutlined,
CheckOutlined,
UploadOutlined
} from '@ant-design/icons';
import EnvVarModal from './EnvVarModal';
import ImportEnvModal from './ImportEnvModal';
const { Title, Text } = Typography;
export default function ProjectView({ project, onProjectUpdate }) {
const [envVars, setEnvVars] = useState([]);
const [loading, setLoading] = useState(true);
const [showModal, setShowModal] = useState(false);
const [showImportModal, setShowImportModal] = useState(false);
const [editingVar, setEditingVar] = useState(null);
const [visibleValues, setVisibleValues] = useState({});
const [copiedId, setCopiedId] = useState(null);
useEffect(() => {
loadEnvVars();
}, [project.id]);
const loadEnvVars = async () => {
try {
const result = await window.electronAPI.envVars.list(project.id);
if (result.success) {
setEnvVars(result.data);
}
} catch (error) {
console.error('Failed to load env vars:', error);
} finally {
setLoading(false);
}
};
const handleCreate = async (data) => {
const result = await window.electronAPI.envVars.create({
...data,
projectId: project.id,
});
if (result.success) {
await loadEnvVars();
await onProjectUpdate();
setShowModal(false);
}
return result;
};
const handleUpdate = async (data) => {
const result = await window.electronAPI.envVars.update(data);
if (result.success) {
await loadEnvVars();
setShowModal(false);
setEditingVar(null);
}
return result;
};
const handleDelete = async (id) => {
Modal.confirm({
title: 'Delete Environment Variable',
content: 'Are you sure you want to delete this environment variable?',
okText: 'Delete',
okType: 'danger',
cancelText: 'Cancel',
onOk: async () => {
const result = await window.electronAPI.envVars.delete(id);
if (result.success) {
message.success('Environment variable deleted');
await loadEnvVars();
await onProjectUpdate();
} else {
message.error(result.error || 'Failed to delete');
}
},
});
};
const handleExport = async (format) => {
const result = await window.electronAPI.envVars.export({
projectId: project.id,
format,
});
if (result.success) {
const blob = new Blob([result.data], { type: 'text/plain' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `${project.name}.${format}`;
a.click();
URL.revokeObjectURL(url);
}
};
const toggleValueVisibility = (id) => {
setVisibleValues(prev => ({
...prev,
[id]: !prev[id],
}));
};
const copyToClipboard = async (text, id) => {
await navigator.clipboard.writeText(text);
setCopiedId(id);
message.success('Copied to clipboard');
setTimeout(() => setCopiedId(null), 2000);
};
const openEditModal = (envVar) => {
setEditingVar(envVar);
setShowModal(true);
};
const closeModal = () => {
setShowModal(false);
setEditingVar(null);
};
if (loading) {
return (
<div style={{ padding: 32 }}>
<Skeleton active paragraph={{ rows: 8 }} />
</div>
);
}
const columns = [
{
title: 'Key',
dataIndex: 'key',
key: 'key',
width: '25%',
render: (text) => <Text code strong>{text}</Text>,
},
{
title: 'Value',
dataIndex: 'value',
key: 'value',
width: '40%',
render: (text, record) => (
<Space.Compact style={{ width: '100%' }}>
<div style={{
flex: 1,
background: '#1f1f1f',
padding: '4px 12px',
borderRadius: 6,
fontFamily: 'monospace',
fontSize: 13,
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap'
}}>
{visibleValues[record.id] ? text : '••••••••'}
</div>
<Tooltip title={visibleValues[record.id] ? 'Hide value' : 'Show value'}>
<Button
type="text"
icon={visibleValues[record.id] ? <EyeInvisibleOutlined /> : <EyeOutlined />}
onClick={() => toggleValueVisibility(record.id)}
/>
</Tooltip>
<Tooltip title="Copy to clipboard">
<Button
type="text"
icon={copiedId === record.id ? <CheckOutlined style={{ color: '#52c41a' }} /> : <CopyOutlined />}
onClick={() => copyToClipboard(text, record.id)}
/>
</Tooltip>
</Space.Compact>
),
},
{
title: 'Description',
dataIndex: 'description',
key: 'description',
width: '25%',
render: (text) => <Text type="secondary">{text || '-'}</Text>,
},
{
title: 'Actions',
key: 'actions',
width: '10%',
align: 'right',
render: (_, record) => (
<Space size="small">
<Tooltip title="Edit">
<Button
type="text"
icon={<EditOutlined />}
onClick={() => openEditModal(record)}
/>
</Tooltip>
<Tooltip title="Delete">
<Button
type="text"
danger
icon={<DeleteOutlined />}
onClick={() => handleDelete(record.id)}
/>
</Tooltip>
</Space>
),
},
];
return (
<div style={{ padding: 24 }}>
<div style={{ marginBottom: 24 }}>
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-start', marginBottom: 12 }}>
<div>
<Title level={2} style={{ margin: 0, color: 'white' }}>{project.name}</Title>
{project.description && (
<Text type="secondary" style={{ marginTop: 8, display: 'block' }}>{project.description}</Text>
)}
</div>
<Space>
<Button
icon={<UploadOutlined />}
onClick={() => setShowImportModal(true)}
>
Import
</Button>
<Button
icon={<DownloadOutlined />}
onClick={() => handleExport('env')}
disabled={envVars.length === 0}
>
Export .env
</Button>
<Button
icon={<DownloadOutlined />}
onClick={() => handleExport('json')}
disabled={envVars.length === 0}
>
Export JSON
</Button>
<Button
type="primary"
icon={<PlusOutlined />}
onClick={() => setShowModal(true)}
>
Add Variable
</Button>
</Space>
</div>
<Tag color="blue">
{envVars.length} {envVars.length === 1 ? 'variable' : 'variables'}
</Tag>
</div>
{envVars.length === 0 ? (
<Empty
description={
<Space direction="vertical" size="small">
<Text strong style={{ fontSize: 16 }}>No environment variables yet</Text>
<Text type="secondary">Add your first environment variable to get started</Text>
</Space>
}
style={{
padding: '80px 0',
background: '#141414',
borderRadius: 8,
border: '2px dashed #303030'
}}
>
<Button
type="primary"
icon={<PlusOutlined />}
onClick={() => setShowModal(true)}
>
Add Variable
</Button>
</Empty>
) : (
<Table
columns={columns}
dataSource={envVars}
rowKey="id"
pagination={false}
style={{ background: '#141414' }}
/>
)}
<EnvVarModal
open={showModal}
onClose={closeModal}
onCreate={handleCreate}
onUpdate={handleUpdate}
editingVar={editingVar}
/>
<ImportEnvModal
open={showImportModal}
onClose={() => setShowImportModal(false)}
projectId={project.id}
onSuccess={async () => {
await loadEnvVars();
await onProjectUpdate();
}}
/>
</div>
);
}