Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: bulk assign sub-issues #284

Merged
merged 1 commit into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions apps/app/components/core/existing-issues-list-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ type FormInput = {
type Props = {
isOpen: boolean;
handleClose: () => void;
type: string;
issues: IIssue[];
handleOnSubmit: any;
};
Expand All @@ -30,7 +29,6 @@ export const ExistingIssuesListModal: React.FC<Props> = ({
handleClose: onClose,
issues,
handleOnSubmit,
type,
}) => {
const [query, setQuery] = useState("");

Expand Down Expand Up @@ -132,7 +130,7 @@ export const ExistingIssuesListModal: React.FC<Props> = ({
<li className="p-2">
{query === "" && (
<h2 className="mt-4 mb-2 px-3 text-xs font-semibold text-gray-900">
Select issues to add to {type}
Select issues to add
</h2>
)}
<ul className="text-sm text-gray-700">
Expand Down Expand Up @@ -203,7 +201,7 @@ export const ExistingIssuesListModal: React.FC<Props> = ({
onClick={handleSubmit(onSubmit)}
disabled={isSubmitting}
>
{isSubmitting ? "Adding..." : `Add to ${type}`}
{isSubmitting ? "Adding..." : "Add selected issues"}
</Button>
</div>
)}
Expand Down
1 change: 0 additions & 1 deletion apps/app/components/issues/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ export * from "./my-issues-list-item";
export * from "./parent-issues-list-modal";
export * from "./sidebar";
export * from "./sub-issues-list";
export * from "./sub-issues-list-modal";
205 changes: 0 additions & 205 deletions apps/app/components/issues/sub-issues-list-modal.tsx

This file was deleted.

76 changes: 73 additions & 3 deletions apps/app/components/issues/sub-issues-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ import { Disclosure, Transition } from "@headlessui/react";
// services
import issuesService from "services/issues.service";
// components
import { CreateUpdateIssueModal, SubIssuesListModal } from "components/issues";
import { ExistingIssuesListModal } from "components/core";
import { CreateUpdateIssueModal } from "components/issues";
// ui
import { CustomMenu } from "components/ui";
// icons
import { ChevronRightIcon, PlusIcon } from "@heroicons/react/24/outline";
// helpers
import { orderArrayBy } from "helpers/array.helper";
// types
import { IIssue, IssueResponse, UserAuth } from "types";
// fetch-keys
Expand Down Expand Up @@ -42,6 +45,65 @@ export const SubIssuesList: FC<SubIssueListProps> = ({ parentIssue, userAuth })
: null
);

const { data: issues } = useSWR(
workspaceSlug && projectId
? PROJECT_ISSUES_LIST(workspaceSlug as string, projectId as string)
: null,
workspaceSlug && projectId
? () => issuesService.getIssues(workspaceSlug as string, projectId as string)
: null
);

const addAsSubIssue = async (data: { issues: string[] }) => {
if (!workspaceSlug || !projectId) return;

await issuesService
.addSubIssues(workspaceSlug as string, projectId as string, parentIssue?.id ?? "", {
sub_issue_ids: data.issues,
})
.then((res) => {
mutate<IIssue[]>(
SUB_ISSUES(parentIssue?.id ?? ""),
(prevData) => {
let newSubIssues = [...(prevData as IIssue[])];

data.issues.forEach((issueId: string) => {
const issue = issues?.results.find((i) => i.id === issueId);

if (issue) newSubIssues.push(issue);
});

newSubIssues = orderArrayBy(newSubIssues, "created_at", "descending");

return newSubIssues;
},
false
);

mutate<IssueResponse>(
PROJECT_ISSUES_LIST(workspaceSlug as string, projectId as string),
(prevData) => ({
...(prevData as IssueResponse),
results: (prevData?.results ?? []).map((p) => {
if (data.issues.includes(p.id))
return {
...p,
parent: parentIssue.id,
};

return p;
}),
}),
false
);

mutate(PROJECT_ISSUES_LIST(workspaceSlug as string, projectId as string));
})
.catch((err) => {
console.log(err);
});
};

const handleSubIssueRemove = (issueId: string) => {
if (!workspaceSlug || !projectId) return;

Expand Down Expand Up @@ -94,10 +156,18 @@ export const SubIssuesList: FC<SubIssueListProps> = ({ parentIssue, userAuth })
prePopulateData={{ ...preloadedData }}
handleClose={() => setCreateIssueModal(false)}
/>
<SubIssuesListModal
<ExistingIssuesListModal
isOpen={subIssuesListModal}
handleClose={() => setSubIssuesListModal(false)}
parent={parentIssue}
issues={
issues?.results.filter(
(i) =>
(i.parent === "" || i.parent === null) &&
i.id !== parentIssue?.id &&
i.id !== parentIssue?.parent
) ?? []
}
handleOnSubmit={addAsSubIssue}
/>
{subIssues && subIssues.length > 0 ? (
<Disclosure defaultOpen={true}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ const SingleCycle: React.FC<UserAuth> = (props) => {
<ExistingIssuesListModal
isOpen={cycleIssuesListModal}
handleClose={() => setCycleIssuesListModal(false)}
type="cycle"
issues={issues?.results.filter((i) => !i.issue_cycle) ?? []}
handleOnSubmit={handleAddIssuesToCycle}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ const SingleModule: React.FC<UserAuth> = (props) => {
<ExistingIssuesListModal
isOpen={moduleIssuesListModal}
handleClose={() => setModuleIssuesListModal(false)}
type="module"
issues={issues?.results.filter((i) => !i.issue_module) ?? []}
handleOnSubmit={handleAddIssuesToModule}
/>
Expand Down
16 changes: 16 additions & 0 deletions apps/app/services/issues.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,22 @@ class ProjectIssuesServices extends APIService {
throw error?.response?.data;
});
}

async addSubIssues(
workspaceSlug: string,
projectId: string,
issueId: string,
data: { sub_issue_ids: string[] }
): Promise<any> {
return this.post(
`/api/workspaces/${workspaceSlug}/projects/${projectId}/issues/${issueId}/sub-issues/`,
data
)
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
}

export default new ProjectIssuesServices();