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

[WEB - 2779] feat: Added sort order for issue activity #6087

Open
wants to merge 3 commits into
base: preview
Choose a base branch
from

Conversation

mathalav55
Copy link
Collaborator

@mathalav55 mathalav55 commented Nov 22, 2024

Description

Sorting functionality for Issue activity.

Implementation

Added sort button for issue activity. Issues are sorted by either ascending or descending Created date.

Summary by CodeRabbit

  • New Features

    • Introduced a sorting component for activities, allowing users to toggle between ascending and descending order.
    • Enhanced the activity management interface with the new sorting functionality.
  • Bug Fixes

    • Improved sorting logic for activity comments based on user-defined order.
  • Documentation

    • Updated interface and component documentation to reflect the new sorting capabilities.

@mathalav55 mathalav55 added 🌟enhancement New feature or request 🌐frontend labels Nov 22, 2024
@mathalav55 mathalav55 added this to the v0.24.0 milestone Nov 22, 2024
@mathalav55 mathalav55 self-assigned this Nov 22, 2024
Copy link
Contributor

coderabbitai bot commented Nov 22, 2024

Walkthrough

A new React functional component named ActivitySortRoot has been added to facilitate sorting of activities in the user interface. This component accepts properties for sorting order and a toggle method. Additionally, the IssueActivityStore has been modified to include a sortOrder property and a method to toggle the sorting order. The IssueActivity component has been updated to integrate the new sorting functionality, allowing users to manage the order of activities displayed.

Changes

File Path Change Summary
web/ce/components/issues/worklog/activity/sort-root.tsx - Added ActivitySortRoot component.
- Introduced TActivitySortRoot type.
web/ce/store/issue/issue-details/activity.store.ts - Updated IssueActivityStore to include sortOrder and toggleSortOrder method.
- Replaced sortBy with orderBy for sorting activities.
web/core/components/issues/issue-detail/issue-activity/root.tsx - Integrated ActivitySortRoot into the IssueActivity component.
- Retrieved sortOrder and toggleSortOrder from useIssueDetail.

Possibly related PRs

Suggested labels

🧹chore

Suggested reviewers

  • sriramveeraghanta
  • SatishGandham

🐰 In the meadow, hopping with glee,
A sort and a toggle, oh what a spree!
With arrows that point, up or down,
Sorting activities, we wear a crown!
Click and you'll see, order's the key,
A joyful new feature, for you and for me! 🌼✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 51619a7 and 1a58cdf.

