Skip to content

#434: Popup Dialog's component #451

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

Closed
wants to merge 4 commits into from
Closed

#434: Popup Dialog's component #451

wants to merge 4 commits into from

Conversation

Yup03
Copy link

@Yup03 Yup03 commented Dec 31, 2024

#434
Created component for pop up dialogs.
Added some styling and also header, content, leftButtonText, and rightButtonText as props.

I couldn't include the component inside the app as it was hard for me to see realtime changes when a file was modified
but I was able to test it in some separate environment.
Any suggestion for improvement is welcomed.

image

@Yup03 Yup03 changed the title #434: Popup Dialogs's component #434: Popup Dialog's component Dec 31, 2024
Copy link
Contributor

coderabbitai bot commented Dec 31, 2024

Walkthrough

The pull request introduces modifications to the PopUpMessages component in the frontend, enhancing its flexibility by replacing hardcoded values with dynamic props. The component now accepts parameters for header, content, button texts, and type, allowing for more customizable message displays. A new custom hook, usePopUp, has been added to manage the visibility state of the pop-up. The accompanying SCSS module has been updated with refined styling, introducing new classes and adjusting existing ones to improve the component's visual presentation and responsiveness.

Changes

File Change Summary
frontend/src/components/PopUpMessages/PopUpMessages.jsx - Added props: header, content, leftBtnText, rightBtnText, type, isOpen, hidePopUp
- Removed hardcoded title and message
- Updated rendering to use new props
- Introduced useEffect for closing the popup on outside click
- Adjusted containerStyle with max-width condition
frontend/src/components/PopUpMessages/PopUpMessages.module.scss - Updated import path for global styles
- Enhanced .container class with new properties
- Added .closeBtn class
- Refined styling for buttons and text containers
- Introduced hover effects
frontend/src/components/PopUpMessages/usePopUp.js - Added new custom hook usePopUp to manage pop-up visibility state

Sequence Diagram

sequenceDiagram
    Parent Component->>PopUpMessages: Render with props
    PopUpMessages->>PopUpMessages: Process props
    PopUpMessages-->>Parent Component: Display customized message
Loading

The sequence diagram illustrates how the new PopUpMessages component receives props from its parent, processes them, and renders a dynamically configured message interface.

Possibly related PRs

  • 410 dialog reset #429: The RichTextEditor component's changes to prop management and state handling may relate to the PopUpMessages component's refactoring, as both involve enhancing component flexibility through props and state management.

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

🧹 Nitpick comments (6)
frontend/src/components/PopUpMessages/PopUpMessages.jsx (3)

36-38: Adaptive width
Limiting width per type is a neat idea. For better responsiveness on smaller screens, you could use media queries.


40-42: Conditional margins
This approach works but might cause layout shifts. Keep an eye on consistency across various screen sizes.


44-65: Neat structure and accessible design
The UI is tidy. Consider adding aria-label or other accessibility attributes to ensure everyone can enjoy your popup.

frontend/src/components/PopUpMessages/PopUpMessages.module.scss (3)

32-44: .textContainer
Clear structure. The text-style mixin is neat. Make sure these headings scale gracefully.


48-53: .buttons for better UX
A row layout with spacing is fab. Could consider a wrap for small screens.


82-87: .closeBtn accessibility
This button stands out for quick dismissals. Consider adding an aria-label for better screen reader support.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a6c52fa and 4fcb3fb.

📒 Files selected for processing (2)
  • frontend/src/components/PopUpMessages/PopUpMessages.jsx (1 hunks)
  • frontend/src/components/PopUpMessages/PopUpMessages.module.scss (1 hunks)
🔇 Additional comments (10)
frontend/src/components/PopUpMessages/PopUpMessages.jsx (4)

1-4: Imports look fresh and clean
No issues spotted here. Keep on rockin’ these dependencies.


6-13: Default props provide clarity
These defaults simplify usage and make the component more robust. Nicely done.


14-35: Handling unknown message types
Returning null when the type is unexpected might surprise users. Consider a fallback icon or an explanatory message.


67-67: Export is smooth
Exporting at the bottom is a common practice that helps with readability. Stay the course!

frontend/src/components/PopUpMessages/PopUpMessages.module.scss (6)

1-1: Global styles import
Using SCSS modules plus a global import is a sweet combo. Good job bridging these styles.


