Skip to content

Add .env file upload and auto-split paste support for environment variables - #1459

Open
YasiruDEX wants to merge 2 commits into
wso2:mainfrom
YasiruDEX:feature/env-file-upload-and-auto-split
Open

Add .env file upload and auto-split paste support for environment variables#1459
YasiruDEX wants to merge 2 commits into
wso2:mainfrom
YasiruDEX:feature/env-file-upload-and-auto-split

Conversation

@YasiruDEX

@YasiruDEX YasiruDEX commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Purpose

Configuring environment variables one field at a time is tedious, especially
when a user already has a .env file, or is copying KEY=VALUE pairs from a
terminal, doc, or another tool. This PR streamlines both entry paths across
every place environment variables are edited in the console.

Resolves issue #1453

Goals

  1. Let users paste a full KEY=VALUE line (optionally quoted, e.g.
    API_KEY="12345") directly into the Key field and have it
    auto-split into the Key and Value fields.
  2. Let users upload a .env (or plain text) file to bulk-populate /
    merge environment variables into the existing list, instead of adding
    them one at a time.

Approach

  • Added an onPaste handler on the Key TextInput in the shared
    EnvVariableEditor component (libs/views/src/component/EnvVariableEditor).
    It detects = in the pasted text, splits on the first occurrence, trims
    whitespace and strips matching surrounding quotes from the value, then
    populates both the Key and Value fields. Falls back to normal paste
    behavior when there's no = or the field is disabled.
  • Added a new shared component, EnvFileUpload
    (libs/views/src/component/EnvFileUpload), exposing:
    • parseEnvFileContent(text) — parses .env syntax: skips blank lines
      and # comments, splits each line on the first =, strips matching
      surrounding quotes from the value.
    • EnvFileUploadButton — a button + hidden file input read via
      FileReader, following the existing upload pattern already used by
      FileMountEditor.
  • Wired the upload button into the three places environment variables are
    edited:
    • Deploy config drawer (pages/deploy/src/subComponent/EditDeployConfigDrawer.tsx)
    • Promote agent drawer (pages/deploy/src/subComponent/PromoteAgentDrawer.tsx)
    • Create-agent environment variable step
      (pages/add-new-agent/src/components/EnvironmentVariable.tsx)
  • Uploaded/pasted entries are merged into existing state by key (update the
    existing row if the key already exists, append otherwise); the
    create-agent flow additionally skips overwriting keys that are locked /
    pre-defined by the Agent Kind schema.
Before After
Screenshot 2026-07-31 at 14 42 49 Screenshot 2026-08-03 at 21 24 30

User stories

  • As a user configuring an agent's environment variables, I want to paste a
    KEY=VALUE line and have both fields fill in automatically, so I don't
    have to manually split and retype it.
  • As a user with an existing .env file, I want to upload it directly
    instead of re-entering each variable by hand.

Release note

You can now paste KEY=VALUE lines directly into an environment variable's
Key field to auto-fill both fields, and upload a .env file to
bulk-populate environment variables when creating, deploying, or promoting
an agent.

Documentation

N/A — this is a self-explanatory UI affordance (standard paste/upload
interaction) on an existing form; there is no dedicated doc page for the
environment variable editor to update.

Training

N/A — no training content covers this UI flow today.

Certification

N/A — no certification exam content covers this UI flow today.

Marketing

N/A — minor UX improvement to an existing feature, not a new marketable
capability.

Automation tests

  • Unit tests
    N/A
  • Integration tests
    N/A

Security checks

Samples

N/A — no new sample apps or configs; existing .env files can be used
directly with the new upload button.

Related PRs

N/A

Migrations (if applicable)

N/A — no data model, schema, or config migration involved; this is a
console-only UI change.

Test environment

Verified locally by rebuilding and running the console via the
docker-compose dev setup (make dev-rebuild) on macOS; the shared
EnvFileUpload component and the EnvVariableEditor paste handler compiled
cleanly through the console's Vite watch build.

Learning

Followed the existing FileMountEditor file-upload pattern already in the
codebase (libs/views/src/component/FileMountEditor/FileMountEditor.tsx)
for consistency — same FileReader-based read, same 1 MB size guard — rather
than introducing a new upload mechanism.

Summary by CodeRabbit

  • New Features
    • Added .env file upload support for environment variable editors.
    • Automatically parses valid key-value entries, handles quoted values, and reports invalid or oversized files.
    • Merges uploaded variables with existing entries while preserving locked variables.
    • Added support across agent creation, deployment configuration, and agent promotion workflows.
    • Users can paste KEY=VALUE content directly into environment variable fields.

