2023-03-15 06:14:44 +00:00
|
|
|
export const GROUP_BY_OPTIONS: Array<{
|
|
|
|
name: string;
|
|
|
|
key: "state" | "priority" | "labels" | null;
|
|
|
|
}> = [
|
|
|
|
{ name: "State", key: "state" },
|
2023-02-08 04:43:07 +00:00
|
|
|
{ name: "Priority", key: "priority" },
|
2023-03-15 06:14:44 +00:00
|
|
|
{ name: "Labels", key: "labels" },
|
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;
|
|
|
|
key: "created_at" | "updated_at" | "priority" | "sort_order";
|
|
|
|
}> = [
|
2023-02-20 13:49:46 +00:00
|
|
|
{ name: "Manual", key: "sort_order" },
|
|
|
|
{ name: "Last created", key: "created_at" },
|
|
|
|
{ name: "Last updated", key: "updated_at" },
|
|
|
|
{ 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
|
|
|
|
|
|
|
import { IIssue } from "types";
|
|
|
|
|
|
|
|
type THandleIssuesMutation = (
|
|
|
|
formData: Partial<IIssue>,
|
|
|
|
oldGroupTitle: string,
|
|
|
|
selectedGroupBy: "state" | "priority" | "labels" | null,
|
|
|
|
issueIndex: number,
|
|
|
|
prevData?:
|
|
|
|
| {
|
|
|
|
[key: string]: IIssue[];
|
|
|
|
}
|
|
|
|
| IIssue[]
|
|
|
|
) =>
|
|
|
|
| {
|
|
|
|
[key: string]: IIssue[];
|
|
|
|
}
|
|
|
|
| IIssue[]
|
|
|
|
| undefined;
|
|
|
|
|
|
|
|
export const handleIssuesMutation: THandleIssuesMutation = (
|
|
|
|
formData,
|
|
|
|
oldGroupTitle,
|
|
|
|
selectedGroupBy,
|
|
|
|
issueIndex,
|
|
|
|
prevData
|
|
|
|
) => {
|
|
|
|
if (!prevData) return prevData;
|
|
|
|
|
|
|
|
if (Array.isArray(prevData)) {
|
|
|
|
const updatedIssue = {
|
|
|
|
...prevData[issueIndex],
|
|
|
|
...formData,
|
|
|
|
assignees: formData?.assignees_list ?? prevData[issueIndex]?.assignees_list,
|
|
|
|
};
|
|
|
|
|
|
|
|
prevData.splice(issueIndex, 1, updatedIssue);
|
|
|
|
|
|
|
|
return [...prevData];
|
|
|
|
} else {
|
|
|
|
const oldGroup = prevData[oldGroupTitle ?? ""] ?? [];
|
|
|
|
|
|
|
|
let newGroup: IIssue[] = [];
|
|
|
|
|
|
|
|
if (selectedGroupBy === "priority") {
|
|
|
|
newGroup = prevData[formData.priority ?? ""] ?? [];
|
|
|
|
} else if (selectedGroupBy === "state") {
|
|
|
|
newGroup = prevData[formData.state ?? ""] ?? [];
|
|
|
|
}
|
|
|
|
|
|
|
|
const updatedIssue = {
|
|
|
|
...oldGroup[issueIndex],
|
|
|
|
...formData,
|
|
|
|
assignees: formData?.assignees_list ?? oldGroup[issueIndex]?.assignees_list,
|
|
|
|
};
|
|
|
|
|
|
|
|
oldGroup.splice(issueIndex, 1);
|
|
|
|
newGroup.push(updatedIssue);
|
|
|
|
|
|
|
|
const groupThatIsUpdated = selectedGroupBy === "priority" ? formData.priority : formData.state;
|
|
|
|
|
|
|
|
return {
|
|
|
|
...prevData,
|
|
|
|
[oldGroupTitle ?? ""]: oldGroup,
|
|
|
|
[groupThatIsUpdated ?? ""]: newGroup,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|