3-17: .container positioning
Absolute placement works, but test on various viewports to ensure it doesn’t clip or stack awkwardly.


19-28: .iconAndText arrangement
The horizontal flex layout looks jammin’. Makes sense for icons and text side by side.


55-63: Shared button styles
Merging .acceptButton and .dismiss rules is practical. Reduces duplication and keeps it all tidy.


65-69: .acceptButton styles
The added background and padding create strong emphasis for the acceptance path. Works fine.


71-79: .dismiss hover
The hover effect adds subtle interactivity. Nicely done.

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

🧹 Nitpick comments (1)
frontend/src/components/PopUpMessages/PopUpMessages.jsx (1)

48-63: Ensure event listener behaviour is robust.

While the solution works well for dismissing the popup outside its boundaries, kindly watch out for potential performance concerns when adding global event listeners if this pattern is repeated throughout the application. Otherwise, your code remains as steady as a well-cooked pot of mom’s spaghetti.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4fcb3fb and 856cdf6.

📒 Files selected for processing (2)
  • frontend/src/components/PopUpMessages/PopUpMessages.jsx (1 hunks)
  • frontend/src/components/PopUpMessages/usePopUp.js (1 hunks)
🔇 Additional comments (2)
frontend/src/components/PopUpMessages/usePopUp.js (1)

1-14: Solid introduction of a custom hook.

This code is clean and simple, so there’s no need for sweaty palms or trembling knees here—this hook does exactly what’s advertised without extra overhead. Nicely done.

frontend/src/components/PopUpMessages/PopUpMessages.jsx (1)

65-65: Conditional rendering is on point.

Conditionally returning null when isOpen is false is a great approach to avoid rendering overhead—definitely no sign of shaky execution here.

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

🧹 Nitpick comments (2)
frontend/src/components/PopUpMessages/PopUpMessages.jsx (2)

17-38: This switch statement's heavier than a plate of spaghetti! Let's make it lighter! 🍝

Consider refactoring the icon logic using an object lookup and moving those hardcoded colors to a constants file.

+const POPUP_TYPES = {
+  INFO: 1,
+  ERROR: 2,
+  SUCCESS: 3,
+};
+
+const ICON_COLORS = {
+  ERROR: "#D92D20",
+  SUCCESS: "#079455",
+};
+
+const ICONS_MAP = {
+  [POPUP_TYPES.INFO]: (props) => <InfoOutlinedIcon {...props} />,
+  [POPUP_TYPES.ERROR]: (props) => (
+    <ErrorOutlineOutlinedIcon {...props} style={{ color: ICON_COLORS.ERROR }} />
+  ),
+  [POPUP_TYPES.SUCCESS]: (props) => (
+    <ErrorOutlineOutlinedIcon {...props} style={{ color: ICON_COLORS.SUCCESS }} />
+  ),
+};
+
 const getIcon = () => {
-  switch (type) {
-    case 1:
-      return <InfoOutlinedIcon className={styles.icon} />;
-    // ... rest of switch
-  }
+  const IconComponent = ICONS_MAP[type];
+  return IconComponent ? <IconComponent className={styles.icon} /> : null;
 };

39-45: These styles are scattered like dropped spaghetti! Let's clean it up! 🧹

Move these inline styles to your SCSS module and use CSS custom properties for the magic numbers.

// In PopUpMessages.module.scss
+:root {
+  --popup-max-width-default: 30rem;
+  --popup-max-width-compact: 20rem;
+  --message-margin-default: 0.5rem 0;
+}

+.container {
+  &[data-type="4"],
+  &[data-type="5"] {
+    max-width: var(--popup-max-width-compact);
+  }
+  &:not([data-type="4"]):not([data-type="5"]) {
+    max-width: var(--popup-max-width-default);
+  }
+}

+.message {
+  margin: var(--message-margin-default);
+  &[data-type="5"] {
+    margin: 0;
+  }
+}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 856cdf6 and 3716538.

📒 Files selected for processing (1)
  • frontend/src/components/PopUpMessages/PopUpMessages.jsx (1 hunks)
🔇 Additional comments (2)
frontend/src/components/PopUpMessages/PopUpMessages.jsx (2)

83-89: The close button's accessibility is already cooking! Bon appétit! 👨‍🍳

Nice job adding the aria-label to the close button! That's some good accessibility pasta right there!


75-78: ⚠️ Potential issue

These buttons are like meatballs without sauce - they need some handlers! 🍝

