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

[Simple Homepage] UI changes to better support Mobile/Tablet Layout #7159

Merged
merged 3 commits into from
Nov 8, 2024

Conversation

bobbykolev
Copy link
Contributor

@bobbykolev bobbykolev commented Nov 7, 2024

#7041
See the ticket for details.

Summary by CodeRabbit

Release Notes

  • New Features

    • Added localization support with a new "Menu" label.
    • Introduced an expandable prop for the DashboardMenu, allowing for collapsible menu functionality.
    • Enhanced PageContentBlockCollapsible to accept additional header properties for customization.
  • Improvements

    • Improved responsiveness of the dashboard layout, adapting component visibility based on screen size.
  • Refactor

    • Streamlined rendering logic in DashboardActivity and MyDashboard components for better maintainability.

Copy link

coderabbitai bot commented Nov 7, 2024

Walkthrough

This pull request introduces several changes across multiple components to enhance localization support and improve the responsiveness of the user interface. A new key for the menu has been added to the localization file, while several components have been updated to support conditional rendering based on screen size. Notably, the DashboardMenu now supports an expandable prop, and various components utilize the useMediaQuery hook to adapt their layouts for mobile devices.

Changes

File Change Summary
src/core/i18n/en/translation.en.json Added key "menu": "Menu" in the "common" section.
src/core/ui/content/PageContentBlockCollapsible.tsx Added optional property collapseHeaderProps to PageContentBlockCollapsibleProps interface.
src/main/topLevelPages/myDashboard/DashboardMenu/DashboardMenu.tsx Introduced expandable prop to DashboardMenu, allowing for collapsible menu rendering.
src/main/topLevelPages/myDashboard/DashboardMenu/dashboardMenuTypes.ts Added optional property expandable to DashboardMenuProps type.
src/main/topLevelPages/myDashboard/DashboardWithMemberships/DashboardActivity.tsx Refactored rendering logic with new functions for activity blocks based on device screen size.
src/main/topLevelPages/myDashboard/MyDashboardWithMemberships.tsx Added useMediaQuery to conditionally render InfoColumn based on mobile state.
src/main/topLevelPages/myDashboard/MyDashboardWithoutMemberships.tsx Added useMediaQuery to conditionally render InfoColumn and modified DashboardMenu for mobile responsiveness.

Possibly related PRs

Suggested labels

client, translations

Suggested reviewers

  • reactoholic

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:

  • 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 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.

@bobbykolev bobbykolev changed the title UI changes to better support Mobile/Tablet Layout [Simple Homepage] UI changes to better support Mobile/Tablet Layout Nov 7, 2024
@bobbykolev
Copy link
Contributor Author

@coderabbitai review

Copy link

coderabbitai bot commented Nov 7, 2024

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@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 and nitpick comments (8)
src/main/topLevelPages/myDashboard/DashboardMenu/dashboardMenuTypes.ts (1)

5-8: Consider adding JSDoc documentation for the DashboardMenuProps interface.

Adding documentation would help other developers understand the purpose and relationship between the compact and expandable props.

+/**
+ * Props for the DashboardMenu component
+ * @property {boolean} [compact] - Renders a compact version of the menu
+ * @property {boolean} [expandable] - Enables collapsible behavior for responsive layouts
+ */
 export type DashboardMenuProps = {
   compact?: boolean;
   expandable?: boolean;
 };
src/core/ui/content/PageContentBlockCollapsible.tsx (1)

16-16: Consider prop collision prevention

While the implementation works, there's a potential for prop collisions between spread props and existing Box properties. Consider these improvements:

