2023-03-15 06:14:44 +00:00
|
|
|
export const GROUP_BY_OPTIONS: Array<{
|
|
|
|
name: string;
|
2023-03-23 19:41:42 +00:00
|
|
|
key: TIssueGroupByOptions;
|
2023-03-15 06:14:44 +00:00
|
|
|
}> = [
|
2023-07-26 12:21:26 +00:00
|
|
|
{ name: "States", key: "state" },
|
|
|
|
{ name: "State Groups", key: "state_detail.group" },
|
2023-02-08 04:43:07 +00:00
|
|
|
{ name: "Priority", key: "priority" },
|
2023-07-26 12:21:26 +00:00
|
|
|
{ name: "Project", key: "project" },
|
2023-03-15 06:14:44 +00:00
|
|
|
{ name: "Labels", key: "labels" },
|
2023-08-24 14:16:12 +00:00
|
|
|
{ name: "Assignees", key: "assignees" },
|
2023-03-23 19:41:42 +00:00
|
|
|
{ name: "Created by", key: "created_by" },
|
2023-02-08 04:43:07 +00:00
|
|
|
{ name: "None", key: null },
|
|
|
|
];
|
|
|
|
|
2023-03-15 06:14:44 +00:00
|
|
|
export const ORDER_BY_OPTIONS: Array<{
|
|
|
|
name: string;
|
2023-03-27 20:22:13 +00:00
|
|
|
key: TIssueOrderByOptions;
|
2023-03-15 06:14:44 +00:00
|
|
|
}> = [
|
2023-02-20 13:49:46 +00:00
|
|
|
{ name: "Manual", key: "sort_order" },
|
2023-03-27 20:22:13 +00:00
|
|
|
{ name: "Last created", key: "-created_at" },
|
2023-05-29 10:08:35 +00:00
|
|
|
{ name: "Last updated", key: "-updated_at" },
|
2023-02-20 13:49:46 +00:00
|
|
|
{ name: "Priority", key: "priority" },
|
|
|
|
];
|
2023-02-08 04:43:07 +00:00
|
|
|
|
|
|
|
export const FILTER_ISSUE_OPTIONS: Array<{
|
|
|
|
name: string;
|
2023-03-15 06:14:44 +00:00
|
|
|
key: "active" | "backlog" | null;
|
2023-02-08 04:43:07 +00:00
|
|
|
}> = [
|
|
|
|
{
|
|
|
|
name: "All",
|
|
|
|
key: null,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Active Issues",
|
2023-03-15 06:14:44 +00:00
|
|
|
key: "active",
|
2023-02-08 04:43:07 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Backlog Issues",
|
2023-03-15 06:14:44 +00:00
|
|
|
key: "backlog",
|
2023-02-08 04:43:07 +00:00
|
|
|
},
|
|
|
|
];
|
2023-03-15 06:14:44 +00:00
|
|
|
|
2023-04-13 13:39:55 +00:00
|
|
|
import { orderArrayBy } from "helpers/array.helper";
|
2023-03-27 20:22:13 +00:00
|
|
|
import { IIssue, TIssueGroupByOptions, TIssueOrderByOptions } from "types";
|
2023-03-15 06:14:44 +00:00
|
|
|
|
|
|
|
type THandleIssuesMutation = (
|
|
|
|
formData: Partial<IIssue>,
|
|
|
|
oldGroupTitle: string,
|
2023-03-23 19:41:42 +00:00
|
|
|
selectedGroupBy: TIssueGroupByOptions,
|
2023-03-15 06:14:44 +00:00
|
|
|
issueIndex: number,
|
2023-04-13 13:39:55 +00:00
|
|
|
orderBy: TIssueOrderByOptions,
|
2023-03-15 06:14:44 +00:00
|
|
|
prevData?:
|
|
|
|
| {
|
|
|
|
[key: string]: IIssue[];
|
|
|
|
}
|
|
|
|
| IIssue[]
|
|
|
|
) =>
|
|
|
|
| {
|
|
|
|
[key: string]: IIssue[];
|
|
|
|
}
|
|
|
|
| IIssue[]
|
|
|
|
| undefined;
|
|
|
|
|
|
|
|
export const handleIssuesMutation: THandleIssuesMutation = (
|
|
|
|
formData,
|
|
|
|
oldGroupTitle,
|
|
|
|
selectedGroupBy,
|
|
|
|
issueIndex,
|
2023-04-13 13:39:55 +00:00
|
|
|
orderBy,
|
2023-03-15 06:14:44 +00:00
|
|
|
prevData
|
|
|
|
) => {
|
|
|
|
if (!prevData) return prevData;
|
|
|
|
|
|
|
|
if (Array.isArray(prevData)) {
|
|
|
|
const updatedIssue = {
|
|
|
|
...prevData[issueIndex],
|
|
|
|
...formData,
|
2023-04-21 10:18:06 +00:00
|
|
|
assignees: formData?.assignees_list ?? prevData[issueIndex]?.assignees,
|
2023-07-11 09:48:47 +00:00
|
|
|
labels: formData?.labels_list ?? prevData[issueIndex]?.labels,
|
2023-03-15 06:14:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
prevData.splice(issueIndex, 1, updatedIssue);
|
|
|
|
|
|
|
|
return [...prevData];
|
|
|
|
} else {
|
|
|
|
const oldGroup = prevData[oldGroupTitle ?? ""] ?? [];
|
|
|
|
|
|
|
|
let newGroup: IIssue[] = [];
|
|
|
|
|
2023-04-03 09:37:39 +00:00
|
|
|
if (selectedGroupBy === "priority") newGroup = prevData[formData.priority ?? ""] ?? [];
|
|
|
|
else if (selectedGroupBy === "state") newGroup = prevData[formData.state ?? ""] ?? [];
|
2023-03-15 06:14:44 +00:00
|
|
|
|
|
|
|
const updatedIssue = {
|
|
|
|
...oldGroup[issueIndex],
|
|
|
|
...formData,
|
2023-04-21 10:18:06 +00:00
|
|
|
assignees: formData?.assignees_list ?? oldGroup[issueIndex]?.assignees,
|
2023-07-11 09:48:47 +00:00
|
|
|
labels: formData?.labels_list ?? oldGroup[issueIndex]?.labels,
|
2023-03-15 06:14:44 +00:00
|
|
|
};
|
|
|
|
|
2023-04-13 13:39:55 +00:00
|
|
|
if (selectedGroupBy !== Object.keys(formData)[0])
|
|
|
|
return {
|
|
|
|
...prevData,
|
|
|
|
[oldGroupTitle ?? ""]: orderArrayBy(
|
|
|
|
oldGroup.map((i) => (i.id === updatedIssue.id ? updatedIssue : i)),
|
|
|
|
orderBy
|
|
|
|
),
|
|
|
|
};
|
2023-03-15 06:14:44 +00:00
|
|
|
|
|
|
|
const groupThatIsUpdated = selectedGroupBy === "priority" ? formData.priority : formData.state;
|
|
|
|
|
|
|
|
return {
|
|
|
|
...prevData,
|
2023-04-13 13:39:55 +00:00
|
|
|
[oldGroupTitle ?? ""]: orderArrayBy(
|
|
|
|
oldGroup.filter((i) => i.id !== updatedIssue.id),
|
|
|
|
orderBy
|
|
|
|
),
|
|
|
|
[groupThatIsUpdated ?? ""]: orderArrayBy([...newGroup, updatedIssue], orderBy),
|
2023-03-15 06:14:44 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|