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

fix(reports): add tooltip to the late reports #3254

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

FussuChalice
Copy link
Contributor

Description

Add small info icon + tooltip explaining how the mechanics of late reports work in Organized: Mark a report as 'Late' if the monthly branch office report has already been submitted. Late report will automatically be included in next month's submission.

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

Fixes # (issue)

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules

Copy link

vercel bot commented Dec 17, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
organized-app ✅ Ready (Inspect) Visit Preview Dec 17, 2024 0:18am

@rhahao
Copy link
Member

rhahao commented Dec 17, 2024

Copy link
Contributor

coderabbitai bot commented Dec 17, 2024

Walkthrough

The changes involve adding a tooltip feature to the LateReport component in two different contexts: field service and publisher records details. A new state variable lateCheckboxHelpIsHovered is introduced in the useLateReport hook to manage the hover state of a help icon. The implementation adds an IconHelpFilled next to the checkbox, which triggers a tooltip when hovered, providing additional contextual information to users.

Changes

File Path Change Summary
src/features/reports/.../late_report/index.tsx (Field Service) - Added imports for Box, Tooltip, IconHelpFilled
- Updated useLateReport hook to include hover state variables
- Wrapped checkbox in Box with tooltip functionality
src/features/reports/.../late_report/useLateReport.tsx (Field Service) - Added lateCheckboxHelpIsHovered state
- Updated hook return to include hover state setter and value
src/features/reports/.../late_report/index.tsx (Publisher Records) - Similar changes to Field Service implementation
- Added tooltip and hover state management for checkbox
src/features/reports/.../late_report/useLateReport.tsx (Publisher Records) - Added lateCheckboxHelpIsHovered state
- Updated hook return to include hover state setter and value

Sequence Diagram

sequenceDiagram
    participant User
    participant Checkbox
    participant HelpIcon
    participant Tooltip

    User->>HelpIcon: Hover
    HelpIcon->>Checkbox: Update hover state
    Checkbox->>Tooltip: Trigger display
    Tooltip-->>User: Show contextual help
Loading

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

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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

sonarcloud bot commented Dec 17, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
56.6% Duplication on New Code (required ≤ 50%)

See analysis details on SonarQube Cloud

@FussuChalice
Copy link
Contributor Author

@rhahao Do you think we should create a new component, just for these purposes (tooltip with icon and checkbox)? Then we can get rid of code duplication. Or is this okay?

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)
src/features/reports/publisher_records_details/report_details/late_report/useLateReport.tsx (1)

74-75: Update TypeScript return type definition

The hook's return type should be updated to include the new hover state properties.

Add these properties to the return type:

interface UseLateReportReturn {
  // ... existing properties
  lateCheckboxHelpIsHovered: boolean;
  setLateCheckboxHelpIsHovered: (value: boolean) => void;
}
src/features/reports/field_service/report_details/late_report/index.tsx (1)

35-54: Add aria-label to improve accessibility

The help icon should have an aria-label for better screen reader support.

 <Box
   onMouseEnter={() => setLateCheckboxHelpIsHovered(true)}
   onMouseLeave={() => setLateCheckboxHelpIsHovered(false)}
+  aria-label={t('tr_lateReportTooltip')}
+  role="button"
   sx={{
     display: 'flex',
     alignItems: 'center',
   }}
 >
src/features/reports/publisher_records_details/report_details/late_report/index.tsx (3)

6-6: Remove unused import

The IconInfo import appears to be unused in the current implementation.

-import { IconHelpFilled, IconInfo } from '@components/icons';
+import { IconHelpFilled } from '@components/icons';

54-73: Add aria-label to improve accessibility

The help icon should have an aria-label for better screen reader support, similar to the field service component.

 <Box
   onMouseEnter={() => setLateCheckboxHelpIsHovered(true)}
   onMouseLeave={() => setLateCheckboxHelpIsHovered(false)}
+  aria-label={t('tr_lateReportTooltip')}
+  role="button"
   sx={{
     display: 'flex',
     alignItems: 'center',
   }}
 >

Line range hint 1-89: Consider extracting shared tooltip component

Both LateReport components share identical tooltip implementation. Consider extracting this into a shared component to improve maintainability.

Create a new shared component:

// src/features/reports/shared/LateReportTooltip.tsx
interface LateReportTooltipProps {
  isHovered: boolean;
  onHoverChange: (value: boolean) => void;
}

