diff --git a/apps/app/components/core/list-view/all-lists.tsx b/apps/app/components/core/list-view/all-lists.tsx index deba8f7c0..9d8608fa2 100644 --- a/apps/app/components/core/list-view/all-lists.tsx +++ b/apps/app/components/core/list-view/all-lists.tsx @@ -3,7 +3,7 @@ import useIssuesView from "hooks/use-issues-view"; // components import { SingleList } from "components/core/list-view/single-list"; // types -import { IIssue, IProjectMember, IState, UserAuth } from "types"; +import { IIssue, IState, UserAuth } from "types"; // types type Props = { diff --git a/apps/app/constants/issue.ts b/apps/app/constants/issue.ts index e219213c1..83541541c 100644 --- a/apps/app/constants/issue.ts +++ b/apps/app/constants/issue.ts @@ -11,10 +11,10 @@ export const GROUP_BY_OPTIONS: Array<{ export const ORDER_BY_OPTIONS: Array<{ name: string; - key: "created_at" | "updated_at" | "priority" | "sort_order"; + key: TIssueOrderByOptions; }> = [ { name: "Manual", key: "sort_order" }, - { name: "Last created", key: "created_at" }, + { name: "Last created", key: "-created_at" }, { name: "Last updated", key: "updated_at" }, { name: "Priority", key: "priority" }, ]; @@ -37,7 +37,7 @@ export const FILTER_ISSUE_OPTIONS: Array<{ }, ]; -import { IIssue, TIssueGroupByOptions } from "types"; +import { IIssue, TIssueGroupByOptions, TIssueOrderByOptions } from "types"; type THandleIssuesMutation = ( formData: Partial, diff --git a/apps/app/contexts/issue-view.context.tsx b/apps/app/contexts/issue-view.context.tsx index 1c0ec92c1..88dff42cc 100644 --- a/apps/app/contexts/issue-view.context.tsx +++ b/apps/app/contexts/issue-view.context.tsx @@ -10,7 +10,12 @@ import ToastAlert from "components/toast-alert"; import projectService from "services/project.service"; import viewsService from "services/views.service"; // types -import { IIssueFilterOptions, IProjectMember, TIssueGroupByOptions } from "types"; +import { + IIssueFilterOptions, + IProjectMember, + TIssueGroupByOptions, + TIssueOrderByOptions, +} from "types"; // fetch-keys import { USER_PROJECT_VIEW, VIEW_DETAILS } from "constants/fetch-keys"; @@ -19,7 +24,7 @@ export const issueViewContext = createContext({} as ContextType); type IssueViewProps = { issueView: "list" | "kanban"; groupByProperty: TIssueGroupByOptions; - orderBy: "created_at" | "updated_at" | "priority" | "sort_order"; + orderBy: TIssueOrderByOptions; showEmptyGroups: boolean; filters: IIssueFilterOptions; }; @@ -38,7 +43,7 @@ type ReducerActionType = { type ContextType = IssueViewProps & { setGroupByProperty: (property: TIssueGroupByOptions) => void; - setOrderBy: (property: "created_at" | "updated_at" | "priority" | "sort_order") => void; + setOrderBy: (property: TIssueOrderByOptions) => void; setShowEmptyGroups: (property: boolean) => void; setFilters: (filters: Partial, saveToServer?: boolean) => void; resetFilterToDefault: () => void; @@ -50,7 +55,7 @@ type ContextType = IssueViewProps & { type StateType = { issueView: "list" | "kanban"; groupByProperty: TIssueGroupByOptions; - orderBy: "created_at" | "updated_at" | "priority" | "sort_order"; + orderBy: TIssueOrderByOptions; showEmptyGroups: boolean; filters: IIssueFilterOptions; }; @@ -59,7 +64,7 @@ type ReducerFunctionType = (state: StateType, action: ReducerActionType) => Stat export const initialState: StateType = { issueView: "list", groupByProperty: null, - orderBy: "created_at", + orderBy: "-created_at", showEmptyGroups: true, filters: { type: null, @@ -111,7 +116,7 @@ export const reducer: ReducerFunctionType = (state, action) => { case "SET_ORDER_BY_PROPERTY": { const newState = { ...state, - orderBy: payload?.orderBy || "created_at", + orderBy: payload?.orderBy || "-created_at", }; return { @@ -315,7 +320,7 @@ export const IssueViewContextProvider: React.FC<{ children: React.ReactNode }> = ); const setOrderBy = useCallback( - (property: "created_at" | "updated_at" | "priority" | "sort_order") => { + (property: TIssueOrderByOptions) => { dispatch({ type: "SET_ORDER_BY_PROPERTY", payload: { diff --git a/apps/app/hooks/use-issues-view.tsx b/apps/app/hooks/use-issues-view.tsx index d6ada03bf..dadc5d6b4 100644 --- a/apps/app/hooks/use-issues-view.tsx +++ b/apps/app/hooks/use-issues-view.tsx @@ -10,21 +10,19 @@ import { issueViewContext } from "contexts/issue-view.context"; import issuesService from "services/issues.service"; import cyclesService from "services/cycles.service"; import modulesService from "services/modules.service"; +import stateService from "services/state.service"; +// helpers +import { getStatesList } from "helpers/state.helper"; +// types +import type { IIssue } from "types"; // fetch-keys import { CYCLE_ISSUES_WITH_PARAMS, MODULE_ISSUES_WITH_PARAMS, PROJECT_ISSUES_LIST_WITH_PARAMS, STATE_LIST, - VIEW_ISSUES, } from "constants/fetch-keys"; -// types -import type { IIssue } from "types"; -import viewsService from "services/views.service"; -import stateService from "services/state.service"; -import { getStatesList } from "helpers/state.helper"; - const useIssuesView = () => { const { issueView, @@ -128,7 +126,7 @@ const useIssuesView = () => { return issuesToGroup ? Object.assign(emptyStatesObject, issuesToGroup) : undefined; return issuesToGroup; - }, [projectIssues, cycleIssues, moduleIssues]); + }, [projectIssues, cycleIssues, moduleIssues, groupByProperty]); const isEmpty = Object.values(groupedByIssues ?? {}).every((group) => group.length === 0) || diff --git a/apps/app/types/issues.d.ts b/apps/app/types/issues.d.ts index 711082727..f3d2783bd 100644 --- a/apps/app/types/issues.d.ts +++ b/apps/app/types/issues.d.ts @@ -230,8 +230,10 @@ export interface IIssueFilterOptions { export type TIssueGroupByOptions = "state" | "priority" | "labels" | "created_by" | null; +export type TIssueOrderByOptions = "-created_at" | "updated_at" | "priority" | "sort_order"; + export interface IIssueViewOptions { group_by: TIssueGroupByOptions; - order_by: "created_at" | "updated_at" | "priority" | "sort_order"; + order_by: TIssueOrderByOptions; filters: IIssueFilterOptions; } diff --git a/apps/app/types/projects.d.ts b/apps/app/types/projects.d.ts index 9cdd46432..69f179dd5 100644 --- a/apps/app/types/projects.d.ts +++ b/apps/app/types/projects.d.ts @@ -1,4 +1,10 @@ -import type { IIssueFilterOptions, IUserLite, IWorkspace, TIssueGroupByOptions } from "./"; +import type { + IIssueFilterOptions, + IUserLite, + IWorkspace, + TIssueGroupByOptions, + TIssueOrderByOptions, +} from "./"; export interface IProject { cover_image: string | null; @@ -37,7 +43,7 @@ export interface IFavoriteProject { type ProjectViewTheme = { issueView: "list" | "kanban"; groupByProperty: TIssueGroupByOptions; - orderBy: "created_at" | "updated_at" | "priority" | "sort_order"; + orderBy: TIssueOrderByOptions; filters: IIssueFilterOptions; };