Skip to content

Smooth animation for expanding/collapsing repositories list#1069

Closed
rishyym0927 wants to merge 11 commits intoOWASP:mainfrom
rishyym0927:feature/animation
Closed

Smooth animation for expanding/collapsing repositories list#1069
rishyym0927 wants to merge 11 commits intoOWASP:mainfrom
rishyym0927:feature/animation

Conversation

@rishyym0927
Copy link
Contributor

@rishyym0927 rishyym0927 commented Mar 10, 2025

Resolves #1056

This PR introduces a global solution for expandable list animations, ensuring a smooth user experience when expanding and collapsing lists. It also refactors the project structure by introducing reusable hooks and global CSS improvements.

1️⃣ Created a Reusable Hook: useExpandableList

  1. Moved the expandable list logic into a separate hook (hooks/useExpandableList.ts).
  2. Handles animation logic (animatingOut state) to ensure a smooth transition.

3️⃣ Global CSS Improvements

  1. Introduced CSS utility classes in global.css to standardize expandable animations.
  2. Ensured consistent animation speeds across different components.

Before & After Improvements:

✅ Before:

Lists would expand/collapse abruptly.
Code for expand/collapse logic was duplicated in multiple components.
Inconsistent animation styles across the app.

✅ After:

Lists now animate smoothly when expanded/collapsed.
Centralized and reusable hook (useExpandableList).
Clean and maintainable component structure.

Video:

Recording.2025-03-10.210220.mp4

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 10, 2025

Summary by CodeRabbit

  • New Features

    • Added a clear fallback message when no repository data is available.
  • Refactor

    • Enhanced interactions for contributor and repository lists for smoother toggling and improved feedback.
  • Style

    • Introduced fade, bounce, and subtle transition animations for a more polished visual experience.
  • Tests

    • Updated test flows to ensure reliable simulation of list interactions and section loading.

Walkthrough

The pull request introduces several changes. A new custom hook, useExpandableList, replaces local state management in components handling expandable lists, updating related function signatures and rendering logic. UI components have been adjusted by moving identifier attributes and modifying conditional rendering for repository display. In addition, new CSS keyframe animations and classes have been added to enhance visual transitions. Test files have also been updated to use improved selectors and waiting logic, ensuring more reliable element detection.

Changes

Files Change Summary
frontend/src/components/ToggleContributors.tsx, frontend/src/components/ToggleableList.tsx, frontend/src/hooks/useExpandableList.ts Refactored state management by replacing local useState usage with the new useExpandableList hook; updated rendering logic and adjusted function signatures/defaults.
frontend/src/components/RepositoriesCard.tsx, frontend/src/components/CardDetailsPage.tsx, frontend/src/components/SecondaryCard.tsx Updated UI structure: moved the id attribute from a <section> to a wrapping <div>, added an optional id prop to SecondaryCard, and modified conditional rendering for repository display.
frontend/src/index.css Added new CSS keyframe animations (fadeIn, fadeOut, bounceSmall) and corresponding classes (.animate-fadeIn, .animate-fadeOut) for enhanced visual effects.
frontend/__tests__/e2e/pages/ProjectDetails.spec.ts, frontend/__tests__/unit/pages/ProjectDetails.test.tsx, frontend/__tests__/unit/pages/RepositoryDetails.test.tsx Modified tests by updating selectors and waiting logic for DOM attachment; streamlined assertions and made minor formatting adjustments in import statements.

Suggested labels

makefile

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.

🪧 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.
  • @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: 1

🧹 Nitpick comments (3)
frontend/src/hooks/useExpandableList.ts (1)

1-31: Great hook implementation for handling expandable lists!

The useExpandableList hook nicely centralizes the expandable list logic and animation handling. The generic type parameter makes this hook versatile and reusable across different components.

A few suggestions:

  1. Consider extracting the animation duration (500ms) into a constant to ensure it stays in sync with your CSS animations
  2. The timeout in toggleShowAll() should have a cleanup function like you did in useEffect()
+ const ANIMATION_DURATION = 500; // Match this with CSS animation duration

  useEffect(() => {
    // ...
-     }, 500)
+     }, ANIMATION_DURATION)
    // ...
  }, [showAll, animatingOut, items, maxInitialDisplay])

  const toggleShowAll = () => {
    if (showAll) {
      setAnimatingOut(true)
-     setTimeout(() => setShowAll(false), 50)
+     const timer = setTimeout(() => setShowAll(false), 50)
+     return () => clearTimeout(timer)
    } else {
      setShowAll(true)
    }
  }
frontend/src/components/ToggleableList.tsx (1)

21-36: Animation logic is complex but effective

The nested conditional rendering with multiple ternary operators works, but consider refactoring for readability:

