Skip to content

Commit

Permalink
added sort order for issue activity
Browse files Browse the repository at this point in the history
  • Loading branch information
vamsikrishnamathala committed Nov 22, 2024
1 parent b72d180 commit 67353ae
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
19 changes: 19 additions & 0 deletions web/ce/components/issues/worklog/activity/sort-root.tsx
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)=>{

Check failure on line 13 in web/ce/components/issues/worklog/activity/sort-root.tsx

View workflow job for this annotation

GitHub Actions / lint-web

Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`
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>
}
15 changes: 12 additions & 3 deletions web/ce/store/issue/issue-details/activity.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import concat from "lodash/concat";
import set from "lodash/set";
import sortBy from "lodash/sortBy";
import orderBy from "lodash/orderBy";

Check failure on line 5 in web/ce/store/issue/issue-details/activity.store.ts

View workflow job for this annotation

GitHub Actions / lint-web

`lodash/orderBy` import should occur before import of `lodash/set`
import uniq from "lodash/uniq";
import update from "lodash/update";
import { action, makeObservable, observable, runInAction } from "mobx";
Expand All @@ -29,17 +29,20 @@ export interface IIssueActivityStoreActions {

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 = {};
Expand All @@ -50,11 +53,13 @@ export class IssueActivityStore implements IIssueActivityStore {
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();
Expand Down Expand Up @@ -98,12 +103,16 @@ export class IssueActivityStore implements IIssueActivityStore {
created_at: comment.created_at,
});
});

activityComments = sortBy(activityComments, "created_at");

Check failure on line 106 in web/ce/store/issue/issue-details/activity.store.ts

View workflow job for this annotation

GitHub Actions / lint-web

Trailing spaces not allowed
activityComments = orderBy(activityComments, (e)=>new Date(e.created_at||''), this.sortOrder);

return activityComments;
});

toggleSortOrder = ()=>{
this.sortOrder = this.sortOrder === 'asc' ? 'desc' : 'asc';
}

// actions
public async fetchActivities(
workspaceSlug: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { TActivityFilters, defaultActivityFilters } from "@/plane-web/constants/
import { EUserPermissions } from "@/plane-web/constants/user-permissions";
// services
import { FileService } from "@/services/file.service";
import { ActivitySortRoot } from "@/plane-web/components/issues/worklog/activity/sort-root";

Check failure on line 22 in web/core/components/issues/issue-detail/issue-activity/root.tsx

View workflow job for this annotation

GitHub Actions / lint-web

`@/plane-web/components/issues/worklog/activity/sort-root` import should occur before import of `@/plane-web/constants/issues`
const fileService = new FileService();

type TIssueActivity = {
Expand All @@ -43,6 +44,7 @@ export const IssueActivity: FC<TIssueActivity> = observer((props) => {
// hooks
const {
issue: { getIssueById },
activity: { sortOrder, toggleSortOrder},
createComment,
updateComment,
removeComment,
Expand Down Expand Up @@ -162,6 +164,7 @@ export const IssueActivity: FC<TIssueActivity> = observer((props) => {
disabled={disabled}
/>
)}
<ActivitySortRoot sortOrder={sortOrder} toggleSort={toggleSortOrder}/>
<ActivityFilterRoot
selectedFilters={selectedFilters}
toggleFilter={toggleFilter}
Expand Down

0 comments on commit 67353ae

Please sign in to comment.