Skip to content

Conversation

@Kavirubc
Copy link

@Kavirubc Kavirubc commented Dec 24, 2025

Purpose

Add ability to bulk import environment variables by pasting .env content or uploading a file, instead of adding them one by one.

Resolves #106

Goals

  • Enable users to paste .env file content into a textarea for quick import
  • Enable users to upload .env files directly
  • Parse and validate environment variables before populating editable fields
  • Merge imported variables with existing ones (replacing duplicates)

Approach

  • Created envParser.ts utility to parse .env content (handles comments, quoted values, empty lines, duplicates)
  • Created EnvBulkImportModal.tsx component with textarea and file upload button
  • Integrated "Bulk Import" button into EnvironmentVariable components on both Create Agent and Deploy pages
  • Used replace() from react-hook-form's useFieldArray to properly sync form fields

User stories

  • As a user, I want to paste my .env file content to quickly import multiple environment variables
  • As a user, I want to upload a .env file to import environment variables
  • As a user, I want imported variables to merge with existing ones without creating duplicates

Release note

Added bulk import functionality for environment variables. Users can now paste .env content or upload .env files to quickly populate environment variable fields when creating or deploying agents.

Documentation

N/A - This is a UI enhancement that follows existing patterns. The feature is self-explanatory with clear button labels and modal instructions.

Training

N/A

Certification

N/A - Minor UI enhancement

Marketing

N/A

Automation tests

  • Unit tests

    N/A - Frontend component changes

  • Integration tests

    Manual testing performed for all user flows

Security checks

Samples

N/A

Related PRs

N/A

Migrations (if applicable)

N/A - No migrations required

Test environment

  • Node.js v20.19.6
  • macOS Darwin 24.5.0
  • Chrome browser
  • Vite dev server v7.1.7

Learning

Used react-hook-form's useFieldArray with replace() method for proper form field synchronization. Used getValues() instead of watched values to avoid stale closure issues in callbacks.

Summary by CodeRabbit

  • New Features
    • Added bulk import functionality for environment variables, allowing users to import multiple variables at once via file upload or by pasting .env file content. Includes a real-time counter displaying detected variables and automatic merging with existing configuration.

✏️ Tip: You can customize this high-level summary in your review settings.

Add utility function to parse .env file content into key-value pairs.
Handles comments, empty lines, quoted values, and duplicate keys.
Add modal dialog for importing environment variables from .env content.
Supports both pasting content and file upload with real-time preview.
Add Bulk Import button and modal integration.
Imported variables merge with existing ones (duplicates are replaced).
Apply the same bulk import functionality to the add-new-agent page.
This fixes the empty first row issue that occurred after
bulk importing environment variables.
Enables bulk import modal usage in the add new agent page.
Gets current form values directly at import time instead of
relying on memoized watched values.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 24, 2025

📝 Walkthrough

Walkthrough

This PR introduces a bulk import feature for environment variables. It adds a new EnvBulkImportModal component that allows users to paste .env file content or upload a file, includes a parseEnvContent utility to parse .env format into structured variables, and integrates both into the existing EnvironmentVariable form component to merge imported variables with existing ones.

Changes

Cohort / File(s) Change Summary
New Modal Component
console/workspaces/libs/shared-component/src/components/EnvBulkImportModal.tsx
New React component enabling bulk import of environment variables via pasted .env content or file upload; handles textarea input, file selection, parsing via parseEnvContent(), and triggers onImport() callback with parsed variables.
Parsing Utility
console/workspaces/libs/shared-component/src/utils/envParser.ts, console/workspaces/libs/shared-component/src/utils/index.ts
New parseEnvContent() utility function parsing .env format (splits lines, extracts key=value pairs, strips quotes, handles duplicates); new EnvVariable interface; re-export from utils barrel.
EnvironmentVariable Form Integration
console/workspaces/libs/shared-component/src/components/EnvironmentVariable.tsx
Added local state for bulk import modal; integrated EnvBulkImportModal component; added handleImport() callback merging imported variables with existing ones by key (imported overrides existing); memoized env values; added "Bulk Import" button alongside existing "Add" button.
Export/Re-export Updates
console/workspaces/libs/shared-component/src/components/index.ts, console/workspaces/libs/shared-component/src/index.ts
Added EnvBulkImportModal to component barrel exports; added export * from './utils' to main library index to expose parsing utilities.
add-new-agent Page Updates
console/workspaces/pages/add-new-agent/package.json, console/workspaces/pages/add-new-agent/src/components/EnvironmentVariable.tsx
Added @agent-management-platform/shared-component workspace dependency; integrated bulk import modal and merge logic into local EnvironmentVariable component mirroring shared component changes.