-  ({ header, primaryAction, children, collapseHeaderProps, ...props }, ref) => {
+  ({ header, primaryAction, children, collapseHeaderProps = {}, ...props }, ref) => {
   // ...
-          {...collapseHeaderProps}
+          {...(collapseHeaderProps.onClick ? { ...collapseHeaderProps } : {
+            ...collapseHeaderProps,
+            onClick: () => setIsCollapsed(!isCollapsed)
+          })}

This change would:

  1. Provide a default empty object for collapseHeaderProps
  2. Handle cases where custom onClick is provided in collapseHeaderProps

Also applies to: 26-26

src/main/topLevelPages/myDashboard/MyDashboardWithMemberships.tsx (1)

23-24: Consider renaming the variable for clarity.

While the comment explains the actual breakpoint, the variable name isMobile could be misleading since it's actually checking for a tablet breakpoint. Consider using a more accurate name like isTabletOrMobile or isBelowDesktop to make the code more self-documenting.

- // using the isMobile convention but this is actually a tablet breakpoint
- const isMobile = useMediaQuery<Theme>(theme => theme.breakpoints.down('md'));
+ const isTabletOrMobile = useMediaQuery<Theme>(theme => theme.breakpoints.down('md'));
src/main/topLevelPages/myDashboard/DashboardWithMemberships/DashboardActivity.tsx (2)

25-41: Consider extracting a common activity block component.

Both rendering functions share similar structure and could be abstracted into a reusable component to reduce code duplication.

Consider refactoring to:

+interface ActivityBlockProps {
+  title: string;
+  columns: number;
+  children: React.ReactNode;
+}
+
+const ActivityBlock: React.FC<ActivityBlockProps> = ({ title, columns, children }) => (
+  <PageContentColumn columns={columns}>
+    <PageContentBlock>
+      <PageContentBlockHeader title={title} />
+      {children}
+    </PageContentBlock>
+  </PageContentColumn>
+);
+
 const renderSpaceActivityBlock = () => (
-  <PageContentColumn key="space-activity" columns={blockColumns}>
-    <PageContentBlock>
-      <PageContentBlockHeader title={t('pages.home.sections.latestContributions.title')} />
+  <ActivityBlock
+    key="space-activity"
+    columns={blockColumns}
+    title={t('pages.home.sections.latestContributions.title')}
+  >
      <LatestContributions spaceMemberships={flatSpacesWithMemberships} />
-    </PageContentBlock>
-  </PageContentColumn>
+  </ActivityBlock>
 );

46-47: Improve readability and key handling in conditional rendering.

While the current implementation works, it could be made more explicit and maintainable.

Consider refactoring to:

-      {!isMobile && [renderSpaceActivityBlock(), renderMyActivityBlock()]}
-      {isMobile && [renderMyActivityBlock(), renderSpaceActivityBlock()]}
+      {!isMobile && (
+        <>
+          {renderSpaceActivityBlock()}
+          {renderMyActivityBlock()}
+        </>
+      )}
+      {isMobile && (
+        <>
+          {renderMyActivityBlock()}
+          {renderSpaceActivityBlock()}
+        </>
+      )}

This approach:

  • Uses explicit React.Fragment syntax for better readability
  • Maintains the same functionality while being more declarative
src/main/topLevelPages/myDashboard/MyDashboardWithoutMemberships.tsx (1)

27-28: Consider improving the variable naming and documentation.

While the comment helps clarify the intent, the variable name isMobile is misleading since it's actually checking for tablet breakpoints. Consider:

- // using the isMobile convention but this is actually a tablet breakpoint
- const isMobile = useMediaQuery<Theme>(theme => theme.breakpoints.down('md'));
+ // Checks if viewport is smaller than 'md' breakpoint (< 900px)
+ const isTabletOrMobile = useMediaQuery<Theme>(theme => theme.breakpoints.down('md'));
src/main/topLevelPages/myDashboard/DashboardMenu/DashboardMenu.tsx (2)

115-118: Consider combining filter and map operations

The renderContent function is well-structured, but consider combining filter and map for better performance:

-    {items.filter(item => item.isVisible(activityEnabled, compact)).map((item, index) => renderMenuItem(item, index))}
+    {items.reduce((acc, item, index) => {
+      if (item.isVisible(activityEnabled, compact)) {
+        acc.push(renderMenuItem(item, index));
+      }
+      return acc;
+    }, [] as React.ReactNode[])}

121-143: Consider extracting header styles to theme or constants

The collapsible menu implementation is good, but the inline styles could be better organized:

+ const HEADER_STYLES = {
+   wrapper: {
+     position: 'relative' as const,
+   },
+   badge: {
+     position: 'absolute' as const,
+   },
+   icon: {
+     color: 'neutral.light',
+   },
+ };

  // In JSX
- sx={{ position: 'relative' }}
+ sx={HEADER_STYLES.wrapper}
- sx={{ position: 'absolute' }}
+ sx={HEADER_STYLES.badge}
- sx={{ color: 'neutral.light' }}
+ sx={HEADER_STYLES.icon}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between a96ca22 and 604913b.

📒 Files selected for processing (7)
  • src/core/i18n/en/translation.en.json (1 hunks)
  • src/core/ui/content/PageContentBlockCollapsible.tsx (2 hunks)
  • src/main/topLevelPages/myDashboard/DashboardMenu/DashboardMenu.tsx (3 hunks)
  • src/main/topLevelPages/myDashboard/DashboardMenu/dashboardMenuTypes.ts (1 hunks)
  • src/main/topLevelPages/myDashboard/DashboardWithMemberships/DashboardActivity.tsx (1 hunks)
  • src/main/topLevelPages/myDashboard/MyDashboardWithMemberships.tsx (2 hunks)
  • src/main/topLevelPages/myDashboard/MyDashboardWithoutMemberships.tsx (2 hunks)
🧰 Additional context used
📓 Path-based instructions (7)
src/core/i18n/en/translation.en.json (1)

Pattern src/**/*.json: Review the JSON files for correct syntax and structure.
Ensure that the configuration and data are accurate and follow the project's standards.
Check for sensitive data exposure and ensure that the data is properly validated.

src/core/ui/content/PageContentBlockCollapsible.tsx (1)

Pattern src/**/*.{ts,tsx,js}: Review the React.js/TypeScript/JavaScript code for best practices and potential bugs.
Ensure that the code adheres to TypeScript's typing system and modern standards.
Ensure sufficient error handling and logging is present.
Check for common security vulnerabilities such as:

  • SQL Injection
  • XSS (Cross-Site Scripting)
  • CSRF (Cross-Site Request Forgery)
  • Insecure dependencies
  • Sensitive data exposure
src/main/topLevelPages/myDashboard/DashboardMenu/DashboardMenu.tsx (1)

Pattern src/**/*.{ts,tsx,js}: Review the React.js/TypeScript/JavaScript code for best practices and potential bugs.
Ensure that the code adheres to TypeScript's typing system and modern standards.
Ensure sufficient error handling and logging is present.
Check for common security vulnerabilities such as:

  • SQL Injection
  • XSS (Cross-Site Scripting)
  • CSRF (Cross-Site Request Forgery)
  • Insecure dependencies
  • Sensitive data exposure
src/main/topLevelPages/myDashboard/DashboardMenu/dashboardMenuTypes.ts (1)

Pattern src/**/*.{ts,tsx,js}: Review the React.js/TypeScript/JavaScript code for best practices and potential bugs.
Ensure that the code adheres to TypeScript's typing system and modern standards.
Ensure sufficient error handling and logging is present.
Check for common security vulnerabilities such as:

  • SQL Injection
  • XSS (Cross-Site Scripting)
  • CSRF (Cross-Site Request Forgery)
  • Insecure dependencies
  • Sensitive data exposure
src/main/topLevelPages/myDashboard/DashboardWithMemberships/DashboardActivity.tsx (1)

Pattern src/**/*.{ts,tsx,js}: Review the React.js/TypeScript/JavaScript code for best practices and potential bugs.
Ensure that the code adheres to TypeScript's typing system and modern standards.
Ensure sufficient error handling and logging is present.
Check for common security vulnerabilities such as:

  • SQL Injection
  • XSS (Cross-Site Scripting)
  • CSRF (Cross-Site Request Forgery)
  • Insecure dependencies
  • Sensitive data exposure
src/main/topLevelPages/myDashboard/MyDashboardWithMemberships.tsx (1)

Pattern src/**/*.{ts,tsx,js}: Review the React.js/TypeScript/JavaScript code for best practices and potential bugs.
Ensure that the code adheres to TypeScript's typing system and modern standards.
Ensure sufficient error handling and logging is present.
Check for common security vulnerabilities such as:

  • SQL Injection
  • XSS (Cross-Site Scripting)
  • CSRF (Cross-Site Request Forgery)
  • Insecure dependencies
  • Sensitive data exposure
src/main/topLevelPages/myDashboard/MyDashboardWithoutMemberships.tsx (1)

Pattern src/**/*.{ts,tsx,js}: Review the React.js/TypeScript/JavaScript code for best practices and potential bugs.
Ensure that the code adheres to TypeScript's typing system and modern standards.
Ensure sufficient error handling and logging is present.
Check for common security vulnerabilities such as:

  • SQL Injection
  • XSS (Cross-Site Scripting)
  • CSRF (Cross-Site Request Forgery)
  • Insecure dependencies
  • Sensitive data exposure
🔇 Additional comments (12)
src/main/topLevelPages/myDashboard/DashboardMenu/dashboardMenuTypes.ts (1)

7-7: LGTM! The new expandable prop is well-typed.

The optional boolean property is correctly implemented and aligns well with the responsive design requirements.

src/core/ui/content/PageContentBlockCollapsible.tsx (2)

3-3: LGTM: Import changes are well-organized

The addition of BoxProps to the existing Material-UI import maintains good code organization.


11-11: Verify the impact of the new optional prop

The addition of collapseHeaderProps is well-typed and maintains backward compatibility. However, let's verify existing usage to ensure no unintended side effects.

✅ Verification successful

The new optional prop is safe to add and already in use

The verification shows that collapseHeaderProps is already being used in DashboardMenu.tsx and all other existing usages of PageContentBlockCollapsible will continue to work as before since the prop is optional. The change maintains backward compatibility.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for existing usage of PageContentBlockCollapsible to verify compatibility
rg -l "PageContentBlockCollapsible" --type ts --type tsx | xargs rg -A 5 "<PageContentBlockCollapsible"

Length of output: 3553

src/main/topLevelPages/myDashboard/MyDashboardWithMemberships.tsx (2)

11-11: LGTM! Appropriate imports for responsive design.

The addition of Theme and useMediaQuery from @mui/material is the correct approach for implementing responsive behavior using Material-UI's breakpoint system.


28-35: Verify the expandable prop type definition.

The conditional rendering implementation looks good and follows responsive design best practices. However, let's verify that the expandable prop is properly typed in the DashboardMenu component.

✅ Verification successful

The expandable prop is properly typed in the DashboardMenu component

The verification confirms that the expandable prop is correctly defined as an optional boolean prop in dashboardMenuTypes.ts. This matches its usage in the conditional rendering implementation.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the expandable prop type definition in DashboardMenu
# Expected: Find the prop type definition that includes the expandable prop

# Search for the DashboardMenu type/interface definition
ast-grep --pattern 'interface $name {
  $$$
  expandable$_
  $$$
}'

# Alternatively, search for the prop types
rg -A 5 'interface.*DashboardMenu.*Props|type.*DashboardMenu.*Props'

Length of output: 726

src/main/topLevelPages/myDashboard/DashboardWithMemberships/DashboardActivity.tsx (1)

Line range hint 1-53: Implementation successfully achieves mobile responsiveness goals.

The changes effectively implement responsive layout handling with clean separation of concerns and proper use of Material-UI's responsive utilities. The code maintains type safety and follows React best practices.

src/main/topLevelPages/myDashboard/MyDashboardWithoutMemberships.tsx (2)

2-2: LGTM! Necessary imports added correctly.

The additional imports from @mui/material are properly added and required for implementing the responsive layout.


32-38: Consider adding error boundary for conditional rendering.

The conditional rendering logic is well-implemented, but adding an error boundary would improve the robustness of the component.

Consider wrapping the conditional content in an error boundary:

import { ErrorBoundary } from 'react-error-boundary';

// Inside the component
<ErrorBoundary fallback={<div>Something went wrong</div>}>
  {!isTabletOrMobile && (
    <InfoColumn>
      <DashboardMenu compact />
    </InfoColumn>
  )}
  <ContentColumn>
    {isTabletOrMobile && <DashboardMenu compact expandable />}
    {/* ... rest of the content ... */}
  </ContentColumn>
</ErrorBoundary>

Let's verify if error boundaries are already used in the codebase:

src/main/topLevelPages/myDashboard/DashboardMenu/DashboardMenu.tsx (3)

19-21: LGTM: Clean import additions

The new imports are well-organized and properly scoped for the collapsible menu functionality.


145-145: LGTM: Clean fallback rendering

The default rendering path is clean and maintains consistency with the non-expandable version.


32-32: Verify type definition for expandable prop

The expandable prop is correctly added with a default value, but let's verify its type definition.

✅ Verification successful

Type definition for expandable prop is properly defined

The DashboardMenuProps interface correctly includes the expandable prop with an optional boolean type, matching its usage in the component with the default value of false.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify DashboardMenuProps type definition
rg -A 5 "DashboardMenuProps" src/main/topLevelPages/myDashboard/DashboardMenu/dashboardMenuTypes.ts

Length of output: 259

src/core/i18n/en/translation.en.json (1)

363-363: LGTM! The new translation key follows the established conventions.

The addition of the "menu" key is well-placed within the "common" section and follows the existing naming and structure patterns. The simple translation value "Menu" is appropriate for a UI element.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Simple homepage: mobile version
2 participants