Skip to content

Commit

Permalink
chore: issue relation modal and issue peek overview mutation fix (mak…
Browse files Browse the repository at this point in the history
…eplane#3482)

* fix: resolve addtocycle and addtomodule mutation in peek overview and issue sidebar

* fix: issue relation modal fix for all issues peek overview

* fix: cycle and module mutation in issue detail and issue peek overview

* fix: updated the issue actions for cycle and module mutation in peek overview

* chore: module issue store updated

* chore: existing isssue modal improvement and build error fix

---------

Co-authored-by: gurusainath <[email protected]>
  • Loading branch information
anmolsinghbhatia and gurusainath committed Jan 27, 2024
1 parent 9ecdcc6 commit 212f2b5
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 81 deletions.
16 changes: 11 additions & 5 deletions web/components/core/modals/existing-issues-list-modal.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { useEffect, useState } from "react";
import { useRouter } from "next/router";
import { Combobox, Dialog, Transition } from "@headlessui/react";
import { Rocket, Search, X } from "lucide-react";
// services
Expand All @@ -13,6 +12,8 @@ import { Button, LayersIcon, Loader, ToggleSwitch, Tooltip } from "@plane/ui";
import { ISearchIssueResponse, TProjectIssuesSearchParams } from "@plane/types";

type Props = {
workspaceSlug: string | undefined;
projectId: string | undefined;
isOpen: boolean;
handleClose: () => void;
searchParams: Partial<TProjectIssuesSearchParams>;
Expand All @@ -23,7 +24,15 @@ type Props = {
const projectService = new ProjectService();

export const ExistingIssuesListModal: React.FC<Props> = (props) => {
const { isOpen, handleClose: onClose, searchParams, handleOnSubmit, workspaceLevelToggle = false } = props;
const {
workspaceSlug,
projectId,
isOpen,
handleClose: onClose,
searchParams,
handleOnSubmit,
workspaceLevelToggle = false,
} = props;
// states
const [searchTerm, setSearchTerm] = useState("");
const [issues, setIssues] = useState<ISearchIssueResponse[]>([]);
Expand All @@ -34,9 +43,6 @@ export const ExistingIssuesListModal: React.FC<Props> = (props) => {

const debouncedSearchTerm: string = useDebounce(searchTerm, 500);

const router = useRouter();
const { workspaceSlug, projectId } = router.query;

const { setToastAlert } = useToast();

const handleClose = () => {
Expand Down
2 changes: 2 additions & 0 deletions web/components/issues/issue-detail/relation-select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ export const IssueRelationSelect: React.FC<TIssueRelationSelect> = observer((pro
return (
<>
<ExistingIssuesListModal
workspaceSlug={workspaceSlug}
projectId={projectId}
isOpen={isRelationModalOpen === relationKey}
handleClose={() => toggleRelationModal(null)}
searchParams={{ issue_relation: true, issue_id: issueId }}
Expand Down
46 changes: 12 additions & 34 deletions web/components/issues/issue-detail/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,23 +120,12 @@ export const IssueDetailRoot: FC<TIssueDetailRoot> = (props) => {
},
addIssueToCycle: async (workspaceSlug: string, projectId: string, cycleId: string, issueIds: string[]) => {
try {
await addIssueToCycle(workspaceSlug, projectId, cycleId, issueIds)
.then((res) => {
updateIssue(workspaceSlug, projectId, res.id, res);
fetchIssue(workspaceSlug, projectId, res.id);
setToastAlert({
title: "Cycle added to issue successfully",
type: "success",
message: "Issue added to issue successfully",
});
})
.catch(() => {
setToastAlert({
type: "error",
title: "Error!",
message: "Selected issues could not be added to the cycle. Please try again.",
});
});
await addIssueToCycle(workspaceSlug, projectId, cycleId, issueIds);
setToastAlert({
title: "Cycle added to issue successfully",
type: "success",
message: "Issue added to issue successfully",
});
} catch (error) {
setToastAlert({
title: "Cycle add to issue failed",
Expand All @@ -163,23 +152,12 @@ export const IssueDetailRoot: FC<TIssueDetailRoot> = (props) => {
},
addIssueToModule: async (workspaceSlug: string, projectId: string, moduleId: string, issueIds: string[]) => {
try {
await addIssueToModule(workspaceSlug, projectId, moduleId, issueIds)
.then((res) => {
updateIssue(workspaceSlug, projectId, res.id, res);
fetchIssue(workspaceSlug, projectId, res.id);
setToastAlert({
title: "Module added to issue successfully",
type: "success",
message: "Module added to issue successfully",
});
})
.catch(() =>
setToastAlert({
type: "error",
title: "Error!",
message: "Selected issues could not be added to the module. Please try again.",
})
);
await addIssueToModule(workspaceSlug, projectId, moduleId, issueIds);
setToastAlert({
title: "Module added to issue successfully",
type: "success",
message: "Module added to issue successfully",
});
} catch (error) {
setToastAlert({
title: "Module add to issue failed",
Expand Down
2 changes: 2 additions & 0 deletions web/components/issues/issue-layouts/empty-states/cycle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ export const CycleEmptyState: React.FC<Props> = observer((props) => {
return (
<>
<ExistingIssuesListModal
workspaceSlug={workspaceSlug}
projectId={projectId}
isOpen={cycleIssuesListModal}
handleClose={() => setCycleIssuesListModal(false)}
searchParams={{ cycle: true }}
Expand Down
2 changes: 2 additions & 0 deletions web/components/issues/issue-layouts/empty-states/module.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ export const ModuleEmptyState: React.FC<Props> = observer((props) => {
return (
<>
<ExistingIssuesListModal
workspaceSlug={workspaceSlug}
projectId={projectId}
isOpen={moduleIssuesListModal}
handleClose={() => setModuleIssuesListModal(false)}
searchParams={{ module: true }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ export const HeaderGroupByCard: FC<IHeaderGroupByCard> = observer((props) => {
)}
{renderExistingIssueModal && (
<ExistingIssuesListModal
workspaceSlug={workspaceSlug?.toString()}
projectId={projectId?.toString()}
isOpen={openExistingIssueListModal}
handleClose={() => setOpenExistingIssueListModal(false)}
searchParams={ExistingIssuesListModalPayload}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ export const HeaderGroupByCard = observer(

{renderExistingIssueModal && (
<ExistingIssuesListModal
workspaceSlug={workspaceSlug?.toString()}
projectId={projectId?.toString()}
isOpen={openExistingIssueListModal}
handleClose={() => setOpenExistingIssueListModal(false)}
searchParams={ExistingIssuesListModalPayload}
Expand Down
46 changes: 12 additions & 34 deletions web/components/issues/peek-overview/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,23 +113,12 @@ export const IssuePeekOverview: FC<IIssuePeekOverview> = observer((props) => {
},
addIssueToCycle: async (workspaceSlug: string, projectId: string, cycleId: string, issueIds: string[]) => {
try {
await addIssueToCycle(workspaceSlug, projectId, cycleId, issueIds)
.then((res) => {
updateIssue(workspaceSlug, projectId, res.id, res);
fetchIssue(workspaceSlug, projectId, res.id);
setToastAlert({
title: "Cycle added to issue successfully",
type: "success",
message: "Issue added to issue successfully",
});
})
.catch(() => {
setToastAlert({
type: "error",
title: "Error!",
message: "Selected issues could not be added to the cycle. Please try again.",
});
});
await addIssueToCycle(workspaceSlug, projectId, cycleId, issueIds);
setToastAlert({
title: "Cycle added to issue successfully",
type: "success",
message: "Issue added to issue successfully",
});
} catch (error) {
setToastAlert({
title: "Cycle add to issue failed",
Expand All @@ -156,23 +145,12 @@ export const IssuePeekOverview: FC<IIssuePeekOverview> = observer((props) => {
},
addIssueToModule: async (workspaceSlug: string, projectId: string, moduleId: string, issueIds: string[]) => {
try {
await addIssueToModule(workspaceSlug, projectId, moduleId, issueIds)
.then((res) => {
updateIssue(workspaceSlug, projectId, res.id, res);
fetchIssue(workspaceSlug, projectId, res.id);
setToastAlert({
title: "Module added to issue successfully",
type: "success",
message: "Module added to issue successfully",
});
})
.catch(() =>
setToastAlert({
type: "error",
title: "Error!",
message: "Selected issues could not be added to the module. Please try again.",
})
);
await addIssueToModule(workspaceSlug, projectId, moduleId, issueIds);
setToastAlert({
title: "Module added to issue successfully",
type: "success",
message: "Module added to issue successfully",
});
} catch (error) {
setToastAlert({
title: "Module add to issue failed",
Expand Down
2 changes: 2 additions & 0 deletions web/components/issues/sub-issues/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,8 @@ export const SubIssuesRoot: FC<ISubIssuesRoot> = observer((props) => {

{issueCrudState?.existing?.toggle && issueCrudState?.existing?.parentIssueId && (
<ExistingIssuesListModal
workspaceSlug={workspaceSlug}
projectId={projectId}
isOpen={issueCrudState?.existing?.toggle}
handleClose={() => handleIssueCrudState("existing", null, null)}
searchParams={{ sub_issue: true, issue_id: issueCrudState?.existing?.parentIssueId }}
Expand Down
11 changes: 6 additions & 5 deletions web/store/issue/cycle/issue.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import set from "lodash/set";
import update from "lodash/update";
import concat from "lodash/concat";
import pull from "lodash/pull";
import uniq from "lodash/uniq";
// base class
import { IssueHelperStore } from "../helpers/issue-helper.store";
// services
Expand Down Expand Up @@ -165,7 +166,6 @@ export class CycleIssues extends IssueHelperStore implements ICycleIssues {

return response;
} catch (error) {
console.log(error);
this.loader = undefined;
throw error;
}
Expand Down Expand Up @@ -267,11 +267,13 @@ export class CycleIssues extends IssueHelperStore implements ICycleIssues {
});

runInAction(() => {
update(this.issues, cycleId, (cycleIssueIds) => {
if (!cycleIssueIds) return [...issueIds];
else return concat(cycleIssueIds, [...issueIds]);
update(this.issues, cycleId, (cycleIssueIds = []) => {
uniq(concat(cycleIssueIds, issueIds));
});
});
issueIds.forEach((issueId) => {
this.rootStore.issues.updateIssue(issueId, { cycle_id: cycleId });
});

return issueToCycle;
} catch (error) {
Expand Down Expand Up @@ -332,7 +334,6 @@ export class CycleIssues extends IssueHelperStore implements ICycleIssues {

return response;
} catch (error) {
console.log(error);
this.loader = undefined;
throw error;
}
Expand Down
9 changes: 6 additions & 3 deletions web/store/issue/module/issue.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import set from "lodash/set";
import update from "lodash/update";
import concat from "lodash/concat";
import pull from "lodash/pull";
import uniq from "lodash/uniq";
// base class
import { IssueHelperStore } from "../helpers/issue-helper.store";
// services
Expand Down Expand Up @@ -259,11 +260,13 @@ export class ModuleIssues extends IssueHelperStore implements IModuleIssues {
});

runInAction(() => {
update(this.issues, moduleId, (moduleIssueIds) => {
if (!moduleIssueIds) return [...issueIds];
else return concat(moduleIssueIds, [...issueIds]);
update(this.issues, moduleId, (moduleIssueIds = []) => {
uniq(concat(moduleIssueIds, issueIds));
});
});
issueIds.forEach((issueId) => {
this.rootStore.issues.updateIssue(issueId, { module_id: moduleId });
});

return issueToModule;
} catch (error) {
Expand Down

0 comments on commit 212f2b5

Please sign in to comment.