-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
base: preview
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
"use client" | ||
|
||
import { FC } from "react"; | ||
import { ArrowUpWideNarrow, ArrowDownWideNarrow } from "lucide-react"; | ||
import { getButtonStyling } from "@plane/ui"; | ||
// helpers | ||
import { cn } from '@/helpers/common.helper' | ||
|
||
export type TActivitySortRoot = { | ||
sortOrder: 'asc' | 'desc' | ||
toggleSort: () => void | ||
} | ||
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> | ||
} | ||
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -2,7 +2,7 @@ | |||||||
|
||||||||
import concat from "lodash/concat"; | ||||||||
import set from "lodash/set"; | ||||||||
import sortBy from "lodash/sortBy"; | ||||||||
import orderBy from "lodash/orderBy"; | ||||||||
import uniq from "lodash/uniq"; | ||||||||
import update from "lodash/update"; | ||||||||
import { action, makeObservable, observable, runInAction } from "mobx"; | ||||||||
|
@@ -29,17 +29,20 @@ | |||||||
|
||||||||
export interface IIssueActivityStore extends IIssueActivityStoreActions { | ||||||||
// observables | ||||||||
sortOrder: 'asc' | 'desc' | ||||||||
loader: TActivityLoader; | ||||||||
activities: TIssueActivityIdMap; | ||||||||
activityMap: TIssueActivityMap; | ||||||||
// helper methods | ||||||||
getActivitiesByIssueId: (issueId: string) => string[] | undefined; | ||||||||
getActivityById: (activityId: string) => TIssueActivity | undefined; | ||||||||
getActivityCommentByIssueId: (issueId: string) => TIssueActivityComment[] | undefined; | ||||||||
toggleSortOrder: ()=>void; | ||||||||
} | ||||||||
|
||||||||
export class IssueActivityStore implements IIssueActivityStore { | ||||||||
// observables | ||||||||
sortOrder: "asc" | "desc" = 'asc'; | ||||||||
loader: TActivityLoader = "fetch"; | ||||||||
activities: TIssueActivityIdMap = {}; | ||||||||
activityMap: TIssueActivityMap = {}; | ||||||||
|
@@ -50,11 +53,13 @@ | |||||||
constructor(protected store: CoreRootStore) { | ||||||||
makeObservable(this, { | ||||||||
// observables | ||||||||
sortOrder: observable.ref, | ||||||||
loader: observable.ref, | ||||||||
activities: observable, | ||||||||
activityMap: observable, | ||||||||
// actions | ||||||||
fetchActivities: action, | ||||||||
toggleSortOrder: action | ||||||||
}); | ||||||||
// services | ||||||||
this.issueActivityService = new IssueActivityService(); | ||||||||
|
@@ -98,12 +103,16 @@ | |||||||
created_at: comment.created_at, | ||||||||
}); | ||||||||
}); | ||||||||
|
||||||||
activityComments = sortBy(activityComments, "created_at"); | ||||||||
activityComments = orderBy(activityComments, (e)=>new Date(e.created_at||''), this.sortOrder); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Improve date handling in sorting. The current date handling could be problematic:
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
Suggested change
|
||||||||
|
||||||||
return activityComments; | ||||||||
}); | ||||||||
|
||||||||
toggleSortOrder = ()=>{ | ||||||||
this.sortOrder = this.sortOrder === 'asc' ? 'desc' : 'asc'; | ||||||||
} | ||||||||
|
||||||||
// actions | ||||||||
public async fetchActivities( | ||||||||
workspaceSlug: string, | ||||||||
|
There was a problem hiding this comment.
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.
Changes include:
📝 Committable suggestion