- className={`rounded-lg border border-gray-400 px-2 py-1 text-sm transition-all duration-700 ease-in-out dark:border-gray-300 ${
-   index >= limit
-     ? showAll
-       ? 'animate-fadeIn'
-       : animatingOut
-         ? 'animate-fadeOut'
-         : 'hidden'
-     : ''
- }`}
+ className={`rounded-lg border border-gray-400 px-2 py-1 text-sm transition-all duration-500 ease-in-out dark:border-gray-300 ${
+   getAnimationClass(index, limit, showAll, animatingOut)
+ }`}

And add this helper function:

const getAnimationClass = (index, limit, showAll, animatingOut) => {
  if (index < limit) return '';
  if (showAll) return 'animate-fadeIn';
  if (animatingOut) return 'animate-fadeOut';
  return 'hidden';
}

Also, the transition duration (700ms) doesn't match the CSS animation duration (500ms) - they should be synchronized.

frontend/src/components/RepositoriesCard.tsx (1)

24-39: Animation logic needs alignment with CSS

Two issues to address:

  1. The transition duration (700ms) doesn't match the CSS animation duration (500ms)
  2. The complex nested ternary expressions reduce readability
- className={`transition-all duration-700 ease-in-out ${
-   index >= 4
-     ? showAll
-       ? 'animate-fadeIn'
-       : animatingOut
-         ? 'animate-fadeOut'
-         : 'hidden'
-     : ''
- }`}
+ className={`transition-all duration-500 ease-in-out ${
+   index >= 4 
+     ? (showAll ? 'animate-fadeIn' : animatingOut ? 'animate-fadeOut' : 'hidden') 
+     : ''
+ }`}

For even better readability, consider extracting this to a helper function like suggested for the ToggleableList component.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 79448f6 and a0bcb76.

