fix: order by last created (#550)

* feat: block sync

* fix: order by last created order
This commit is contained in:
Aaryan Khandelwal 2023-03-28 01:52:13 +05:30 committed by GitHub
parent b9e42d116e
commit 37aade5ef6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 33 additions and 22 deletions

View File

@ -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 = {

View File

@ -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<IIssue>,

View File

@ -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<ContextType>({} 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<IIssueFilterOptions>, 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: {

View File

@ -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) ||

View File

@ -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;
}

View File

@ -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;
};