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

Fixed LeftDrawerOrg Visibility #3239

Merged

Conversation

aadhil2k4
Copy link
Contributor

@aadhil2k4 aadhil2k4 commented Jan 10, 2025

What kind of change does this PR introduce?

Bugfix

Issue Number:

Fixes #3237

Did you add tests for your changes?

No, only visible changes

Snapshots/Videos:

LeftDrawerOrg_Fix.mp4

Does this PR introduce a breaking change?

No

Have you read the contributing guide?

Yes

Summary by CodeRabbit

  • New Features

    • Enhanced drawer visibility behavior, ensuring it is visible by default when no explicit hide state is set.
  • Tests

    • Added test cases to verify drawer visibility behavior when the hideDrawer prop is null or has a defined value.

Copy link
Contributor

coderabbitai bot commented Jan 10, 2025

Walkthrough

The pull request modifies the LeftDrawerOrg component in the Talawa admin interface by introducing a new useEffect hook. This hook ensures that the drawer is visible by default when the hideDrawer prop is not explicitly set to null. The change addresses an issue where the drawer elements were not visible upon page refresh or initial load, ensuring consistent drawer visibility.

Changes

File Change Summary
src/components/LeftDrawerOrg/LeftDrawerOrg.tsx Added useEffect hook to set hideDrawer to false if it is null on component mount
src/components/LeftDrawer/LeftDrawer.spec.tsx Added tests to check behavior of hideDrawer prop when initially null and when it has a value
src/components/LeftDrawerOrg/LeftDrawerOrg.spec.tsx Added tests to verify hideDrawer behavior when initially null and when it has a value

Assessment against linked issues