@coderabbitai

coderabbitai Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds reusable .env file upload and parsing. Adds KEY=VALUE paste handling. Integrates both input methods into new-agent, deployment-edit, and promote-agent environment variable forms.

Changes

Environment variable input

Layer / File(s) Summary
Reusable .env upload parser
console/workspaces/libs/views/src/component/EnvFileUpload/*, console/workspaces/libs/views/src/component/index.ts
Adds parsing, file validation, error handling, upload UI, and public exports.
KEY=VALUE paste handling
console/workspaces/libs/views/src/component/EnvVariableEditor/EnvVariableEditor.tsx
Pasted values update both fields. Keys normalize whitespace to underscores.
New-agent environment integration
console/workspaces/pages/add-new-agent/src/components/EnvironmentVariable.tsx
Uploaded entries update existing variables, add non-sensitive entries, skip blank rows, and preserve locked keys.
Deployment environment integration
console/workspaces/pages/deploy/src/subComponent/EditDeployConfigDrawer.tsx, console/workspaces/pages/deploy/src/subComponent/PromoteAgentDrawer.tsx
Uploaded entries update matching variables, clear secret references, append non-sensitive entries, and appear beside Add controls.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Operator
  participant EnvFileUploadButton
  participant EnvironmentVariableForm
  participant EnvironmentState

  Operator->>EnvFileUploadButton: select .env file
  EnvFileUploadButton->>EnvFileUploadButton: parse valid entries
  EnvFileUploadButton->>EnvironmentVariableForm: onParsed(entries)
  EnvironmentVariableForm->>EnvironmentState: merge entries by key
  EnvironmentState-->>EnvironmentVariableForm: updated environment variables
Loading

Possibly related issues

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely summarizes both main changes: .env file upload and automatic splitting of pasted environment variables.
Description check ✅ Passed The description follows the template, explains the purpose and implementation, includes UI screenshots, testing details, and addresses all required sections.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@console/workspaces/libs/views/src/component/EnvFileUpload/EnvFileUpload.tsx`:
- Around line 47-51: Require at least two characters before stripping matching
surrounding quotes in the quote-normalization logic: add a value.length >= 2
guard in EnvFileUpload.tsx lines 47-51, and the equivalent pastedValue.length >=
2 guard in EnvVariableEditor.tsx lines 136-140, preserving single-quote and
double-quote handling otherwise.

In
`@console/workspaces/libs/views/src/component/EnvVariableEditor/EnvVariableEditor.tsx`:
- Around line 127-145: Update handleKeyPaste to return immediately when
isSecretLocked is true, before calling preventDefault() or changing either
field; preserve the existing paste parsing and onValueChange behavior for
unlocked secrets.

In `@console/workspaces/pages/deploy/src/subComponent/PromoteAgentDrawer.tsx`:
- Around line 294-308: Update handleEnvFileParsed to exclude parsed entries
whose keys are platform-managed system keys in the target configuration before
merging them into formState.env. Reuse the existing target configuration
system-key set used by the prefill filtering, and preserve the current update
behavior for user-managed keys.
- Around line 509-523: Gate the environment upload and Add controls in
PromoteAgentDrawer.tsx on targetConfigLoaded && filledForTarget ===
formState.targetEnvironment, in addition to isPending. In
EditDeployConfigDrawer.tsx, gate the corresponding upload and Add controls on
the readiness state that becomes true after the initial configuration seed
completes.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 907ef358-ce1f-4fde-8640-cbe4a3d17951

📥 Commits

Reviewing files that changed from the base of the PR and between 7b4fc3b and ebb836b.

📒 Files selected for processing (7)
  • console/workspaces/libs/views/src/component/EnvFileUpload/EnvFileUpload.tsx
  • console/workspaces/libs/views/src/component/EnvFileUpload/index.ts
  • console/workspaces/libs/views/src/component/EnvVariableEditor/EnvVariableEditor.tsx
  • console/workspaces/libs/views/src/component/index.ts
  • console/workspaces/pages/add-new-agent/src/components/EnvironmentVariable.tsx
  • console/workspaces/pages/deploy/src/subComponent/EditDeployConfigDrawer.tsx
  • console/workspaces/pages/deploy/src/subComponent/PromoteAgentDrawer.tsx

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.

1 participant