📒 Files selected for processing (5)
  • frontend/src/components/RepositoriesCard.tsx (1 hunks)
  • frontend/src/components/ToggleContributors.tsx (3 hunks)
  • frontend/src/components/ToggleableList.tsx (3 hunks)
  • frontend/src/hooks/useExpandableList.ts (1 hunks)
  • frontend/src/index.css (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: CodeQL (python)
  • GitHub Check: CodeQL (javascript-typescript)
  • GitHub Check: Run frontend e2e tests
  • GitHub Check: Run frontend unit tests
  • GitHub Check: Run backend tests
🔇 Additional comments (11)
frontend/src/components/ToggleableList.tsx (2)

15-15: Good implementation of the useExpandableList hook!

The hook usage is clean and appropriate for this component.


39-53: Button state handling improvement

Good job updating the button to respect animation state. The disabled attribute during animation prevents user interaction while the animation is in progress, enhancing the user experience.

frontend/src/components/RepositoriesCard.tsx (2)

18-18: Appropriate use of useExpandableList hook

The hook is implemented properly with a limit of 4 repositories.


45-58: Button state handling is well implemented

The button properly uses the toggleShowAll function and disables during animation, which prevents users from triggering multiple animations simultaneously.

frontend/src/components/ToggleContributors.tsx (7)

4-4: Great addition of the custom hook!

Using the useExpandableList hook aligns with the PR objective of centralizing expandable list functionality. This abstraction will help maintain consistency across the application.


20-23: Clean implementation of the expandable list hook.

The hook provides all necessary functionality: visibility control, animation states, and toggle functionality. This is a significant improvement over managing these states separately in each component.


26-26: Explicit return value for empty state.

Returning null for empty contributors list is more explicit than the previous implementation. This is a small but good practice improvement.


33-33: Improved rendering logic with hook-provided values.

Using visibleItems from the hook simplifies the component logic by delegating the filtering responsibility to the hook.


36-36: Well-implemented conditional styling for animations.

The class name logic effectively handles different states (visible, animating in/out, hidden) based on the item index and hook state values. The transition duration of 700ms provides smooth animations as required.


73-75: Enhanced button behavior with animation states.

The button is now properly disabled during animations and has visual feedback (opacity change) to indicate when it's in a transitioning state. This prevents users from triggering multiple animations simultaneously.


77-77: Improved button text toggle logic.

Including the animatingOut condition in determining button text ensures the text doesn't change abruptly during the animation, providing a smoother user experience.

Comment on lines +292 to +330
@keyframes fadeIn {
from {
opacity: 0;
transform: translateY(10px);
}
to {
opacity: 1;
transform: translateY(0);
}
}

@keyframes fadeOut {
from {
opacity: 1;
transform: translateY(0);
}
to {
opacity: 0;
transform: translateY(10px);
}
}

@keyframes bounceSmall {
0%,
100% {
transform: translateY(0);
}
50% {
transform: translateY(-4px);
}
}

.animate-fadeIn {
animation: fadeIn 0.5s ease-out;
}

.animate-fadeOut {
animation: fadeOut 0.5s ease-in;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Duplicate animation definitions with inconsistent timing

There are duplicate fadeIn and fadeOut keyframes in the file. The original animations (lines 121-141) have a duration of 0.3s while these new ones use 0.5s.

Suggested improvements:

  1. Remove the duplicates and enhance the existing animations with the translateY property
  2. Standardize the animation durations across the application
  3. Consider using CSS variables for animation durations to maintain consistency
- @keyframes fadeIn {
-   from {
-     opacity: 0;
-     transform: translateY(10px);
-   }
-   to {
-     opacity: 1;
-     transform: translateY(0);
-   }
- }
- 
- @keyframes fadeOut {
-   from {
-     opacity: 1;
-     transform: translateY(0);
-   }
-   to {
-     opacity: 0;
-     transform: translateY(10px);
-   }
- }

/* Modify existing animations at lines 121-151 instead */
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@keyframes fadeIn {
from {
opacity: 0;
transform: translateY(10px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
@keyframes fadeOut {
from {
opacity: 1;
transform: translateY(0);
}
to {
opacity: 0;
transform: translateY(10px);
}
}
@keyframes bounceSmall {
0%,
100% {
transform: translateY(0);
}
50% {
transform: translateY(-4px);
}
}
.animate-fadeIn {
animation: fadeIn 0.5s ease-out;
}
.animate-fadeOut {
animation: fadeOut 0.5s ease-in;
}
/* Duplicate fadeIn and fadeOut keyframes removed.
Modify existing animations at lines 121-151 instead */
@keyframes bounceSmall {
0%,
100% {
transform: translateY(0);
}
50% {
transform: translateY(-4px);
}
}
.animate-fadeIn {
animation: fadeIn 0.5s ease-out;
}
.animate-fadeOut {
animation: fadeOut 0.5s ease-in;
}

@rishyym0927 rishyym0927 marked this pull request as draft March 10, 2025 15:38
Copy link
Collaborator

@kasya kasya left a comment

Choose a reason for hiding this comment

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

@rishyym0927 Thanks for working on this! Please update failing tests so that we can review and test this.

@rishyym0927
Copy link
Contributor Author

@rishyym0927 Thanks for working on this! Please update failing tests so that we can review and test this.

Yeah Im trying to fix and tune the tests !!!

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.

Caution

Inline review comments failed to post. This is likely due to GitHub's limits when posting large numbers of comments. If you are seeing this consistently it is likely a permissions issue. Please check "Moderation" -> "Code review limits" under your organization settings.

Actionable comments posted: 1

🧹 Nitpick comments (4)
frontend/src/components/SecondaryCard.tsx (1)

7-8: Consider using empty string as default for ID

The addition of the id prop is well-implemented and enhances the component's flexibility. However, the default value of a single space " " doesn't conform to HTML ID standards, which don't allow spaces in IDs.

-  id = ' ',
+  id = '',

Also applies to: 12-13, 14-17

frontend/src/components/RepositoriesCard.tsx (2)

25-34: Use a stable key to avoid re-render issues.

The current usage of index as the key can lead to potential UI or re-rendering issues if the order of repositories changes. Consider using a unique identifier in each repository object (e.g., repository.key or repository.id) as the key instead:

- {visibleItems.map((repository, index) => (
-   <div key={index} ...>
+ {visibleItems.map((repository) => (
+   <div key={repository.key} ...>

45-49: Provide additional disabled-state user feedback.

When animatingOut is true, the button is disabled. You might consider updating the button text or style to indicate that it’s in a disabled (animating) state, helping users understand why the button is temporarily inactive.

frontend/src/components/UserCard.tsx (1)

30-31: Clarify fallback logic for company, location, or email fields.

You’re currently defaulting to show only the first non-empty of company, location, or email. If you intend to show more than one field, consider stacking them or clarifying the user experience.

- <p className="mt-1 max-w-[250px] truncate text-sm text-gray-600 dark:text-gray-400 sm:text-base">
-   {company || location || email}
+ <p className="mt-1 text-sm text-gray-600 dark:text-gray-400 sm:text-base">
+   {[company, location, email].filter(Boolean).join(' · ')}
🛑 Comments failed to post (1)
frontend/src/components/MultiSearch.tsx (1)

49-53: 🛠️ Refactor suggestion

Maintain type safety for search hits.

Casting to multiple union types can obscure type-checking. To maximize clarity and catch potential errors, consider refining the type guard logic or using TypeScript’s discriminated unions for each index name.

@rishyym0927 rishyym0927 marked this pull request as ready for review March 11, 2025 10:23
@rishyym0927
Copy link
Contributor Author

@kasya Hey I have updated the testing files, cause the new animation is introduced thus there was a significant need to update the test files as the old ones will not work on it.

@Dishant1804
Copy link
Contributor

Dishant1804 commented Mar 11, 2025

Thanks for the PR @rishyym0927 i think we should animate the main container as well, because currently we are just animating the inner content and the outer container in which the data is being displayed is abruptly closing and opening without animation, we can animate that too

@rishyym0927
Copy link
Contributor Author

Hey @Dishant1804,

Thank you for your guidance! My approach was to generalize the animation for all "Show More" and "Show Less" buttons. Animating the entire box could be considered a separate issue, as it would make the animation more generalized, but we would still need to animate the inner content. In the future, we could explore using something like Framer for enhanced visuals. My primary goal, for now, was to animate only those specific sections.

Appreciate your insights! 😊

@Dishant1804
Copy link
Contributor

@rishyym0927 the main goal is to focus on performance and reusability of the code at the same time i think we can implement the container animation here itself without framer motion library as of now, the implementation of inner container is good you can replicate similar kind of animation for the outer container as well that will be a better approach, addressing it here itself will help to stay in context of this issue of generalized animation for containers :)

@rishyym0927
Copy link
Contributor Author

@Dishant1804 That sounds perfect to me! So basically, you’re suggesting that we implement the animation on the outer box itself and further generalize it for better reusability in the future.

Would you like me to start working on this feature now, or should I wait for feedback from the other reviewers as well?

@Dishant1804
Copy link
Contributor

Dishant1804 commented Mar 11, 2025

@Dishant1804 That sounds perfect to me! So basically, you’re suggesting that we implement the animation on the outer box itself and further generalize it for better reusability in the future.

Would you like me to start working on this feature now, or should I wait for feedback from the other reviewers as well?

Lets wait for the feedback from other reviewers as well, we need their inputs as well

@Rajgupta36
Copy link
Contributor

Thanks for the PR @rishyym0927 i think we should animate the main container as well, because currently we are just animating the inner content and the outer container in which the data is being displayed is abruptly closing and opening without animation, we can animate that too

@rishyym0927, I agree with @Dishant1804's decision. Please implement a smooth height expansion animation when clicking "Show More" or "Show Less" instead of an sudden change.


{repositories.length > 4 && (
<div className="mt-6 flex items-center justify-center text-center">
<button
Copy link
Contributor

Choose a reason for hiding this comment

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

@rishyym0927 please use action button here, we have it in components, or if it does not fit with your requirements please create a separate button component that is modular and reusable, and one more thing we are using Chakra UI so if possible try to use components from the chakra ui library whenever possible to maintain consistency across the code base.
Thank you :)

@sonarqubecloud
Copy link

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/index.css (1)

296-304: 🛠️ Refactor suggestion

Duplicate and Inconsistent Fade Animations

The new @keyframes fadeIn (lines 296–304) and @keyframes fadeOut (lines 305–314), along with the corresponding classes .animate-fadeIn and .animate-fadeOut (lines 324–329), introduce updated animation timings (0.5s ease-out/in) and include a vertical translation effect. However, these definitions duplicate existing ones (defined earlier around lines 121–141 and 169–171) that use a 0.3s duration without the translate effect. This duplication can lead to maintenance challenges and unintended UI inconsistencies. It is recommended to consolidate the animations—either update the original definitions or remove them if the new animations are intended to be the single source of truth.

Also applies to: 305-314, 324-329

🧹 Nitpick comments (1)
frontend/src/index.css (1)

315-323: Introduction of New BounceSmall Animation

The @keyframes bounceSmall animation (lines 315–323) adds a subtle bouncing effect by translating the element upward by 4px at the midpoint. This effect can enhance visual feedback for interactive elements such as expandable lists. Ensure its usage is consistent with the overall design language and consider leveraging CSS variables for ease of future adjustments if needed.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 44b80b5 and 740ca80.

📒 Files selected for processing (4)
  • frontend/__tests__/unit/pages/ProjectDetails.test.tsx (2 hunks)
  • frontend/__tests__/unit/pages/RepositoryDetails.test.tsx (2 hunks)
  • frontend/src/components/CardDetailsPage.tsx (1 hunks)
  • frontend/src/index.css (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • frontend/src/components/CardDetailsPage.tsx
  • frontend/tests/unit/pages/RepositoryDetails.test.tsx
  • frontend/tests/unit/pages/ProjectDetails.test.tsx
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: Run backend tests
  • GitHub Check: CodeQL (python)
  • GitHub Check: Run frontend e2e tests
  • GitHub Check: CodeQL (javascript-typescript)
  • GitHub Check: Run frontend unit tests

@arkid15r arkid15r marked this pull request as draft March 17, 2025 21:25
@arkid15r
Copy link
Collaborator

This has been stale for a while, I'm closing this. Feel free to reopen when you feel it's ready for review.

@arkid15r arkid15r closed this Mar 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Smooth Animation to "Show More" Button for Better UI Experience

5 participants