-
-
Notifications
You must be signed in to change notification settings - Fork 1
feat: Add Import Functionality for Environment Variables #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
curiouscoder-cmd
merged 1 commit into
curiouscoder-cmd:main
from
GreenHacker420:feature/import-env-files
Oct 11, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,173 @@ | ||
| import { useState } from 'react'; | ||
| import { Modal, Input, Select, Switch, message, Alert } from 'antd'; | ||
| import { Upload } from 'lucide-react'; | ||
|
|
||
| const { TextArea } = Input; | ||
| const { Option } = Select; | ||
|
|
||
| export default function ImportEnvModal({ open, onClose, projectId, onSuccess }) { | ||
| const [content, setContent] = useState(''); | ||
| const [format, setFormat] = useState('env'); | ||
| const [overwrite, setOverwrite] = useState(false); | ||
| const [loading, setLoading] = useState(false); | ||
|
|
||
| const handleFileUpload = (e) => { | ||
| const file = e.target.files[0]; | ||
| if (!file) return; | ||
|
|
||
| const reader = new FileReader(); | ||
| reader.onload = (event) => { | ||
| setContent(event.target.result); | ||
|
|
||
| // Auto-detect format | ||
| if (file.name.endsWith('.json')) { | ||
| setFormat('json'); | ||
| } else { | ||
| setFormat('env'); | ||
| } | ||
| }; | ||
| reader.readAsText(file); | ||
| }; | ||
|
|
||
| const handleImport = async () => { | ||
| if (!content.trim()) { | ||
| message.error('Please provide content to import'); | ||
| return; | ||
| } | ||
|
|
||
| setLoading(true); | ||
| try { | ||
| const result = await window.electronAPI.envVars.import({ | ||
| projectId, | ||
| content, | ||
| format, | ||
| overwrite, | ||
| }); | ||
|
|
||
| if (result.success) { | ||
| const { imported, updated, skipped, total, errors } = result.data; | ||
|
|
||
| let messageText = `Import complete: ${imported} imported`; | ||
| if (updated > 0) messageText += `, ${updated} updated`; | ||
| if (skipped > 0) messageText += `, ${skipped} skipped`; | ||
|
|
||
| message.success(messageText); | ||
|
|
||
| if (errors && errors.length > 0) { | ||
| console.error('Import errors:', errors); | ||
| message.warning(`${errors.length} variables had errors`); | ||
| } | ||
|
|
||
| onSuccess(); | ||
| handleClose(); | ||
| } else { | ||
| message.error(result.error || 'Failed to import'); | ||
| } | ||
| } catch (error) { | ||
| message.error('Failed to import: ' + error.message); | ||
| } finally { | ||
| setLoading(false); | ||
| } | ||
| }; | ||
|
|
||
| const handleClose = () => { | ||
| setContent(''); | ||
| setFormat('env'); | ||
| setOverwrite(false); | ||
| onClose(); | ||
| }; | ||
|
|
||
| return ( | ||
| <Modal | ||
| title={ | ||
| <div className="flex items-center gap-2"> | ||
| <Upload className="w-5 h-5" /> | ||
| <span>Import Environment Variables</span> | ||
| </div> | ||
| } | ||
| open={open} | ||
| onCancel={handleClose} | ||
| onOk={handleImport} | ||
| okText="Import" | ||
| confirmLoading={loading} | ||
| width={600} | ||
| destroyOnClose | ||
| > | ||
| <div className="space-y-4"> | ||
| <Alert | ||
| message="Import your existing .env or JSON files" | ||
| description="Paste the content below or upload a file. Comments in .env files will be preserved as descriptions." | ||
| type="info" | ||
| showIcon | ||
| /> | ||
|
|
||
| <div> | ||
| <label className="block text-sm font-medium mb-2"> | ||
| Upload File (Optional) | ||
| </label> | ||
| <input | ||
| type="file" | ||
| accept=".env,.json,.txt" | ||
| onChange={handleFileUpload} | ||
| className="block w-full text-sm text-gray-400 | ||
| file:mr-4 file:py-2 file:px-4 | ||
| file:rounded-md file:border-0 | ||
| file:text-sm file:font-semibold | ||
| file:bg-blue-600 file:text-white | ||
| hover:file:bg-blue-700 | ||
| file:cursor-pointer cursor-pointer" | ||
| /> | ||
| </div> | ||
|
|
||
| <div> | ||
| <label className="block text-sm font-medium mb-2">Format</label> | ||
| <Select | ||
| value={format} | ||
| onChange={setFormat} | ||
| className="w-full" | ||
| > | ||
| <Option value="env">.env format (KEY=value)</Option> | ||
| <Option value="json">JSON format</Option> | ||
| </Select> | ||
| </div> | ||
|
|
||
| <div> | ||
| <label className="block text-sm font-medium mb-2">Content</label> | ||
| <TextArea | ||
| value={content} | ||
| onChange={(e) => setContent(e.target.value)} | ||
| placeholder={ | ||
| format === 'env' | ||
| ? '# Database configuration\nDB_HOST=localhost\nDB_PORT=5432\nDB_NAME=myapp' | ||
| : '{\n "DB_HOST": "localhost",\n "DB_PORT": "5432",\n "DB_NAME": "myapp"\n}' | ||
| } | ||
| rows={10} | ||
| className="font-mono text-sm" | ||
| /> | ||
| </div> | ||
|
|
||
| <div className="flex items-center justify-between p-3 bg-gray-800 rounded-lg"> | ||
| <div> | ||
| <div className="font-medium">Overwrite existing variables</div> | ||
| <div className="text-sm text-gray-400"> | ||
| Update values if keys already exist | ||
| </div> | ||
| </div> | ||
| <Switch | ||
| checked={overwrite} | ||
| onChange={setOverwrite} | ||
| /> | ||
| </div> | ||
|
|
||
| {format === 'env' && ( | ||
| <Alert | ||
| message="Tip" | ||
| description="Comments above variables (lines starting with #) will be imported as descriptions." | ||
| type="success" | ||
| showIcon | ||
| /> | ||
| )} | ||
| </div> | ||
| </Modal> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check notice
Code scanning / CodeQL
Unused variable, import, function or class Note