Skip to content

feat(creator): add Load from File to YAML editor#299

Open
platex-rehor-bot wants to merge 2 commits intoRedHatInsights:masterfrom
platex-rehor-bot:bot/RHCLOUD-40758
Open

feat(creator): add Load from File to YAML editor#299
platex-rehor-bot wants to merge 2 commits intoRedHatInsights:masterfrom
platex-rehor-bot:bot/RHCLOUD-40758

Conversation

@platex-rehor-bot
Copy link
Copy Markdown
Contributor

Summary

  • Adds a "Load from File" button to the quickstart creator YAML editor, allowing content creators to load existing .yaml/.yml files from disk into the Monaco editor for preview and editing
  • Includes overwrite confirmation dialog (same pattern as existing "Load Sample Template" button)
  • File content is parsed and live-previewed immediately on load via the existing parseAndUpdateQuickstart() flow
  • Adds 12 new unit tests for CreatorYAMLView covering both file loading and sample template flows

Changes: 3 files — CreatorYAMLView.tsx (component), CreatorYAMLView.test.tsx (new tests), jest.config.js (add yaml to transform allowlist)

RHCLOUD-40758

Test plan

  • Verify "Load from File" button renders next to "Load Sample Template"
  • Click "Load from File" with empty editor → file picker opens
  • Click "Load from File" with content → confirmation dialog appears
  • Cancel confirmation → file picker does not open
  • Select a valid .yaml file → content loads into editor, preview updates
  • Select an invalid YAML file → parse error alert shown
  • Re-select the same file → works (input is reset after each selection)
  • All 12 new unit tests pass (npm test)

🤖 Generated with Claude Code

RHCLOUD-40758
Add ability to load existing YAML files into the quickstart creator
YAML editor via a file picker. Includes overwrite confirmation dialog,
FileReader-based loading, and YAML parse/preview on load. Also adds
12 new unit tests for CreatorYAMLView covering both Load from File
and Load Sample Template flows.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 24, 2026

Warning

Rate limit exceeded

@platex-rehor-bot has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 49 minutes and 49 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 49 minutes and 49 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Enterprise

Run ID: 7deca930-3d44-4959-98b4-d83b0643e708

📥 Commits

Reviewing files that changed from the base of the PR and between d9be8ba and 605e8c5.

📒 Files selected for processing (2)
  • src/components/creator/CreatorYAMLView.test.tsx
  • src/components/creator/CreatorYAMLView.tsx

Walkthrough

This PR adds file-loading capability to the CreatorYAMLView component. The Jest configuration is updated to transform the yaml package, a comprehensive test suite is added, and the component now supports selecting local YAML files via a toolbar button with confirmation flow and automatic parsing.

Changes

Cohort / File(s) Summary
Jest Configuration
jest.config.js
Updated transformIgnorePatterns to include the yaml package for transformation by Jest/SWC instead of ignoring it.
YAML File Loading Feature
src/components/creator/CreatorYAMLView.tsx, src/components/creator/CreatorYAMLView.test.tsx
Added file-loading capability with hidden file input and toolbar button. Users can select local .yaml/.yml files with confirmation prompts when editor content exists. File content replaces editor state and triggers YAML parsing. Comprehensive test suite covers file selection flows, parsing validation, error handling, and debounced editor updates.

Sequence Diagram

sequenceDiagram
    participant User
    participant Component as CreatorYAMLView
    participant FileAPI as File Input API
    participant YAMLParser as YAML Parser
    participant State as Component State

    User->>Component: Click upload button
    alt Editor has content
        Component->>User: Show confirmation dialog
        User->>Component: Confirm or cancel
    end
    
    Component->>FileAPI: Open file picker
    User->>FileAPI: Select .yaml/.yml file
    FileAPI->>Component: Return file object
    
    Component->>FileAPI: Read file as text
    FileAPI->>Component: Return file content
    
    Component->>YAMLParser: Parse YAML content
    YAMLParser->>Component: Return parsed data
    
    Component->>State: Update editor value
    Component->>State: Update quickstart spec
    Component->>State: Update bundles/tags
    
    Component->>FileAPI: Reset file input
    Component->>User: Render updated editor
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main feature addition: a "Load from File" capability for the YAML editor component.
Description check ✅ Passed The description is comprehensive and directly related to the changeset, covering the feature, implementation approach, files modified, and test plan.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 and usage tips.

