mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
969a51f425
* improve issue popover to detect outside click * chore: stopPropagation event added to prevent peekoverview triggering in action menu & issue properties * chore: stopPropagation event added to prevent peekoverview triggering in issue properties * chore: enable entire issue card clickability in list and kanban layout, introduce control-click functionality to open issues in new tabs * chore: build error fix and unused variable removed * chore: build error fix --------- Co-authored-by: sriram veeraghanta <veeraghanta.sriram@gmail.com>
134 lines
4.2 KiB
TypeScript
134 lines
4.2 KiB
TypeScript
import { useState } from "react";
|
|
import { useRouter } from "next/router";
|
|
import { CustomMenu } from "@plane/ui";
|
|
import { Copy, Link, Pencil, Trash2 } from "lucide-react";
|
|
// mobx store
|
|
import { useMobxStore } from "lib/mobx/store-provider";
|
|
// hooks
|
|
import useToast from "hooks/use-toast";
|
|
// components
|
|
import { CreateUpdateIssueModal, DeleteIssueModal } from "components/issues";
|
|
// helpers
|
|
import { copyUrlToClipboard } from "helpers/string.helper";
|
|
// types
|
|
import { IIssue } from "types";
|
|
import { IQuickActionProps } from "../list/list-view-types";
|
|
import { EProjectStore } from "store/command-palette.store";
|
|
// constant
|
|
import { EUserWorkspaceRoles } from "constants/workspace";
|
|
|
|
export const ProjectIssueQuickActions: React.FC<IQuickActionProps> = (props) => {
|
|
const { issue, handleDelete, handleUpdate, customActionButton } = props;
|
|
|
|
const router = useRouter();
|
|
const { workspaceSlug } = router.query;
|
|
|
|
// states
|
|
const [createUpdateIssueModal, setCreateUpdateIssueModal] = useState(false);
|
|
const [issueToEdit, setIssueToEdit] = useState<IIssue | null>(null);
|
|
const [deleteIssueModal, setDeleteIssueModal] = useState(false);
|
|
|
|
const { user: userStore } = useMobxStore();
|
|
|
|
const { currentProjectRole } = userStore;
|
|
|
|
const isEditingAllowed = !!currentProjectRole && currentProjectRole >= EUserWorkspaceRoles.MEMBER;
|
|
|
|
const { setToastAlert } = useToast();
|
|
|
|
const handleCopyIssueLink = () => {
|
|
copyUrlToClipboard(`/${workspaceSlug}/projects/${issue.project}/issues/${issue.id}`).then(() =>
|
|
setToastAlert({
|
|
type: "success",
|
|
title: "Link copied",
|
|
message: "Issue link copied to clipboard",
|
|
})
|
|
);
|
|
};
|
|
|
|
return (
|
|
<>
|
|
<DeleteIssueModal
|
|
data={issue}
|
|
isOpen={deleteIssueModal}
|
|
handleClose={() => setDeleteIssueModal(false)}
|
|
onSubmit={handleDelete}
|
|
/>
|
|
<CreateUpdateIssueModal
|
|
isOpen={createUpdateIssueModal}
|
|
handleClose={() => {
|
|
setCreateUpdateIssueModal(false);
|
|
setIssueToEdit(null);
|
|
}}
|
|
// pre-populate date only if not editing
|
|
prePopulateData={!issueToEdit && createUpdateIssueModal ? { ...issue, name: `${issue.name} (copy)` } : {}}
|
|
data={issueToEdit}
|
|
onSubmit={async (data) => {
|
|
if (issueToEdit && handleUpdate) handleUpdate({ ...issueToEdit, ...data });
|
|
}}
|
|
currentStore={EProjectStore.PROJECT}
|
|
/>
|
|
<CustomMenu
|
|
placement="bottom-start"
|
|
customButton={customActionButton}
|
|
ellipsis
|
|
menuButtonOnClick={(e) => e.stopPropagation()}
|
|
>
|
|
<CustomMenu.MenuItem
|
|
onClick={(e) => {
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
handleCopyIssueLink();
|
|
}}
|
|
>
|
|
<div className="flex items-center gap-2">
|
|
<Link className="h-3 w-3" />
|
|
Copy link
|
|
</div>
|
|
</CustomMenu.MenuItem>
|
|
{isEditingAllowed && (
|
|
<>
|
|
<CustomMenu.MenuItem
|
|
onClick={(e) => {
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
setIssueToEdit(issue);
|
|
setCreateUpdateIssueModal(true);
|
|
}}
|
|
>
|
|
<div className="flex items-center gap-2">
|
|
<Pencil className="h-3 w-3" />
|
|
Edit issue
|
|
</div>
|
|
</CustomMenu.MenuItem>
|
|
<CustomMenu.MenuItem
|
|
onClick={(e) => {
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
setCreateUpdateIssueModal(true);
|
|
}}
|
|
>
|
|
<div className="flex items-center gap-2">
|
|
<Copy className="h-3 w-3" />
|
|
Make a copy
|
|
</div>
|
|
</CustomMenu.MenuItem>
|
|
<CustomMenu.MenuItem
|
|
onClick={(e) => {
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
setDeleteIssueModal(true);
|
|
}}
|
|
>
|
|
<div className="flex items-center gap-2">
|
|
<Trash2 className="h-3 w-3" />
|
|
Delete issue
|
|
</div>
|
|
</CustomMenu.MenuItem>
|
|
</>
|
|
)}
|
|
</CustomMenu>
|
|
</>
|
|
);
|
|
};
|