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

466 add duplicate button #471

Merged
merged 4 commits into from
Jan 7, 2025
Merged

466 add duplicate button #471

merged 4 commits into from
Jan 7, 2025

Conversation

MandeepPaul
Copy link
Contributor

Describe your changes

Added duplicate button in DefaultPageTemplate to create a copy of any guide.

Issue number

#466

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.

Preview

image

Copy link
Contributor

coderabbitai bot commented Jan 7, 2025

Walkthrough

The pull request introduces enhancements across several default page components (Banners, Hints, Links, and Popups) by incorporating new service methods for item duplication and retrieval. The DefaultPageTemplate is modified to support these functionalities, enabling components to duplicate and fetch specific items dynamically. Additionally, updates to the List and ListItem components provide a new UI interaction for duplicating items, primarily accessible to admin users.

Changes

File Path Change Summary
frontend/src/scenes/banner/BannerDefaultPage.jsx Added imports for addBanner and getBannerById from bannerServices module.
frontend/src/scenes/hints/HintDefaultPage.jsx Added imports for addHint and getHintById from hintServices module, updated DefaultPageTemplate props.
frontend/src/scenes/links/LinksDefaultPage.jsx Added imports for createHelper and getHelperById from helperLinkService, updated DefaultPageTemplate props.
frontend/src/scenes/popup/PopupDefaultPage.jsx Added imports for addPopup and getPopupById from popupServices, updated DefaultPageTemplate props.
frontend/src/templates/DefaultPageTemplate/DefaultPageTemplate.jsx Added duplicateHandler, new props getItemById and duplicateItem, updated state management.
frontend/src/templates/GuideMainPageTemplate/...List/List.jsx Added onDuplicate prop to ListItem.
frontend/src/templates/GuideMainPageTemplate/...ListItem/ListItem.jsx Added new duplication action button, updated component signature.

Suggested reviewers

  • erenfn

Possibly related PRs


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

🧹 Nitpick comments (3)
frontend/src/scenes/links/LinksDefaultPage.jsx (1)

3-3: There's inconsistency on his sweater already! 🤔

While the implementation is solid, the function naming createHelper breaks the consistency with other similar functions in the codebase (addHint, addPopup). Consider renaming for consistency:

- import { createHelper, getHelperById, deleteHelper, getHelpers } from "../../services/helperLinkService";
+ import { addHelper, getHelperById, deleteHelper, getHelpers } from "../../services/helperLinkService";

  // ...
          getItemById={getHelperById}
-         duplicateItem={createHelper}
+         duplicateItem={addHelper}

Also applies to: 44-45

frontend/src/templates/DefaultPageTemplate/DefaultPageTemplate.jsx (2)

52-74: Knees weak! Let's enhance error handling in duplicateHandler

The error handling could use some love to be more specific about what went wrong.

  } catch (error) {
-   const errorMessage = error.response?.data?.message
-     ? `Error: ${error.response.data.message}`
-     : 'An unexpected error occurred. Please try again.';
+   const errorMessage = error.response?.data?.message
+     ? `Failed to duplicate ${itemType.slice(0, -1)}: ${error.response.data.message}`
+     : `Failed to duplicate ${itemType.slice(0, -1)}. Please try again.`;
    toastEmitter.emit(TOAST_EMITTER_KEY, errorMessage);
+   console.error(`Duplication error for ${itemType}:`, error);
  }

54-59: Arms are heavy! Consider extracting helper links logic

The special handling for helper links could be cleaner if extracted into a separate function.