Copy link
Copy Markdown

@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: 2

🧹 Nitpick comments (3)
src/components/creator/CreatorYAMLView.test.tsx (2)

182-196: Consider also asserting the specific parser message surfaces.

YAML.parse error messages are part of the user-visible alert ("{message}. Showing previous valid state in preview."). Asserting only on the static title "YAML Parse Error" means a regression that suppresses the dynamic reason would still pass. An additional assertion on the trailing sentence would tighten the test.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/creator/CreatorYAMLView.test.tsx` around lines 182 - 196, The
test in CreatorYAMLView.test.tsx only asserts the static title "YAML Parse
Error" and should also assert the dynamic parser message from YAML.parse is
rendered; update the 'shows parse error for invalid YAML' test that renders
<CreatorYAMLView /> and fires the file change to additionally expect the
specific parser message (or the full alert sentence like "{message}. Showing
previous valid state in preview.") is present in the document so regressions
that drop the dynamic reason will fail; locate the file input test that uses
mockFile and add an assertion (e.g., regex matching the parser error text) after
the waitFor that checks the alert body contains the YAML.parse error text.

198-206: Minor: empty-files test does not assert confirm was not invoked.

The test validates that no callback fires, but the actual code path this exercises (file falsy → early return) is inside handleFileSelected, which is only reached after the picker was already opened. Consider also asserting parseError stays unset and the editor value is unchanged, to guard against future regressions where an empty selection might mutate state.

     fireEvent.change(fileInput, { target: { files: [] } });
 
     expect(onChangeSpec).not.toHaveBeenCalled();
+    expect(screen.queryByText(/YAML Parse Error/i)).not.toBeInTheDocument();
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/creator/CreatorYAMLView.test.tsx` around lines 198 - 206, The
test "does nothing when no file is selected" should also verify that the
confirmation dialog wasn't invoked and that component state didn't change:
mock/spy on global confirm (or window.confirm) and assert it was not called, and
assert CreatorYAMLView's parseError remains unset and the editor value is
unchanged after firing the change event (i.e., capture the editor's initial
value from the rendered output before the event and compare it after). Locate
the behavior in handleFileSelected and add these assertions alongside the
existing onChangeQuickStartSpec check.
src/components/creator/CreatorYAMLView.tsx (1)

153-183: Optional: extract the shared "confirm overwrite" flow.

handleLoadSample and handleLoadFromFile share the same "if content then confirm" pattern with only the message and follow-up action differing. A small helper would reduce duplication and keep the messages in one place:

♻️ Sketch
const confirmOverwriteIfDirty = (message: string): boolean => {
  if (yamlContent.trim() === '') return true;
  return window.confirm(message);
};

const handleLoadSample = () => {
  if (!confirmOverwriteIfDirty('This will overwrite your current work. Are you sure?')) return;
  setYamlContent(DEFAULT_QUICKSTART_YAML);
  parseAndUpdateQuickstart(DEFAULT_QUICKSTART_YAML);
};

