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

405-linkid-potential-bug #412

Merged
merged 8 commits into from
Dec 24, 2024
Merged

405-linkid-potential-bug #412

merged 8 commits into from
Dec 24, 2024

Conversation

DeboraSerra
Copy link
Contributor

@DeboraSerra DeboraSerra commented Dec 21, 2024

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.

@DeboraSerra DeboraSerra requested a review from erenfn December 21, 2024 01:08
Copy link
Contributor

coderabbitai bot commented Dec 21, 2024

Walkthrough

The pull request encompasses modifications across four frontend React components: Settings.jsx, LinksDefaultPage.jsx, NewLinksPopup.jsx, and constants.js. The changes primarily focus on code organization, type consistency, and minor structural improvements. Key modifications include standardizing the id handling as a string, removing unnecessary fragments, refactoring error handling and conditional logic, and updating the API base URL for the staging environment.

Changes

File Change Summary
frontend/src/components/Links/Settings/Settings.jsx - Converted id to string in default state
- Updated handleClose to use string id
- Replaced double quotes with single quotes in JSX attributes
frontend/src/scenes/links/LinksDefaultPage.jsx - Removed unnecessary fragment tags
- Adjusted import statement formatting
- Improved code readability
frontend/src/scenes/links/NewLinksPopup.jsx - Relocated DEFAULT_VALUES object
- Removed getLinkById import
- Simplified error handling
- Updated conditional logic in handleSaveHelper
frontend/src/utils/constants.js - Commented out local environment URL
- Uncommented staging environment URL

Possibly Related PRs

Suggested Reviewers

  • erenfn

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6c39205 and 21d3a52.

📒 Files selected for processing (1)
  • frontend/src/components/Links/Popup/Popup.jsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • frontend/src/components/Links/Popup/Popup.jsx

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: 1

🔭 Outside diff range comments (1)
frontend/src/scenes/links/NewLinksPopup.jsx (1)

Line range hint 86-96: Critical: Validation bypass for existing links

Yo! The validation check for title and URL is skipped when id is a number, which could allow empty or invalid links to slip through. This might be causing the linkId bug mentioned in the PR title.

Fix the validation flow like this:

  const handleLinks = async (item) => {
    const { id, ...link } = item;
    if (!link?.title.trim() || !link?.url.trim()) {
      emitToastError(buildToastError("Title and URL are required"));
      return null;
    }
    try {
-      if (typeof id === "number") return item;
+      if (typeof id === "number") return { ...item, title: link.title.trim(), url: link.url.trim() };
      return { ...link };
    } catch (err) {
      emitToastError(err);
      return null;
    }
  };
🧹 Nitpick comments (2)
frontend/src/scenes/links/NewLinksPopup.jsx (1)

Line range hint 117-129: Prevent race conditions in link deletion

Mom's spaghetti moment! 🍝 There's a potential race condition here. If the helper update succeeds but link deletion fails, we'll end up in an inconsistent state.

Consider wrapping the helper update and link deletions in a transaction-like pattern:

    if (isEdit && deletedLinks.length) {
-     await Promise.all(
-       deletedLinks.map(async (it) => {
-         try {
-           return await deleteLink({ ...it, helperId: helperToEdit });
-         } catch (err) {
-           emitToastError(err);
-           return null;
-         }
-       })
-     );
+     const deletionResults = await Promise.all(
+       deletedLinks.map((it) => deleteLink({ ...it, helperId: helperToEdit }).catch(err => ({ error: err })))
+     );
+     const deletionErrors = deletionResults.filter(result => result.error);
+     if (deletionErrors.length) {
+       deletionErrors.forEach(({ error }) => emitToastError(error));
+       // Consider rolling back helper update here
+       return null;
+     }
    }
frontend/src/components/Links/Settings/Settings.jsx (1)

157-159: Improve auto-save indicator accuracy

There's vomit on his sweater already! The "Auto-saved" text is misleading since changes are only saved on form submission.

Consider either:

  1. Implementing actual auto-save functionality, or
  2. Changing the text to "Changes will be saved when you close"
-         <span className={s["settings__header--info"]}>Auto-saved</span>
+         <span className={s["settings__header--info"]}>Saved on close</span>

Also applies to: 98-99

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7f19775 and e84d976.

📒 Files selected for processing (3)
  • frontend/src/components/Links/Settings/Settings.jsx (5 hunks)
  • frontend/src/scenes/links/LinksDefaultPage.jsx (2 hunks)
  • frontend/src/scenes/links/NewLinksPopup.jsx (8 hunks)
✅ Files skipped from review due to trivial changes (1)
  • frontend/src/scenes/links/LinksDefaultPage.jsx
🔇 Additional comments (1)
frontend/src/components/Links/Settings/Settings.jsx (1)

84-86: 🛠️ Refactor suggestion

Verify URL format before saving

Arms are heavy! We should validate the URL format before saving to prevent invalid links.

Let's check if there are any URL validation utilities in the codebase:

Consider adding URL validation:

+     const isValidUrl = (url) => {
+       if (url.startsWith('/')) return true;
+       try {
+         new URL(url);
+         return true;
+       } catch {
+         return false;
+       }
+     };
+
      if (!info.title.trim() && !info.url.trim()) {
        toggleSettings(e);
        setLinkToEdit(null);
        return;
      }
+     if (!isValidUrl(info.url.trim())) {
+       // Use your toast system here
+       alert('Please enter a valid URL');
+       return;
+     }

frontend/src/components/Links/Settings/Settings.jsx Outdated Show resolved Hide resolved
@DeboraSerra DeboraSerra linked an issue Dec 21, 2024 that may be closed by this pull request
@erenfn erenfn changed the base branch from master to develop December 21, 2024 16:56
Copy link
Collaborator

@erenfn erenfn left a comment

Choose a reason for hiding this comment

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

I don't get that error anymore in the db anymore. However, I came across this new error: It occurs when you edit a helper link and delete one of its links:

image
image

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 (1)
frontend/src/utils/constants.js (1)

3-3: Be mindful of local testing needs
Palms might be sweating when toggling between local and staging. By commenting out the local API, you lose an easy environment for debugging. If local usage is still valuable, consider adding a separate configuration switch.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 946b348 and 070e485.

📒 Files selected for processing (2)
  • frontend/src/scenes/links/NewLinksPopup.jsx (7 hunks)
  • frontend/src/utils/constants.js (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • frontend/src/scenes/links/NewLinksPopup.jsx
🔇 Additional comments (1)
frontend/src/utils/constants.js (1)

6-6: Verify the staging endpoint
Knees weak, arms heavy—double-check that the staging URL is correct and ready to handle new requests. A misconfigured endpoint could lead to confusion and headaches during QA.

@erenfn
Copy link
Collaborator

erenfn commented Dec 23, 2024

I still get this error in the console. It happens when you add a link, delete it, and then clicking save. My guess is that we add that link to the "links to be deleted" list and then try to delete it. However, this error occurs because we haven't created it in the first place. The links that are created before clicking save shouldn't be added to the deletedLinks links afterwards

image

@erenfn erenfn self-requested a review December 24, 2024 14:34
Copy link
Collaborator

@erenfn erenfn left a comment

Choose a reason for hiding this comment

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

The other bug is gone.

However, adding two url's with the same title and deleting one of them deletes both of them. We should fix it

  • Add two links called Link1:

image
-Delete one of them
image
-Both of them are gone
image

@erenfn erenfn merged commit 370bf11 into develop Dec 24, 2024
2 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.

Link.id potential bug
3 participants