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

Merged
merged 3 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 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,28 @@
"use client";

import { FC, memo } 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> = memo((props) => (
<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>
));

ActivitySortRoot.displayName = "ActivitySortRoot";
13 changes: 11 additions & 2 deletions web/ce/store/issue/issue-details/activity.store.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable no-useless-catch */

import concat from "lodash/concat";
import orderBy from "lodash/orderBy";
import set from "lodash/set";
import sortBy from "lodash/sortBy";
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 @@ -99,11 +104,15 @@ export class IssueActivityStore implements IIssueActivityStore {
});
});

activityComments = sortBy(activityComments, "created_at");
activityComments = orderBy(activityComments, (e)=>new Date(e.created_at || 0), 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 @@ -14,6 +14,7 @@ import { IssueActivityCommentRoot } from "@/components/issues/issue-detail";
import { useIssueDetail, useProject, useUser, useUserPermissions } from "@/hooks/store";
// plane web components
import { ActivityFilterRoot, IssueActivityWorklogCreateButton } from "@/plane-web/components/issues/worklog";
import { ActivitySortRoot } from "@/plane-web/components/issues/worklog/activity/sort-root";
// plane web constants
import { TActivityFilters, defaultActivityFilters } from "@/plane-web/constants/issues";
import { EUserPermissions } from "@/plane-web/constants/user-permissions";
Expand Down Expand Up @@ -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
Loading