const handleLoadFromFile = () => {
  if (!confirmOverwriteIfDirty('Loading a file will overwrite your current work. Are you sure?')) return;
  fileInputRef.current?.click();
};
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/creator/CreatorYAMLView.tsx` around lines 153 - 183, Extract
the duplicated "confirm overwrite" logic into a small helper like
confirmOverwriteIfDirty(message: string): boolean that checks yamlContent.trim()
=== '' and returns true if empty or calls window.confirm(message) otherwise;
then simplify handleLoadSample to return early if the helper returns false
before calling setYamlContent(DEFAULT_QUICKSTART_YAML) and
parseAndUpdateQuickstart(DEFAULT_QUICKSTART_YAML), and simplify
handleLoadFromFile to return early if the helper returns false before calling
fileInputRef.current?.click(); reference the symbols confirmOverwriteIfDirty,
handleLoadSample, handleLoadFromFile, yamlContent, setYamlContent,
parseAndUpdateQuickstart, and fileInputRef in your changes.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/components/creator/CreatorYAMLView.tsx`:
- Around line 185-203: The file-read operation in handleFileSelected currently
omits FileReader error handling so read failures are silent; add reader.onerror
(and optionally reader.onabort) handlers to call the existing parse error
pathway (e.g., setParseError or the same alert used by parseAndUpdateQuickstart)
with a clear message and underlying error info, clear or reset yaml state if
appropriate, and log the error for diagnostics; keep the current success flow
using setYamlContent and parseAndUpdateQuickstart in reader.onload.
- Around line 170-183: The confirm dialog in handleLoadFromFile fires because
yamlContent contains the initial placeholder comments; update the guard to only
ask for confirmation when the user has actually modified the editor by either
(a) introducing a constant INITIAL_YAML_PLACEHOLDER (matching the initial
yamlContent value) and change the check to skip confirmation when currentContent
=== '' or currentContent === INITIAL_YAML_PLACEHOLDER, or (b) add a dirty
boolean (set true in handleEditorChange) and only prompt when dirty is true;
modify handleLoadFromFile to reference the chosen symbol
(INITIAL_YAML_PLACEHOLDER or dirty) and leave handleLoadSample behavior
consistent with this change.

---

Nitpick comments:
In `@src/components/creator/CreatorYAMLView.test.tsx`:
- Around line 182-196: The test in CreatorYAMLView.test.tsx only asserts the
static title "YAML Parse Error" and should also assert the dynamic parser
message from YAML.parse is rendered; update the 'shows parse error for invalid
YAML' test that renders <CreatorYAMLView /> and fires the file change to
additionally expect the specific parser message (or the full alert sentence like
"{message}. Showing previous valid state in preview.") is present in the
document so regressions that drop the dynamic reason will fail; locate the file
input test that uses mockFile and add an assertion (e.g., regex matching the
parser error text) after the waitFor that checks the alert body contains the
YAML.parse error text.
- Around line 198-206: The test "does nothing when no file is selected" should
also verify that the confirmation dialog wasn't invoked and that component state
didn't change: mock/spy on global confirm (or window.confirm) and assert it was
not called, and assert CreatorYAMLView's parseError remains unset and the editor
value is unchanged after firing the change event (i.e., capture the editor's
initial value from the rendered output before the event and compare it after).
Locate the behavior in handleFileSelected and add these assertions alongside the
existing onChangeQuickStartSpec check.

In `@src/components/creator/CreatorYAMLView.tsx`:
- Around line 153-183: Extract the duplicated "confirm overwrite" logic into a
small helper like confirmOverwriteIfDirty(message: string): boolean that checks
yamlContent.trim() === '' and returns true if empty or calls
window.confirm(message) otherwise; then simplify handleLoadSample to return
early if the helper returns false before calling
setYamlContent(DEFAULT_QUICKSTART_YAML) and
parseAndUpdateQuickstart(DEFAULT_QUICKSTART_YAML), and simplify
handleLoadFromFile to return early if the helper returns false before calling
fileInputRef.current?.click(); reference the symbols confirmOverwriteIfDirty,
handleLoadSample, handleLoadFromFile, yamlContent, setYamlContent,
parseAndUpdateQuickstart, and fileInputRef in your changes.
🪄 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: Organization UI

Review profile: CHILL

Plan: Enterprise

Run ID: 9afd8dd2-edd2-44ea-bf0a-c24ab8dc1846

📥 Commits

Reviewing files that changed from the base of the PR and between f495a37 and d9be8ba.

📒 Files selected for processing (3)
  • jest.config.js
  • src/components/creator/CreatorYAMLView.test.tsx
  • src/components/creator/CreatorYAMLView.tsx

Comment thread src/components/creator/CreatorYAMLView.tsx
Comment thread src/components/creator/CreatorYAMLView.tsx
RHCLOUD-40758
- Extract PLACEHOLDER_YAML constant and isUserContent() helper to skip
  confirm dialog on fresh editor (placeholder content is not user work)
- Add confirmOverwriteIfDirty() shared helper to deduplicate the confirm
  pattern between handleLoadSample and handleLoadFromFile
- Add FileReader.onerror handler to surface read failures via parseError
- Add FileReader error test, strengthen parse error assertions, verify
  confirm is not invoked on empty file selection
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