Skip to content

Allow empty payloads in test runs #1962

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

Conversation

myftija
Copy link
Collaborator

@myftija myftija commented Apr 22, 2025

Changes in this PR:

  • adapted the code editor component to allow empty inputs
  • exposed basic linter configs in the code editor component
  • applied a couple of light touch ups to the error display elements in favor of consistency

Screenshots

Previously:
Screenshot 2025-04-21 at 17 20 37

Now:
Screenshot 2025-04-21 at 17 21 17

Summary by CodeRabbit

  • New Features

    • Added configurable linting options to the JSON editor, allowing users to enable or disable linting and permit empty content without errors.
  • Style

    • Improved the visual appearance of linting errors and diagnostic messages in the editor for better readability.
  • Bug Fixes

    • Enhanced validation error messages for JSON fields, providing clearer feedback when invalid JSON is entered.
  • Chores

    • Removed placeholder text from the JSON editor in the task form for a cleaner interface.

Copy link

changeset-bot bot commented Apr 22, 2025

⚠️ No Changeset found

Latest commit: 134e486

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

coderabbitai bot commented Apr 22, 2025

Walkthrough

The changes introduce configurable linting behavior to the JSONEditor component, allowing users to enable or disable linting and to specify whether empty content should be considered valid. Supporting logic was added to handle linting based on these new props. Editor theme styles were updated to improve the appearance of linting diagnostics. The default editor setup was simplified by removing built-in linting extensions, delegating linting responsibility to the JSONEditor component. Additionally, JSON parsing and validation logic was improved in the test task schema for clearer error reporting, and a placeholder attribute was removed from a JSONEditor instance.

Changes

File(s) Change Summary
apps/webapp/app/components/code/JSONEditor.tsx Added linterEnabled and allowEmpty props, implemented empty-aware linter logic, updated default props, and adjusted editor setup to use new linting behavior.
apps/webapp/app/components/code/codeMirrorSetup.ts Removed linting-related imports and extensions; editor setup no longer includes built-in linting.
apps/webapp/app/components/code/codeMirrorTheme.ts Added and updated styles for linting and diagnostic UI elements in the dark theme.
apps/webapp/app/routes/_app.orgs...test.tasks.$taskParam/route.tsx Removed the placeholder attribute from a JSONEditor component in the StandardTaskForm.
apps/webapp/app/v3/testTask.ts Refactored JSON parsing for payload and metadata fields to improve error handling and reporting in schema logic.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant JSONEditor
    participant CodeMirror
    participant Linter

    User->>JSONEditor: Edit JSON content
    JSONEditor->>CodeMirror: Update editor state
    alt Linting enabled
        JSONEditor->>Linter: Run linter (empty-aware if allowEmpty)
        Linter-->>JSONEditor: Return diagnostics (or none if empty)
        JSONEditor->>CodeMirror: Display diagnostics with custom styling
    else Linting disabled
        JSONEditor->>CodeMirror: No diagnostics shown
    end
Loading

Poem

In the warren where code runs deep,
JSON now gets a careful sweep.
Linting toggled, errors bright,
Empty fields? That’s now all right!
With colors clear and checks anew,
Our editor’s smarter—thanks to this crew.
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2c19693 and 134e486.

📒 Files selected for processing (5)
  • apps/webapp/app/components/code/JSONEditor.tsx (5 hunks)
  • apps/webapp/app/components/code/codeMirrorSetup.ts (1 hunks)
  • apps/webapp/app/components/code/codeMirrorTheme.ts (2 hunks)
  • apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.test.tasks.$taskParam/route.tsx (0 hunks)
  • apps/webapp/app/v3/testTask.ts (1 hunks)
💤 Files with no reviewable changes (1)
  • apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.test.tasks.$taskParam/route.tsx
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - pnpm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - npm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (ubuntu-latest - pnpm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (ubuntu-latest - npm)
  • GitHub Check: typecheck / typecheck
🔇 Additional comments (13)
apps/webapp/app/components/code/codeMirrorSetup.ts (2)

4-4: Good modularization of linting functionality.

The import changes here are part of a larger refactoring that moves linting responsibility from the global editor setup to the JSONEditor component. This allows for more flexible and configurable linting behavior.


34-34: LGTM: Keymap integration preserved correctly.

You've appropriately maintained the lintKeymap integration in the editor setup while removing the automatic inclusion of linting extensions. This preserves keyboard shortcuts for linting without forcing linting behavior.

apps/webapp/app/components/code/codeMirrorTheme.ts (2)

42-67: Well-structured styling for linting UI elements.

The added styles for linting tooltips, diagnostics, and markers provide a cohesive visual experience that fits with the overall theme. The error styling with red borders and indicators clearly highlights validation issues for users.


111-111: Maintain consistent spacing in the theme.

The marginTop adjustment for tooltips helps maintain consistent spacing and improves the overall appearance of the editor.

apps/webapp/app/components/code/JSONEditor.tsx (6)

1-2: LGTM: Necessary imports for linting functionality.

The updated imports correctly bring in the required linting functionality that was previously imported in the codeMirrorSetup file.

Also applies to: 11-11


22-23: Good configuration options for linting flexibility.

Adding the linterEnabled and allowEmpty props provides excellent flexibility for consumers of the JSONEditor component, aligning with the PR objective to allow empty payloads.


30-41: Elegant solution for handling empty content.

The emptyAwareJsonLinter function is a smart approach that allows empty content to be valid while still applying linting rules to non-empty content. The implementation is clean and focused.


49-50: Sensible default configuration.

Setting linterEnabled: true and allowEmpty: true as defaults provides a good balance of syntax validation while supporting the PR objective of allowing empty payloads.


65-66: Proper prop destructuring.

The new props are correctly destructured from the combined default and user-provided props.


79-90: Well-structured conditional linting setup.

The approach to conditionally add linting extensions is well-organized:

  1. Only adds linting if enabled
  2. Uses a switch statement for language-specific linting, making it easy to extend
  3. Applies the appropriate linter based on the allowEmpty setting

The language satisfies never in the default case is a good TypeScript pattern to ensure exhaustive handling of all language types.

apps/webapp/app/v3/testTask.ts (3)

7-14: Improved payload handling with optional support.

The schema changes properly handle optional payloads, returning an empty object for falsy values. This aligns with the UI changes to allow empty payloads in the editor.


15-24: Cleaner error handling for JSON parsing.

The updated transformation logic provides clearer error messages when JSON parsing fails, improving the user experience while maintaining validation integrity.


25-42: Consistent approach for metadata handling.

The metadata field uses the same pattern as payload, maintaining consistency in the codebase for similar types of data. The error message is appropriately specific to metadata.

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

.optional()
.transform((val, ctx) => {
if (!val) {
return {};
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Returning undefined here would be more fitting, but it breaks the replay flow, which doesn't handle this well. The fix seemed a bit involved, so leaving this for a separate PR. In the meantime, the behavior stays the same, as users would still pass { } as empty payload for tests.

Copy link
Member

Choose a reason for hiding this comment

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

Good idea

@matt-aitken matt-aitken merged commit fab5652 into triggerdotdev:main Apr 22, 2025
6 of 7 checks passed
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.

2 participants