Sequence Diagram(s)

sequenceDiagram
    actor User
    participant Modal as EnvBulkImportModal
    participant Parser as parseEnvContent
    participant Form as EnvironmentVariable
    
    User->>Modal: Open modal (click Bulk Import)
    User->>Modal: Paste .env content OR upload file
    activate Modal
    Modal->>Modal: Read file/textarea content
    deactivate Modal
    
    Note over Modal: Real-time variable count
    
    User->>Modal: Click Import
    activate Modal
    Modal->>Parser: parseEnvContent(content)
    activate Parser
    Parser->>Parser: Split lines, extract key=value, strip quotes
    Parser-->>Modal: EnvVariable[]
    deactivate Parser
    
    Modal->>Form: onImport(parsedVars)
    deactivate Modal
    
    activate Form
    Form->>Form: Merge imported vars with existing<br/>(imported overrides, filter empty)
    Form->>Form: Replace entire env array
    Form-->>User: Updated form with imported vars
    deactivate Form
    
    Modal->>Modal: Clear content, close
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

The changes span multiple files with consistent new logic (modal component, parsing utility, form integration), but the individual pieces are straightforward. Review requires understanding the merge semantics, file handling, and form integration, plus verification that the parsing handles .env format correctly.

Poem

🐰 A bulk import blooms in the code today,
Variables hop in, no need to delay—
Parse that .env with elegant grace,
Merge them in order, each in its place!
Upload or paste, let the form embrace—
Automation's gift to the developer's race! 🌱

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: add bulk import for environment variables' clearly summarizes the main change—bulk import functionality for environment variables.
Description check ✅ Passed The PR description is comprehensive, following the template with Purpose, Goals, Approach, User stories, Release note, and other sections fully completed.
Linked Issues check ✅ Passed The PR implementation fully addresses issue #106 by enabling users to import environment variables via file upload or pasting .env content, with proper parsing and merging logic.
Out of Scope Changes check ✅ Passed All changes are scope-aligned: new envParser utility, EnvBulkImportModal component, and integration into EnvironmentVariable components directly support the bulk import feature.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
console/workspaces/libs/shared-component/src/components/EnvironmentVariable.tsx (1)

19-115: Consider consolidating duplicate EnvironmentVariable components.

This component is nearly identical to the one in console/workspaces/pages/add-new-agent/src/components/EnvironmentVariable.tsx, with only minor differences in import paths and styling. Since both components share the same logic for handling environment variables and bulk imports, consolidating them into a single shared implementation would:

  • Reduce code duplication
  • Simplify maintenance
  • Ensure consistent behavior across pages

Consider using this shared-component version in add-new-agent by importing it rather than maintaining two separate implementations.

🔎 Verification: Check if EnvironmentVariable is exported from shared-component
#!/bin/bash
# Check if EnvironmentVariable is exported from shared-component index
rg -n "EnvironmentVariable" console/workspaces/libs/shared-component/src/components/index.ts console/workspaces/libs/shared-component/src/index.ts
console/workspaces/libs/shared-component/src/components/EnvBulkImportModal.tsx (1)

61-79: Consider adding error handling for file upload.

The file upload handler lacks error handling for:

  • FileReader errors (e.g., file read failures)
  • Large file sizes that might cause browser issues
  • Non-text file content

For production robustness, consider adding:

const handleFileUpload = useCallback(
    (e: ChangeEvent<HTMLInputElement>) => {
        const file = e.target.files?.[0];
        if (!file) return;

        // Optional: check file size (e.g., 1MB limit)
        if (file.size > 1024 * 1024) {
            // Show error to user
            return;
        }

        const reader = new FileReader();
        reader.onload = (event) => {
            const text = event.target?.result;
            if (typeof text === "string") {
                setContent(text);
            }
        };
        reader.onerror = () => {
            // Show error to user
        };
        reader.readAsText(file);

        e.target.value = "";
    },
    []
);
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 228334b and eadb2ed.

⛔ Files ignored due to path filters (1)
  • console/common/config/rush/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (8)
  • console/workspaces/libs/shared-component/src/components/EnvBulkImportModal.tsx
  • console/workspaces/libs/shared-component/src/components/EnvironmentVariable.tsx
  • console/workspaces/libs/shared-component/src/components/index.ts
  • console/workspaces/libs/shared-component/src/index.ts
  • console/workspaces/libs/shared-component/src/utils/envParser.ts
  • console/workspaces/libs/shared-component/src/utils/index.ts
  • console/workspaces/pages/add-new-agent/package.json
  • console/workspaces/pages/add-new-agent/src/components/EnvironmentVariable.tsx
