fix: mutation of project detail, removed two identifier validation and added default value for deep checking
This commit is contained in:
parent
1368fb9164
commit
a1598e7310
19 changed files with 170 additions and 78 deletions
|
|
@ -1,4 +1,3 @@
|
|||
import { useState } from "react";
|
||||
// hooks
|
||||
import useTheme from "./useTheme";
|
||||
import useUser from "./useUser";
|
||||
|
|
@ -7,14 +6,19 @@ import { groupBy, orderArrayBy } from "constants/common";
|
|||
// constants
|
||||
import { PRIORITIES } from "constants/";
|
||||
// types
|
||||
import type { IssueResponse, IIssue, NestedKeyOf } from "types";
|
||||
import type { IssueResponse, IIssue } from "types";
|
||||
|
||||
const useIssuesFilter = (projectIssues?: IssueResponse) => {
|
||||
const { issueView, setIssueView, groupByProperty, setGroupByProperty } = useTheme();
|
||||
|
||||
const [orderBy, setOrderBy] = useState<NestedKeyOf<IIssue> | null>(null);
|
||||
|
||||
const [filterIssue, setFilterIssue] = useState<"activeIssue" | "backlogIssue" | null>(null);
|
||||
const {
|
||||
issueView,
|
||||
setIssueView,
|
||||
groupByProperty,
|
||||
setGroupByProperty,
|
||||
orderBy,
|
||||
setOrderBy,
|
||||
filterIssue,
|
||||
setFilterIssue,
|
||||
} = useTheme();
|
||||
|
||||
const { states } = useUser();
|
||||
|
||||
|
|
@ -52,29 +56,29 @@ const useIssuesFilter = (projectIssues?: IssueResponse) => {
|
|||
|
||||
if (filterIssue !== null) {
|
||||
if (filterIssue === "activeIssue") {
|
||||
groupedByIssues = Object.keys(groupedByIssues).reduce((acc, key) => {
|
||||
const value = groupedByIssues[key];
|
||||
const filteredValue = value.filter(
|
||||
(issue) =>
|
||||
issue.state_detail.group === "started" || issue.state_detail.group === "unstarted"
|
||||
);
|
||||
if (filteredValue.length > 0) {
|
||||
acc[key] = filteredValue;
|
||||
}
|
||||
return acc;
|
||||
}, {} as typeof groupedByIssues);
|
||||
const filteredStates = states?.filter(
|
||||
(state) => state.group === "started" || state.group === "unstarted"
|
||||
);
|
||||
groupedByIssues = Object.fromEntries(
|
||||
filteredStates
|
||||
?.sort((a, b) => a.sequence - b.sequence)
|
||||
?.map((state) => [
|
||||
state.name,
|
||||
projectIssues?.results.filter((issue) => issue.state === state.id) ?? [],
|
||||
]) ?? []
|
||||
);
|
||||
} else if (filterIssue === "backlogIssue") {
|
||||
groupedByIssues = Object.keys(groupedByIssues).reduce((acc, key) => {
|
||||
const value = groupedByIssues[key];
|
||||
const filteredValue = value.filter(
|
||||
(issue) =>
|
||||
issue.state_detail.group === "backlog" || issue.state_detail.group === "cancelled"
|
||||
);
|
||||
if (filteredValue.length > 0) {
|
||||
acc[key] = filteredValue;
|
||||
}
|
||||
return acc;
|
||||
}, {} as typeof groupedByIssues);
|
||||
const filteredStates = states?.filter(
|
||||
(state) => state.group === "backlog" || state.group === "cancelled"
|
||||
);
|
||||
groupedByIssues = Object.fromEntries(
|
||||
filteredStates
|
||||
?.sort((a, b) => a.sequence - b.sequence)
|
||||
?.map((state) => [
|
||||
state.name,
|
||||
projectIssues?.results.filter((issue) => issue.state === state.id) ?? [],
|
||||
]) ?? []
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue