Skip to content
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

chore: remove front end validation of urls #395

Merged

Conversation

DeboraSerra
Copy link
Contributor

Describe your changes

Briefly describe the changes you made and their purpose.

Issue number

Mention the issue number(s) this PR addresses (e.g., #123).

Please ensure all items are checked off before requesting a review:

  • I deployed the code locally.
  • I have performed a self-review of my code.
  • I have included the issue # in the PR.
  • I have labelled the PR correctly.
  • The issue I am working on is assigned to me.
  • I didn't use any hardcoded values (otherwise it will not scale, and will make it difficult to maintain consistency across the application).
  • I made sure font sizes, color choices etc are all referenced from the theme.
  • My PR is granular and targeted to one specific feature.
  • I took a screenshot or a video and attached to this PR if there is a UI change.

image
image
image
image

@DeboraSerra DeboraSerra linked an issue Dec 16, 2024 that may be closed by this pull request
2 tasks
@DeboraSerra DeboraSerra requested a review from erenfn December 16, 2024 21:19
Copy link
Contributor

coderabbitai bot commented Dec 16, 2024

Walkthrough

The pull request involves modifications to URL validation and error handling in two frontend components: CreateBannerPage.jsx and CreatePopupPage.jsx. The primary change is the removal of pre-save URL validation checks, which simplifies the save operation process. Both components now allow saving data without performing initial URL validation, potentially shifting the validation responsibility to a different stage of the application workflow.

Changes

File Change Summary
frontend/src/scenes/banner/CreateBannerPage.jsx Removed URL validation checks for actionUrl and url before saving banner data.
frontend/src/scenes/popup/CreatePopupPage.jsx Eliminated pre-save URL validation for actionButtonUrl and url, simplified error handling, and added console logging for responses.
frontend/src/tests/scenes/popup/CreatePopupPage.test.jsx Updated tests to reflect changes in error handling and popup creation logic, including modifications to error messages.

Possibly Related Issues

Possibly Related PRs

  • 375 add url to banner and popup #382: The changes in this PR involve the addition of URL validation for both banners and popups, which directly relates to the removal of URL validation checks in the main PR's CreateBannerPage.jsx. Both PRs modify the handling of URLs in their respective components, indicating a connection in their functionality.

Suggested Reviewers

  • erenfn

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • 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. (Beta)
  • @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.

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.

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

🔭 Outside diff range comments (1)
frontend/src/scenes/popup/CreatePopupPage.jsx (1)

Line range hint 89-96: Yo dawg, we got some dead code here! 🍝

The validateUrl function is just chillin' there without being used anywhere since the front-end validation was removed. Let's keep our codebase clean and fresh!

-  const validateUrl = (url) => {
-    try {
-      new URL(url);
-      return null;
-    } catch (err) {
-      return "Invalid URL format";
-    }
-  };
🧹 Nitpick comments (2)
frontend/src/scenes/popup/CreatePopupPage.jsx (2)

120-120: Ope! Console.log in production? Mom's spaghetti! 🍝

Let's not leave debug statements in production code. If we need to track responses, we should use proper logging utilities.

-      console.log(response)
+      // Consider using a proper logging utility if needed

128-128: Hold up! We're losing error context faster than losing yourself in the music! 🎵

The simplified error handling might make it harder to debug issues in production. Consider preserving some context in the error message.

-      emitToastError(error);
+      const errorMessage = `Failed to ${location.state?.isEdit ? 'edit' : 'create'} popup: ${error.message}`;
+      emitToastError(errorMessage);
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 99e5614 and d194db3.

📒 Files selected for processing (2)
  • frontend/src/scenes/banner/CreateBannerPage.jsx (0 hunks)
  • frontend/src/scenes/popup/CreatePopupPage.jsx (1 hunks)
💤 Files with no reviewable changes (1)
  • frontend/src/scenes/banner/CreateBannerPage.jsx
🔇 Additional comments (1)
frontend/src/scenes/popup/CreatePopupPage.jsx (1)

Line range hint 97-130: Yo, we need to talk about this validation situation! 🤔

While removing front-end validation aligns with the PR objectives, consider these implications:

  1. Users won't get immediate feedback on invalid URLs
  2. More invalid requests might hit the backend
  3. This could impact user experience and server load

Consider implementing client-side validation as a UX enhancement while keeping the backend validation as the source of truth.

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

🔭 Outside diff range comments (1)
frontend/src/tests/scenes/popup/CreatePopupPage.test.jsx (1)

Line range hint 21-94: Mom's spaghetti moment: We're missing some crucial test cases!

With the removal of frontend URL validation, we should add test cases to verify that:

  1. The form submission succeeds with invalid URLs
  2. The form submission succeeds with empty URLs
  3. The error handling correctly processes backend validation errors

Here's a suggested test case to add:

it('allows submission with invalid URLs', async () => {
  const mockAddPopup = vi.spyOn(popupServices, 'addPopup').mockResolvedValueOnce({
    data: { success: true },
  });

  render(
    <Router>
      <CreatePopupPage />
    </Router>
  );

  // Set an invalid URL
  const urlInput = screen.getByDisplayValue('https://');
  fireEvent.change(urlInput, { target: { value: 'not-a-valid-url' } });

  const saveButton = await screen.findByRole('button', { name: /Save/i });
  fireEvent.click(saveButton);

  // Verify form submission was attempted
  expect(mockAddPopup).toHaveBeenCalledTimes(1);
});
🧹 Nitpick comments (1)
frontend/src/tests/scenes/popup/CreatePopupPage.test.jsx (1)

Line range hint 119-171: Knees weak, arms heavy... but I gotchu covered with this TODO!

I notice there's a commented-out test for edit mode functionality. This is an important test case that should be implemented, especially since URL handling might be different in edit mode.

Would you like me to help implement this test case? I can create a GitHub issue to track this and provide a complete implementation that:

  1. Tests edit mode initialization
  2. Verifies URL field population
  3. Validates edit mode submission
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d194db3 and d1ebf83.

📒 Files selected for processing (1)
  • frontend/src/tests/scenes/popup/CreatePopupPage.test.jsx (1 hunks)
🔇 Additional comments (1)
frontend/src/tests/scenes/popup/CreatePopupPage.test.jsx (1)

87-87: Yo dawg, let's keep our error messages consistent!

The error message expectation has been simplified from "An unexpected error occurred" to "An error occurred". Make sure this matches the actual error message being emitted in the component after the URL validation removal.

✅ Verification successful

Yo, the error message test is on point, homie!

The test's expectation of expect.stringContaining('An error occurred') is perfectly aligned with the actual error handling in the codebase. The emitToastError function in guideHelper.js uses two variants of the message:

  • "An error occurred: " + specific error message
  • "An error occurred. Please check your network connection and try again."

Both messages contain the test's expected substring "An error occurred", making the test robust enough to catch both cases. No changes needed, eh!

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other error message occurrences to ensure consistency
rg "An (unexpected )?error occurred" --type js

Length of output: 2725


Script:

#!/bin/bash
# Let's check the actual component to see what error message it's using
ast-grep --pattern 'catch ($err) { $$$}' frontend/src/scenes/popup/CreatePopupPage.jsx

Length of output: 88


Script:

#!/bin/bash
# Let's try a broader pattern to catch error handling in the component
rg -A 5 "setError|toast" frontend/src/scenes/popup/CreatePopupPage.jsx

Length of output: 654


Script:

#!/bin/bash
# Let's check what emitToastError does
rg -A 5 "emitToastError" --type js

Length of output: 6417

@erenfn erenfn merged commit 223e02f into develop Dec 17, 2024
2 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Dec 24, 2024
9 tasks
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.

Fix Toast Messages in Create Banner and Create Popup pages
2 participants