🧰 Additional context used
🧬 Code graph analysis (3)
console/workspaces/libs/shared-component/src/utils/envParser.ts (1)
console/workspaces/libs/shared-component/src/utils/index.ts (2)
  • EnvVariable (20-20)
  • parseEnvContent (19-19)
console/workspaces/pages/add-new-agent/src/components/EnvironmentVariable.tsx (2)
console/workspaces/libs/shared-component/src/components/EnvironmentVariable.tsx (1)
  • EnvironmentVariable (27-115)
console/workspaces/libs/shared-component/src/components/EnvBulkImportModal.tsx (1)
  • EnvBulkImportModal (39-190)
console/workspaces/libs/shared-component/src/components/EnvironmentVariable.tsx (2)
console/workspaces/pages/add-new-agent/src/components/EnvironmentVariable.tsx (1)
  • EnvironmentVariable (26-104)
console/workspaces/libs/shared-component/src/components/EnvBulkImportModal.tsx (1)
  • EnvBulkImportModal (39-190)
🔇 Additional comments (17)
console/workspaces/libs/shared-component/src/components/index.ts (1)

28-28: LGTM!

The export follows the established barrel pattern and correctly exposes the new EnvBulkImportModal component.

console/workspaces/libs/shared-component/src/index.ts (1)

20-20: LGTM!

The export correctly expands the public API to include utilities (parseEnvContent and EnvVariable type) for use by consumers.

console/workspaces/pages/add-new-agent/package.json (1)

52-52: LGTM!

The workspace dependency correctly enables the add-new-agent page to consume EnvBulkImportModal and related utilities from the shared-component library.

console/workspaces/libs/shared-component/src/utils/index.ts (1)

19-20: LGTM!

The barrel exports correctly separate type and value exports, following TypeScript best practices for public API design.

console/workspaces/libs/shared-component/src/utils/envParser.ts (3)

19-22: LGTM!

The EnvVariable interface appropriately models environment variables with a simple key-value structure.


25-34: LGTM!

The stripQuotes helper correctly handles basic quote stripping for single and double quotes, which is appropriate for typical .env file formats.


37-70: LGTM!

The parseEnvContent function implements a solid basic .env parser that handles:

  • Cross-platform line endings
  • Comments and empty lines
  • Quoted values (single and double)
  • Duplicate keys (last value wins)
  • Proper key-value splitting at the first =

The implementation is appropriate for typical .env file formats and aligns with the PR objectives.

console/workspaces/pages/add-new-agent/src/components/EnvironmentVariable.tsx (5)

19-19: LGTM!

The imports are correctly structured and all new dependencies (useState, useCallback, useMemo, FileText, EnvBulkImportModal, EnvVariable) are properly utilized in the component.

Also applies to: 21-21, 24-24


27-30: LGTM!

The hook additions correctly support the bulk import feature:

  • getValues avoids stale closures in handleImport
  • replace enables swapping the entire env array
  • useWatch provides reactive env values
  • useState manages modal visibility

32-36: LGTM!

The memoization correctly stabilizes envValues for use in callbacks and validation logic, preventing unnecessary re-renders and ensuring consistent behavior.

Also applies to: 38-38


41-64: LGTM!

The handleImport merge logic correctly:

  • Uses getValues to avoid stale closures
  • Filters empty rows before merging
  • Uses a Map for efficient key-based merging (imported values override existing)
  • Preserves key insertion order (existing keys maintain position, new imports append)
  • Replaces the entire array for clean state management

87-100: LGTM!

The UI integration correctly adds:

  • A "Bulk Import" button with appropriate icon and styling
  • EnvBulkImportModal properly wired with open state and handlers

The implementation provides a smooth user experience for bulk importing environment variables.

console/workspaces/libs/shared-component/src/components/EnvBulkImportModal.tsx (5)

19-31: LGTM!

All imports are correctly structured and utilized throughout the component.


33-37: LGTM!

The props interface correctly defines a standard modal contract with clear responsibilities for open state, close handling, and import callback.


44-50: LGTM!

State management is clean and efficient:

  • Content state for user input
  • Ref for file input control
  • Memoized parsing to avoid redundant work

87-99: LGTM!

Both handlers are correctly implemented:

  • handleImport validates count before proceeding and properly cleans up
  • handleClose ensures clean state reset

101-189: LGTM!

The UI implementation is excellent:

  • Clean dialog structure with appropriate sizing
  • Monospace textarea with helpful placeholder and theme-aware styling
  • Standard file upload pattern with clear accept types
  • Real-time visual feedback via count indicator with color coding
  • Proper button states (Import disabled when no variables detected)

The user experience is intuitive and polished.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Improvement] Support importing environment variables via a .env file

1 participant