const LateReportTooltip = ({ isHovered, onHoverChange }: LateReportTooltipProps) => {
  const { t } = useAppTranslation();
  
  return (
    <Tooltip title={t('tr_lateReportTooltip')} placement="bottom-start">
      <Box
        onMouseEnter={() => onHoverChange(true)}
        onMouseLeave={() => onHoverChange(false)}
        aria-label={t('tr_lateReportTooltip')}
        role="button"
        sx={{
          display: 'flex',
          alignItems: 'center',
        }}
      >
        <IconHelpFilled
          width={16}
          height={16}
          color={isHovered ? 'var(--accent-main)' : 'var(--black)'}
        />
      </Box>
    </Tooltip>
  );
};
src/features/reports/field_service/report_details/late_report/useLateReport.tsx (1)

133-141: Add TypeScript interface and JSDoc documentation.

Consider adding type safety and documentation for better maintainability:

+ interface UseLateReportResult {
+   show_late: boolean;
+   late_sent: string;
+   checked: boolean;
+   handleChecked: (value: boolean) => Promise<void>;
+   readOnly: boolean;
+   setLateCheckboxHelpIsHovered: (value: boolean) => void;
+   lateCheckboxHelpIsHovered: boolean;
+ }

+ /**
+  * Hook to manage late report state and interactions
+  * @param person - The person associated with the report
+  * @returns {UseLateReportResult} Object containing late report state and handlers
+  */
  const useLateReport = (person: PersonType): UseLateReportResult => {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cba7411 and 92b4c6b.

⛔ Files ignored due to path filters (1)
  • src/locales/en/congregation.json is excluded by !**/*.json
📒 Files selected for processing (4)
  • src/features/reports/field_service/report_details/late_report/index.tsx (1 hunks)
  • src/features/reports/field_service/report_details/late_report/useLateReport.tsx (2 hunks)
  • src/features/reports/publisher_records_details/report_details/late_report/index.tsx (3 hunks)
  • src/features/reports/publisher_records_details/report_details/late_report/useLateReport.tsx (3 hunks)
🔇 Additional comments (4)
src/features/reports/publisher_records_details/report_details/late_report/useLateReport.tsx (1)

16-17: LGTM: Clean state management addition

The hover state management follows React patterns and is appropriately initialized.

src/features/reports/field_service/report_details/late_report/index.tsx (1)

27-55: LGTM: Clean tooltip implementation

The tooltip implementation follows MUI best practices and maintains consistent styling with CSS variables.

src/features/reports/field_service/report_details/late_report/useLateReport.tsx (2)

28-30: LGTM! State variable follows React conventions.

The new hover state is well-named and appropriately initialized.


139-140: Verify consistent tooltip implementation.

The hook is used in multiple components. Let's verify that the tooltip implementation is consistent across all usage locations.

✅ Verification successful

Tooltip implementation is consistent across late report components

The tooltip implementation for the late report feature is consistent in both locations:

  1. src/features/reports/field_service/report_details/late_report/index.tsx:
<Tooltip title={t('tr_lateReportTooltip')} placement="bottom-start">
    <IconHelpFilled
        lateCheckboxHelpIsHovered
    />
</Tooltip>
  1. src/features/reports/publisher_records_details/report_details/late_report/index.tsx:
<Tooltip title={t('tr_lateReportTooltip')} placement="bottom-start">
    <IconHelpFilled
        lateCheckboxHelpIsHovered
    />
</Tooltip>

Both implementations use the same:

  • Custom Tooltip component
  • Same tooltip text key (tr_lateReportTooltip)
  • Same placement (bottom-start)
  • Same icon component (IconHelpFilled)
  • Same hover state handling (lateCheckboxHelpIsHovered)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for components using this hook and verify tooltip implementation
echo "Searching for components using useLateReport hook..."
rg -l "useLateReport" --type tsx

# Search for tooltip-related code in those components
echo "\nChecking tooltip implementation in components..."
rg "lateCheckboxHelpIsHovered|IconHelpFilled|Tooltip" --type tsx

Length of output: 381


Script:

#!/bin/bash
# Search for components using this hook and verify tooltip implementation
echo "Searching for components using useLateReport hook..."
rg -l "useLateReport"

# Search for tooltip-related code in those components
echo -e "\nChecking tooltip implementation in components..."
rg "lateCheckboxHelpIsHovered|IconHelpFilled|Tooltip"

Length of output: 28490

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