📒 Files selected for processing (3)
  • web/ce/components/issues/worklog/activity/sort-root.tsx (1 hunks)
  • web/ce/store/issue/issue-details/activity.store.ts (4 hunks)
  • web/core/components/issues/issue-detail/issue-activity/root.tsx (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • web/ce/components/issues/worklog/activity/sort-root.tsx
  • web/ce/store/issue/issue-details/activity.store.ts
  • web/core/components/issues/issue-detail/issue-activity/root.tsx

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.

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.

@pushya22 pushya22 changed the title [ WEB - 2779 ] feat: Added sort order for issue activity [WEB - 2779] feat: Added sort order for issue activity Nov 22, 2024
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

🧹 Outside diff range and nitpick comments (4)
web/ce/components/issues/worklog/activity/sort-root.tsx (1)

9-12: Consider enhancing type definitions for better maintainability.

While the types are functionally correct, consider these improvements:

  1. Extract the sort order type to a reusable enum
  2. Add JSDoc comments to document the purpose and usage
+/** Sort order options for activity list */
+export enum ActivitySortOrder {
+  ASC = 'asc',
+  DESC = 'desc'
+}

+/** Props for ActivitySortRoot component
+ * @property {ActivitySortOrder} sortOrder - Current sort direction
+ * @property {() => void} toggleSort - Callback to toggle sort direction
+ */
 export type TActivitySortRoot = {
-  sortOrder: 'asc' | 'desc'
+  sortOrder: ActivitySortOrder
   toggleSort: () => void
 }
web/ce/store/issue/issue-details/activity.store.ts (1)

112-114: Consider a more concise implementation.

While the implementation is correct, it could be more concise.

Consider this improvement:

-  toggleSortOrder = ()=>{
-    this.sortOrder = this.sortOrder === 'asc' ? 'desc' : 'asc';
-  }
+  toggleSortOrder = () => this.sortOrder = this.sortOrder === 'asc' ? 'desc' : 'asc';
web/core/components/issues/issue-detail/issue-activity/root.tsx (2)

47-47: Consider adding type annotations for sort-related properties.

While the hook usage is correct, adding TypeScript type annotations for sortOrder and toggleSortOrder would improve type safety and documentation.

- activity: { sortOrder, toggleSortOrder},
+ activity: { sortOrder: 'asc' | 'desc', toggleSortOrder: () => void },

167-167: Consider adding ARIA labels for accessibility.

While the sort control integration looks good, consider enhancing accessibility by adding appropriate ARIA labels to help screen reader users understand the sorting functionality.

- <ActivitySortRoot sortOrder={sortOrder} toggleSort={toggleSortOrder}/>
+ <ActivitySortRoot 
+   sortOrder={sortOrder} 
+   toggleSort={toggleSortOrder}
+   aria-label="Sort issue activities"
+   aria-controls="issue-activity-list"
+ />
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 86f8743 and 67353ae.

📒 Files selected for processing (3)
  • web/ce/components/issues/worklog/activity/sort-root.tsx (1 hunks)
  • web/ce/store/issue/issue-details/activity.store.ts (4 hunks)
  • web/core/components/issues/issue-detail/issue-activity/root.tsx (3 hunks)
🔇 Additional comments (8)
web/ce/components/issues/worklog/activity/sort-root.tsx (2)

1-8: LGTM! Imports are well-organized and appropriate.

The imports are properly structured with external dependencies first, followed by internal utilities.


1-19: Verify integration with issue activity sorting.

The component implements a generic sort UI, but we should verify its integration with the issue activity sorting by creation date.

✅ Verification successful

Sort implementation correctly integrates with issue activity creation date sorting

The verification confirms that:

  • The ActivitySortRoot component is properly integrated with the activity store
  • The activity store implements sorting by creation date using orderBy(activityComments, (e)=>new Date(e.created_at||''), this.sortOrder)
  • The sort order toggle functionality is correctly wired from the UI component through to the store
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of sorting by creation date in the parent components and stores

# Check for sort implementation in related files
echo "Checking sort implementation in activity store..."
rg -l "sortOrder" --type typescript web/ce/store/issue/issue-details/

# Check for creation date usage in sorting
echo "Checking creation date sorting..."
rg -l "createdAt|created_at.*sort" --type typescript web/ce/store/issue/issue-details/

Length of output: 414


Script:

#!/bin/bash
# Let's try a different approach to find the sorting implementation

# Search for activity-related files and sort implementation
echo "Searching for activity-related files with sort implementation..."
rg -l "sortOrder|sort.*activity" web/

# Look for creation date sorting in the codebase
echo "Searching for creation date sorting..."
rg -l "createdAt.*sort|created_at.*sort" web/

# Check for activity store implementations
echo "Looking for activity store files..."
fd "activity|activities" web/ce/store/

Length of output: 922


Script:

#!/bin/bash
# Let's examine the activity store implementation to verify the sorting logic

# Check the activity store implementation
echo "Examining activity store sorting implementation..."
rg -A 10 "sortOrder|sort.*activity" web/ce/store/issue/issue-details/activity.store.ts

# Check the activity root component to understand the integration
echo "Checking activity root component..."
rg -A 10 "sortOrder|sort.*activity" web/core/components/issues/issue-detail/issue-activity/root.tsx

Length of output: 2608

web/ce/store/issue/issue-details/activity.store.ts (4)

5-5: LGTM!

The orderBy import from lodash is appropriate for implementing the sorting functionality.


32-32: LGTM!

The interface changes are well-defined with appropriate types for the sorting functionality.

Also applies to: 40-40


45-45: LGTM!

The store property and MobX decorators are correctly implemented following MobX patterns.

Also applies to: 56-56, 62-62


Line range hint 1-150: Verify integration with UI components.

The store changes look good, but let's verify the integration with the UI components mentioned in the AI summary.

✅ Verification successful

Integration with UI components is properly implemented

The verification confirms that:

  • The ActivitySortRoot component is correctly implemented with the required props (sortOrder and toggleSort)
  • The component is properly integrated in the issue activity root component, passing the store's sortOrder and toggleSortOrder values
  • The sorting functionality is correctly wired up through the component hierarchy
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the integration of sorting functionality in UI components

# Check ActivitySortRoot component usage
echo "Checking ActivitySortRoot component usage:"
rg -A 5 "ActivitySortRoot" web/

# Check usage of toggleSortOrder in IssueActivity component
echo "Checking toggleSortOrder usage in IssueActivity:"
rg -A 5 "toggleSortOrder" "web/core/components/issues/issue-detail/issue-activity/root.tsx"

Length of output: 3088

web/core/components/issues/issue-detail/issue-activity/root.tsx (2)

22-22: LGTM! Import statement follows project conventions.

The import statement for ActivitySortRoot follows the established project structure and naming conventions.


167-167: Verify sort integration with IssueActivityCommentRoot.

The sort functionality appears to be properly integrated in the UI, but let's verify if the IssueActivityCommentRoot component is consuming the sort order correctly.

Also applies to: 183-196

Comment on lines 13 to 19
export const ActivitySortRoot:FC<TActivitySortRoot> = (props)=>{
return <div className={cn(getButtonStyling("neutral-primary", "sm"), "px-2 text-custom-text-300 cursor-pointer")} onClick={()=>{props.toggleSort()}}>
{
props.sortOrder === 'asc' ? <ArrowUpWideNarrow className="size-4 " /> : <ArrowDownWideNarrow className="size-4 " />
}
</div>
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance component implementation for accessibility and performance.

The component needs improvements in accessibility and could benefit from performance optimizations.

-export const ActivitySortRoot:FC<TActivitySortRoot> = (props)=>{
+import { memo } from 'react';
+
+export const ActivitySortRoot: FC<TActivitySortRoot> = memo((props) => {
+  const { sortOrder, toggleSort } = props;
+  const label = `Sort activities ${sortOrder === 'asc' ? 'descending' : 'ascending'}`;
+
   return (
     <div 
-      className={cn(getButtonStyling("neutral-primary", "sm"), "px-2 text-custom-text-300 cursor-pointer")} 
-      onClick={()=>{props.toggleSort()}}
+      className={cn(getButtonStyling("neutral-primary", "sm"), "px-2 text-custom-text-300 cursor-pointer")}
+      onClick={toggleSort}
+      role="button"
+      aria-label={label}
+      tabIndex={0}
+      onKeyDown={(e) => e.key === 'Enter' && toggleSort()}
     >
       {
-        props.sortOrder === 'asc' ? <ArrowUpWideNarrow className="size-4 " /> : <ArrowDownWideNarrow className="size-4 " />
+        sortOrder === 'asc' ? <ArrowUpWideNarrow className="size-4" /> : <ArrowDownWideNarrow className="size-4" />
       }
     </div>
-}
+});
+
+ActivitySortRoot.displayName = 'ActivitySortRoot';

Changes include:

  1. Added proper accessibility attributes (role, aria-label, keyboard support)
  2. Memoized component for better performance
  3. Destructured props for cleaner code
  4. Fixed trailing space in className
  5. Added display name for better debugging
📝 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
export const ActivitySortRoot:FC<TActivitySortRoot> = (props)=>{
return <div className={cn(getButtonStyling("neutral-primary", "sm"), "px-2 text-custom-text-300 cursor-pointer")} onClick={()=>{props.toggleSort()}}>
{
props.sortOrder === 'asc' ? <ArrowUpWideNarrow className="size-4 " /> : <ArrowDownWideNarrow className="size-4 " />
}
</div>
}
import { memo } from 'react';
export const ActivitySortRoot: FC<TActivitySortRoot> = memo((props) => {
const { sortOrder, toggleSort } = props;
const label = `Sort activities ${sortOrder === 'asc' ? 'descending' : 'ascending'}`;
return (
<div
className={cn(getButtonStyling("neutral-primary", "sm"), "px-2 text-custom-text-300 cursor-pointer")}
onClick={toggleSort}
role="button"
aria-label={label}
tabIndex={0}
onKeyDown={(e) => e.key === 'Enter' && toggleSort()}
>
{
sortOrder === 'asc' ? <ArrowUpWideNarrow className="size-4" /> : <ArrowDownWideNarrow className="size-4" />
}
</div>
);
});
ActivitySortRoot.displayName = 'ActivitySortRoot';

Comment on lines 106 to 107
activityComments = orderBy(activityComments, (e)=>new Date(e.created_at||''), this.sortOrder);
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

Improve date handling in sorting.

The current date handling could be problematic:

  1. Using an empty string as fallback for created_at will create an invalid date.
  2. The type suggests created_at is optional but it should be required for activities and comments.

Consider this improvement:

-    activityComments = orderBy(activityComments, (e)=>new Date(e.created_at||''), this.sortOrder);
+    activityComments = orderBy(activityComments, 'created_at', this.sortOrder);

Also, remove the empty line 106 for better code organization.

📝 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
activityComments = orderBy(activityComments, (e)=>new Date(e.created_at||''), this.sortOrder);
activityComments = orderBy(activityComments, 'created_at', this.sortOrder);

Copy link
Collaborator

@SatishGandham SatishGandham left a comment

Choose a reason for hiding this comment

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

Hi @mathalav55 , please check the coderabbit comments and run the lint and build locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🌟enhancement New feature or request 🌐frontend
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants