mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
30cc923fdb
* fix: issue archive without automation * fix: unarchive issue endpoint change * chore: archiving logic implemented in the quick-actions dropdowns * chore: peek overview archive button * chore: issue archive completed at state * chore: updated archiving icon and added archive option everywhere * chore: all issues quick actions dropdown * chore: archive and unarchive response * fix: archival mutation * fix: restore issue from peek overview * chore: update notification content for archive/restore * refactor: activity user name * fix: all issues mutation * fix: restore issue auth * chore: close peek overview on archival --------- Co-authored-by: NarayanBavisetti <narayan3119@gmail.com> Co-authored-by: gurusainath <gurusainath007@gmail.com>
183 lines
5.8 KiB
TypeScript
183 lines
5.8 KiB
TypeScript
import { useState } from "react";
|
|
import { useRouter } from "next/router";
|
|
import { ArchiveIcon, CustomMenu } from "@plane/ui";
|
|
import { observer } from "mobx-react";
|
|
import { Copy, ExternalLink, Link, Pencil, Trash2 } from "lucide-react";
|
|
import omit from "lodash/omit";
|
|
// hooks
|
|
import useToast from "hooks/use-toast";
|
|
import { useEventTracker, useProjectState } from "hooks/store";
|
|
// components
|
|
import { ArchiveIssueModal, CreateUpdateIssueModal, DeleteIssueModal } from "components/issues";
|
|
// helpers
|
|
import { copyUrlToClipboard } from "helpers/string.helper";
|
|
// types
|
|
import { TIssue } from "@plane/types";
|
|
import { IQuickActionProps } from "../list/list-view-types";
|
|
// constants
|
|
import { EIssuesStoreType } from "constants/issue";
|
|
import { STATE_GROUPS } from "constants/state";
|
|
|
|
export const AllIssueQuickActions: React.FC<IQuickActionProps> = observer((props) => {
|
|
const {
|
|
issue,
|
|
handleDelete,
|
|
handleUpdate,
|
|
handleArchive,
|
|
customActionButton,
|
|
portalElement,
|
|
readOnly = false,
|
|
} = props;
|
|
// states
|
|
const [createUpdateIssueModal, setCreateUpdateIssueModal] = useState(false);
|
|
const [issueToEdit, setIssueToEdit] = useState<TIssue | undefined>(undefined);
|
|
const [deleteIssueModal, setDeleteIssueModal] = useState(false);
|
|
const [archiveIssueModal, setArchiveIssueModal] = useState(false);
|
|
// router
|
|
const router = useRouter();
|
|
const { workspaceSlug } = router.query;
|
|
// store hooks
|
|
const { setTrackElement } = useEventTracker();
|
|
const { getStateById } = useProjectState();
|
|
// toast alert
|
|
const { setToastAlert } = useToast();
|
|
// derived values
|
|
const stateDetails = getStateById(issue.state_id);
|
|
const isEditingAllowed = !readOnly;
|
|
// auth
|
|
const isArchivingAllowed = handleArchive && isEditingAllowed;
|
|
const isInArchivableGroup =
|
|
!!stateDetails && [STATE_GROUPS.completed.key, STATE_GROUPS.cancelled.key].includes(stateDetails?.group);
|
|
|
|
const issueLink = `${workspaceSlug}/projects/${issue.project_id}/issues/${issue.id}`;
|
|
|
|
const handleOpenInNewTab = () => window.open(`/${issueLink}`, "_blank");
|
|
const handleCopyIssueLink = () =>
|
|
copyUrlToClipboard(issueLink).then(() =>
|
|
setToastAlert({
|
|
type: "success",
|
|
title: "Link copied",
|
|
message: "Issue link copied to clipboard",
|
|
})
|
|
);
|
|
|
|
const duplicateIssuePayload = omit(
|
|
{
|
|
...issue,
|
|
name: `${issue.name} (copy)`,
|
|
},
|
|
["id"]
|
|
);
|
|
|
|
return (
|
|
<>
|
|
<ArchiveIssueModal
|
|
data={issue}
|
|
isOpen={archiveIssueModal}
|
|
handleClose={() => setArchiveIssueModal(false)}
|
|
onSubmit={handleArchive}
|
|
/>
|
|
<DeleteIssueModal
|
|
data={issue}
|
|
isOpen={deleteIssueModal}
|
|
handleClose={() => setDeleteIssueModal(false)}
|
|
onSubmit={handleDelete}
|
|
/>
|
|
<CreateUpdateIssueModal
|
|
isOpen={createUpdateIssueModal}
|
|
onClose={() => {
|
|
setCreateUpdateIssueModal(false);
|
|
setIssueToEdit(undefined);
|
|
}}
|
|
data={issueToEdit ?? duplicateIssuePayload}
|
|
onSubmit={async (data) => {
|
|
if (issueToEdit && handleUpdate) await handleUpdate({ ...issueToEdit, ...data });
|
|
}}
|
|
storeType={EIssuesStoreType.PROJECT}
|
|
/>
|
|
<CustomMenu
|
|
placement="bottom-start"
|
|
customButton={customActionButton}
|
|
portalElement={portalElement}
|
|
closeOnSelect
|
|
ellipsis
|
|
>
|
|
{isEditingAllowed && (
|
|
<CustomMenu.MenuItem
|
|
onClick={() => {
|
|
setTrackElement("Global issues");
|
|
setIssueToEdit(issue);
|
|
setCreateUpdateIssueModal(true);
|
|
}}
|
|
>
|
|
<div className="flex items-center gap-2">
|
|
<Pencil className="h-3 w-3" />
|
|
Edit
|
|
</div>
|
|
</CustomMenu.MenuItem>
|
|
)}
|
|
<CustomMenu.MenuItem onClick={handleOpenInNewTab}>
|
|
<div className="flex items-center gap-2">
|
|
<ExternalLink className="h-3 w-3" />
|
|
Open in new tab
|
|
</div>
|
|
</CustomMenu.MenuItem>
|
|
<CustomMenu.MenuItem onClick={handleCopyIssueLink}>
|
|
<div className="flex items-center gap-2">
|
|
<Link className="h-3 w-3" />
|
|
Copy link
|
|
</div>
|
|
</CustomMenu.MenuItem>
|
|
{isEditingAllowed && (
|
|
<CustomMenu.MenuItem
|
|
onClick={() => {
|
|
setTrackElement("Global issues");
|
|
setCreateUpdateIssueModal(true);
|
|
}}
|
|
>
|
|
<div className="flex items-center gap-2">
|
|
<Copy className="h-3 w-3" />
|
|
Make a copy
|
|
</div>
|
|
</CustomMenu.MenuItem>
|
|
)}
|
|
{isArchivingAllowed && (
|
|
<CustomMenu.MenuItem onClick={() => setArchiveIssueModal(true)} disabled={!isInArchivableGroup}>
|
|
{isInArchivableGroup ? (
|
|
<div className="flex items-center gap-2">
|
|
<ArchiveIcon className="h-3 w-3" />
|
|
Archive
|
|
</div>
|
|
) : (
|
|
<div className="flex items-start gap-2">
|
|
<ArchiveIcon className="h-3 w-3" />
|
|
<div className="-mt-1">
|
|
<p>Archive</p>
|
|
<p className="text-xs text-custom-text-400">
|
|
Only completed or canceled
|
|
<br />
|
|
issues can be archived
|
|
</p>
|
|
</div>
|
|
</div>
|
|
)}
|
|
</CustomMenu.MenuItem>
|
|
)}
|
|
{isEditingAllowed && (
|
|
<CustomMenu.MenuItem
|
|
onClick={() => {
|
|
setTrackElement("Global issues");
|
|
setDeleteIssueModal(true);
|
|
}}
|
|
>
|
|
<div className="flex items-center gap-2">
|
|
<Trash2 className="h-3 w-3" />
|
|
Delete
|
|
</div>
|
|
</CustomMenu.MenuItem>
|
|
)}
|
|
</CustomMenu>
|
|
</>
|
|
);
|
|
});
|