The left and right buttons are missing onClick handlers. Also, consider adding aria-labels for better accessibility.

 <div className={styles.buttons}>
   <button 
     className={styles.dismiss}
+    onClick={onLeftButtonClick}
+    aria-label={leftBtnText}
   >
     {leftBtnText}
   </button>
   <button 
     className={styles.acceptButton}
+    onClick={onRightButtonClick}
+    aria-label={rightBtnText}
   >
     {rightBtnText}
   </button>
 </div>

Likely invalid or redundant comment.

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

🧹 Nitpick comments (3)
frontend/src/components/PopUpMessages/PopUpMessages.jsx (3)

18-39: Let's clean up this icon logic faster than mom's spaghetti sauce! 🍝

The switch statement could use some cleanup to avoid repeating ourselves. Also, those magic numbers are making me nervous like knees weak, arms heavy!

Here's a cleaner approach:

+const ICON_CONFIGS = {
+  1: { icon: InfoOutlinedIcon, color: undefined },
+  2: { icon: ErrorOutlineOutlinedIcon, color: "#D92D20" },
+  3: { icon: ErrorOutlineOutlinedIcon, color: "#079455" }
+};

 const getIcon = () => {
-  switch (type) {
-    case 1:
-      return <InfoOutlinedIcon className={styles.icon} />;
-    case 2:
-      return (
-        <ErrorOutlineOutlinedIcon
-          className={styles.icon}
-          style={{ color: "#D92D20" }}
-        />
-      );
-    case 3:
-      return (
-        <ErrorOutlineOutlinedIcon
-          className={styles.icon}
-          style={{ color: "#079455" }}
-        />
-      );
-    default:
-      return null;
-  }
+  const config = ICON_CONFIGS[type];
+  if (!config) return null;
+  
+  const IconComponent = config.icon;
+  return (
+    <IconComponent 
+      className={styles.icon} 
+      style={config.color ? { color: config.color } : undefined}
+    />
+  );
 };

40-46: These styles are spread like sauce on spaghetti! 🍝

Let's move these inline styles to the SCSS module and use constants for better maintainability.

Consider moving these styles to your SCSS module:

// In PopUpMessages.module.scss
.container {
  &--compact {
    max-width: 20rem;
  }
  
  &--default {
    max-width: 30rem;
  }
}

.message {
  margin: 0.5rem 0;
  
  &--compact {
    margin: 0;
  }
}

Then update your JSX:

-const containerStyle = {
-  maxWidth: type === 4 || type === 5 ? "20rem" : "30rem",
-};
-
-const messageStyle = {
-  margin: type === 5 ? "0" : "0.5rem 0px",
-};

+const containerClass = `${styles.container} ${
+  (type === 4 || type === 5) ? styles['container--compact'] : styles['container--default']
+}`;
+
+const messageClass = `${styles.message} ${
+  type === 5 ? styles['message--compact'] : ''
+}`;

48-64: These comments are as casual as eating spaghetti with your hands! 🍝

While the code is solid, let's make those comments more professional than a five-star Italian restaurant.

-//Close PopUp when we click outside of the component
+// Handle click events outside the popup component to trigger closure
 
-//Add callback separately so we can cleanup later
+// Define callback separately for proper cleanup in useEffect
 
-//CLEAN UP to prevent memory leaks
+// Cleanup event listener to prevent memory leaks
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3716538 and eb539d9.

📒 Files selected for processing (1)
  • frontend/src/components/PopUpMessages/PopUpMessages.jsx (1 hunks)
🔇 Additional comments (2)
frontend/src/components/PopUpMessages/PopUpMessages.jsx (2)

1-17: Yo, these imports and props are cleaner than mom's kitchen! 🍝

The component setup is looking fresh with proper imports and clean default values. Props declaration is neat and tidy - no spaghetti code here!


95-103: These PropTypes are as well-organized as mom's recipe book! 🍝

The prop validation is looking clean and proper. Nice job making the essential props required!

@Yup03 Yup03 marked this pull request as draft January 2, 2025 10:35
@erenfn
Copy link
Collaborator

erenfn commented Jan 4, 2025

Hey, I realized this was taking some time. We have a release in one week, so we are trying to finish all the issues before then. Mandeep from our internal team solved the issue in #464. But thank you so much for your time

@erenfn erenfn closed this Jan 4, 2025
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