Objective Addressed Explanation
Fix Initial LeftDrawerOrg Visibility [#3237]

Possibly related issues

Possibly related PRs

Suggested reviewers

  • rishav-jha-mech
  • palisadoes

Poem

🐰 A drawer's tale of hide and seek,
Visibility now no longer bleak,
With one small hook, we set it free,
No more shall elements hide from me!
Refresh away, dear user's delight! 🎉


📜 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 06375b2 and 96bbb2a.

📒 Files selected for processing (2)
  • src/components/LeftDrawer/LeftDrawer.spec.tsx (1 hunks)
  • src/components/LeftDrawerOrg/LeftDrawerOrg.spec.tsx (1 hunks)
🧰 Additional context used
📓 Learnings (1)
src/components/LeftDrawerOrg/LeftDrawerOrg.spec.tsx (1)
Learnt from: Doraemon012
PR: PalisadoesFoundation/talawa-admin#1988
File: src/components/LeftDrawerOrg/LeftDrawerOrg.test.tsx:282-282
Timestamp: 2024-11-12T10:40:58.654Z
Learning: In the test 'Component should be rendered properly' within 'Testing LeftDrawerOrg component for SUPERADMIN', setting 'SuperAdmin' to false is intentional.
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Test Application
  • GitHub Check: Analyse Code With CodeQL (javascript)
🔇 Additional comments (4)
src/components/LeftDrawer/LeftDrawer.spec.tsx (2)

224-239: LGTM! Well-structured test for null hideDrawer initialization.

The test effectively verifies that the drawer becomes visible by default when hideDrawer is null.


241-258: LGTM! Good negative test case.

The test properly verifies that setHideDrawer is not called when hideDrawer already has a value.

src/components/LeftDrawerOrg/LeftDrawerOrg.spec.tsx (2)

476-496: LGTM! Comprehensive test setup for null hideDrawer initialization.

The test properly verifies the default visibility behavior with all required providers and async handling.


498-517: LGTM! Well-implemented negative test case.

The test effectively verifies that setHideDrawer is not called when hideDrawer has a value, maintaining consistency with LeftDrawer tests.


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.

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

Our Pull Request Approval Process

Thanks for contributing!

Testing Your Code

Remember, your PRs won't be reviewed until these criteria are met:

  1. We don't merge PRs with poor code quality.
    1. Follow coding best practices such that CodeRabbit.ai approves your PR.
  2. We don't merge PRs with failed tests.
    1. When tests fail, click on the Details link to learn more.
    2. Write sufficient tests for your changes (CodeCov Patch Test). Your testing level must be better than the target threshold of the repository
    3. Tests may fail if you edit sensitive files. Ask to add the ignore-sensitive-files-pr label if the edits are necessary.
  3. We cannot merge PRs with conflicting files. These must be fixed.

Our policies make our code better.

Reviewers

Do not assign reviewers. Our Queue Monitors will review your PR and assign them.
When your PR has been assigned reviewers contact them to get your code reviewed and approved via:

  1. comments in this PR or
  2. our slack channel

Reviewing Your Code

Your reviewer(s) will have the following roles:

  1. arbitrators of future discussions with other contributors about the validity of your changes
  2. point of contact for evaluating the validity of your work
  3. person who verifies matching issues by others that should be closed.
  4. person who gives general guidance in fixing your tests

CONTRIBUTING.md

Read our CONTRIBUTING.md file. Most importantly:

  1. PRs with issues not assigned to you will be closed by the reviewer
  2. Fix the first comment in the PR so that each issue listed automatically closes

Other

  1. 🎯 Please be considerate of our volunteers' time. Contacting the person who assigned the reviewers is not advised unless they ask for your input. Do not @ the person who did the assignment otherwise.
  2. Read the CONTRIBUTING.md file make

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 (2)
src/components/LeftDrawerOrg/LeftDrawerOrg.tsx (2)

77-82: LGTM! Consider adding a comment to explain the initialization logic.

The useEffect hook correctly initializes the drawer's visibility state. To improve maintainability, consider adding a comment explaining why null is treated as false.

  useEffect(() => {
+   // Initialize drawer visibility to visible (false) when not explicitly set (null)
    if (hideDrawer === null) {
      setHideDrawer(false);
    }
  }, []);

Line range hint 16-21: Consider improving the hideDrawer prop type.

The current type allows null which is only used for initialization. Consider using a default value instead:

 export interface InterfaceLeftDrawerProps {
   orgId: string;
   targets: TargetsType[];
-  hideDrawer: boolean | null;
+  hideDrawer?: boolean;
   setHideDrawer: React.Dispatch<React.SetStateAction<boolean | null>>;
 }

Then provide a default prop:

const leftDrawerOrg = ({
  targets,
  orgId,
  hideDrawer = false,
  setHideDrawer,
}: InterfaceLeftDrawerProps): JSX.Element => {

This would eliminate the need for null checking and make the component's API more intuitive.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between eceaad9 and 06375b2.

📒 Files selected for processing (1)
  • src/components/LeftDrawerOrg/LeftDrawerOrg.tsx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Test Application
  • GitHub Check: Analyse Code With CodeQL (javascript)
🔇 Additional comments (1)
src/components/LeftDrawerOrg/LeftDrawerOrg.tsx (1)

77-82: Verify the fix resolves the visibility issue.

The implementation effectively fixes the drawer visibility by:

  1. Initializing hideDrawer to false when null
  2. Maintaining existing visibility control when explicitly set
  3. Using proper React patterns for state initialization

The fix aligns with the PR objective to address the visibility bug (#3237).

Also applies to: 16-21

✅ Verification successful

✓ The initialization pattern is consistent with codebase practices

The implementation in LeftDrawerOrg follows an established pattern across the codebase where drawer components initialize hideDrawer from null to false. This is consistent with:

  • Similar initialization in LeftDrawer component
  • Existing test coverage for null state handling
  • Usage patterns in parent components
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify no other components rely on null state
rg -l "hideDrawer.*null" src/

Length of output: 775


Script:

#!/bin/bash
# Check the context of hideDrawer null usage
rg "hideDrawer.*null" src/ -B 2 -A 2

Length of output: 16145

coderabbitai[bot]
coderabbitai bot previously approved these changes Jan 10, 2025
Copy link
Contributor

@palisadoes palisadoes left a comment

Choose a reason for hiding this comment

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

  1. What test can be done for this and the other left drawer you fixed?
  2. Please add tests if possible for this and the previous PR
  3. This cannot happen again. It's an embarrassing failure.

@aadhil2k4
Copy link
Contributor Author

LeftDrawer:
SCR-20250111-bcaq
LeftDrawerOrg:
SCR-20250111-beka

Copy link

codecov bot commented Jan 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.17%. Comparing base (eceaad9) to head (96bbb2a).
Report is 7 commits behind head on develop-postgres.

Additional details and impacted files
@@                  Coverage Diff                  @@
##           develop-postgres    #3239       +/-   ##
=====================================================
+ Coverage             10.74%   90.17%   +79.43%     
=====================================================
  Files                   309      330       +21     
  Lines                  7802     8491      +689     
  Branches               1729     1875      +146     
=====================================================
+ Hits                    838     7657     +6819     
+ Misses                 6900      604     -6296     
- Partials                 64      230      +166     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@aadhil2k4 aadhil2k4 requested a review from palisadoes January 10, 2025 18:55
@palisadoes
Copy link
Contributor

Is this fixed for both screens in this PR? It looks so, but I need confirmation

@aadhil2k4
Copy link
Contributor Author

Is this fixed for both screens in this PR? It looks so, but I need confirmation

Yes, it is fixed for both the screens.

@palisadoes palisadoes merged commit e343b0c into PalisadoesFoundation:develop-postgres Jan 11, 2025
18 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.

2 participants