+ const duplicateHelperLinks = async (id) => {
+   const { createdBy, id: fetchedId, links, ...helper } = await getItemById(id);
+   const updatedLinks = links.map(({ id, ...data }) => data);
+   return duplicateItem(helper, updatedLinks);
+ };

  const duplicateHandler = async (id) => {
    try {
      if (itemType === 'helper links') {
-       const { createdBy, id: fetchedId, links, ...helper } = await getItemById(id);
-       const updatedLinks = links.map(({ id, ...data }) => data);
-       await duplicateItem(helper, updatedLinks);
+       await duplicateHelperLinks(id);
      } else {
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c0fd8aa and e9b4990.

📒 Files selected for processing (7)
  • frontend/src/scenes/banner/BannerDefaultPage.jsx (2 hunks)
  • frontend/src/scenes/hints/HintDefaultPage.jsx (2 hunks)
  • frontend/src/scenes/links/LinksDefaultPage.jsx (2 hunks)
  • frontend/src/scenes/popup/PopupDefaultPage.jsx (2 hunks)
  • frontend/src/templates/DefaultPageTemplate/DefaultPageTemplate.jsx (5 hunks)
  • frontend/src/templates/GuideMainPageTemplate/GuideMainPageComponents/List/List.jsx (1 hunks)
  • frontend/src/templates/GuideMainPageTemplate/GuideMainPageComponents/List/ListItem/ListItem.jsx (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build (22.x)
🔇 Additional comments (3)
frontend/src/scenes/hints/HintDefaultPage.jsx (1)

6-6: Mom's spaghetti approves! 🍝

Clean implementation of the duplication feature. The code follows the established pattern and maintains good separation of concerns.

Also applies to: 32-33

frontend/src/scenes/popup/PopupDefaultPage.jsx (1)

5-5: Knees weak, arms heavy, but this code is ready! 💪

The implementation is solid and consistent with the pattern established in other components.

Also applies to: 33-34

frontend/src/scenes/banner/BannerDefaultPage.jsx (1)

33-34: There's vomit on his sweater already! But this code is clean!

The integration of duplicate functionality follows the established pattern consistently. Props are correctly passed through to the template.

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

♻️ Duplicate comments (1)
frontend/src/templates/GuideMainPageTemplate/GuideMainPageComponents/List/ListItem/ListItem.jsx (1)

33-36: ⚠️ Potential issue

Yo! That event bubbling issue is still there!

This is a duplicate of a previous comment that wasn't addressed. The duplicate button click will bubble up to the parent div's onClick.

- <IconButton onClick={onDuplicate}>
+ <IconButton onClick={(e) => {
+   e.stopPropagation();
+   onDuplicate();
+ }}>
🧹 Nitpick comments (2)
frontend/src/templates/GuideMainPageTemplate/GuideMainPageComponents/List/ListItem/ListItem.jsx (2)

12-12: Mom's spaghetti! Add default prop value for onDuplicate

To prevent those nasty undefined errors when onDuplicate isn't provided, let's add a default prop value.

- const ListItem = ({ title, text, id, onClick, onDelete, onEdit, onDuplicate }) => {
+ const ListItem = ({ title, text, id, onClick, onDelete, onEdit, onDuplicate = () => {} }) => {

35-35: Keep it consistent with MUI theming, dawg!

Instead of using CSS variables, let's stick to MUI's theme system for better consistency.

- <ContentCopyTwoToneIcon sx={{ color: 'var(--main-text-color)' }} />
+ <ContentCopyTwoToneIcon sx={{ color: theme.palette.text.primary }} />
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e9b4990 and 77d4926.

📒 Files selected for processing (1)
  • frontend/src/templates/GuideMainPageTemplate/GuideMainPageComponents/List/ListItem/ListItem.jsx (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build (22.x)
🔇 Additional comments (2)
frontend/src/templates/GuideMainPageTemplate/GuideMainPageComponents/List/ListItem/ListItem.jsx (2)

1-1: Yo dawg, these imports are clean!

The removal of unused React hooks and addition of the ContentCopyTwoTone icon import is on point! 🍝

Also applies to: 7-7


57-57: Props validation is on point!

The onDuplicate PropType has been added correctly. Nice work! 🍝

@MandeepPaul MandeepPaul requested a review from erenfn January 7, 2025 08:54
@MandeepPaul
Copy link
Contributor Author

I will update those icons in issue #472.

@erenfn erenfn merged commit 50fb7dc into develop Jan 7, 2025
2 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Jan 7, 2025
9 tasks
@MandeepPaul MandeepPaul deleted the 466-add-duplicate-button branch January 8, 2025 06:52
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