2024-02-18 09:58:37 +00:00
|
|
|
import { FC } from "react";
|
|
|
|
import { observer } from "mobx-react";
|
2024-03-19 14:38:35 +00:00
|
|
|
import Link from "next/link";
|
2024-03-20 15:32:58 +00:00
|
|
|
import { MoveRight, MoveDiagonal, Link2, Trash2, ArchiveRestoreIcon } from "lucide-react";
|
2024-02-18 09:58:37 +00:00
|
|
|
// ui
|
2024-03-06 08:48:41 +00:00
|
|
|
import {
|
|
|
|
ArchiveIcon,
|
|
|
|
CenterPanelIcon,
|
|
|
|
CustomSelect,
|
|
|
|
FullScreenPanelIcon,
|
|
|
|
SidePanelIcon,
|
|
|
|
Tooltip,
|
|
|
|
TOAST_TYPE,
|
|
|
|
setToast,
|
|
|
|
} from "@plane/ui";
|
2024-03-06 13:09:14 +00:00
|
|
|
// components
|
2024-03-19 14:38:35 +00:00
|
|
|
import { IssueSubscription, IssueUpdateStatus } from "@/components/issues";
|
|
|
|
import { STATE_GROUPS } from "@/constants/state";
|
2024-02-18 09:58:37 +00:00
|
|
|
// helpers
|
2024-03-19 14:38:35 +00:00
|
|
|
import { cn } from "@/helpers/common.helper";
|
|
|
|
import { copyUrlToClipboard } from "@/helpers/string.helper";
|
2024-02-18 09:58:37 +00:00
|
|
|
// store hooks
|
2024-03-19 14:38:35 +00:00
|
|
|
import { useIssueDetail, useProjectState, useUser } from "@/hooks/store";
|
2024-03-12 15:09:36 +00:00
|
|
|
// hooks
|
2024-03-19 14:38:35 +00:00
|
|
|
import { usePlatformOS } from "@/hooks/use-platform-os";
|
2024-02-18 09:58:37 +00:00
|
|
|
|
|
|
|
export type TPeekModes = "side-peek" | "modal" | "full-screen";
|
|
|
|
|
|
|
|
const PEEK_OPTIONS: { key: TPeekModes; icon: any; title: string }[] = [
|
|
|
|
{
|
|
|
|
key: "side-peek",
|
|
|
|
icon: SidePanelIcon,
|
|
|
|
title: "Side Peek",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: "modal",
|
|
|
|
icon: CenterPanelIcon,
|
|
|
|
title: "Modal",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: "full-screen",
|
|
|
|
icon: FullScreenPanelIcon,
|
|
|
|
title: "Full Screen",
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
export type PeekOverviewHeaderProps = {
|
|
|
|
peekMode: TPeekModes;
|
|
|
|
setPeekMode: (value: TPeekModes) => void;
|
|
|
|
removeRoutePeekId: () => void;
|
|
|
|
workspaceSlug: string;
|
|
|
|
projectId: string;
|
|
|
|
issueId: string;
|
|
|
|
isArchived: boolean;
|
|
|
|
disabled: boolean;
|
2024-03-22 13:07:11 +00:00
|
|
|
toggleDeleteIssueModal: (issueId: string | null) => void;
|
2024-02-28 11:23:26 +00:00
|
|
|
toggleArchiveIssueModal: (value: boolean) => void;
|
|
|
|
handleRestoreIssue: () => void;
|
2024-02-18 09:58:37 +00:00
|
|
|
isSubmitting: "submitting" | "submitted" | "saved";
|
|
|
|
};
|
|
|
|
|
|
|
|
export const IssuePeekOverviewHeader: FC<PeekOverviewHeaderProps> = observer((props) => {
|
|
|
|
const {
|
|
|
|
peekMode,
|
|
|
|
setPeekMode,
|
|
|
|
workspaceSlug,
|
|
|
|
projectId,
|
|
|
|
issueId,
|
|
|
|
isArchived,
|
|
|
|
disabled,
|
|
|
|
removeRoutePeekId,
|
|
|
|
toggleDeleteIssueModal,
|
2024-02-28 11:23:26 +00:00
|
|
|
toggleArchiveIssueModal,
|
|
|
|
handleRestoreIssue,
|
2024-02-18 09:58:37 +00:00
|
|
|
isSubmitting,
|
|
|
|
} = props;
|
|
|
|
// store hooks
|
|
|
|
const { currentUser } = useUser();
|
2024-02-28 11:23:26 +00:00
|
|
|
const {
|
|
|
|
issue: { getIssueById },
|
|
|
|
} = useIssueDetail();
|
|
|
|
const { getStateById } = useProjectState();
|
2024-03-12 15:09:36 +00:00
|
|
|
const { isMobile } = usePlatformOS();
|
2024-02-18 09:58:37 +00:00
|
|
|
// derived values
|
2024-02-28 11:23:26 +00:00
|
|
|
const issueDetails = getIssueById(issueId);
|
|
|
|
const stateDetails = issueDetails ? getStateById(issueDetails?.state_id) : undefined;
|
2024-02-18 09:58:37 +00:00
|
|
|
const currentMode = PEEK_OPTIONS.find((m) => m.key === peekMode);
|
|
|
|
|
2024-03-20 15:32:58 +00:00
|
|
|
const issueLink = `${workspaceSlug}/projects/${projectId}/${isArchived ? "archives/" : ""}issues/${issueId}`;
|
2024-02-28 11:23:26 +00:00
|
|
|
|
2024-02-18 09:58:37 +00:00
|
|
|
const handleCopyText = (e: React.MouseEvent<HTMLButtonElement>) => {
|
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
2024-02-28 11:23:26 +00:00
|
|
|
copyUrlToClipboard(issueLink).then(() => {
|
2024-03-06 08:48:41 +00:00
|
|
|
setToast({
|
|
|
|
type: TOAST_TYPE.SUCCESS,
|
2024-02-18 09:58:37 +00:00
|
|
|
title: "Link Copied!",
|
|
|
|
message: "Issue link copied to clipboard.",
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
2024-02-28 11:23:26 +00:00
|
|
|
// auth
|
|
|
|
const isArchivingAllowed = !isArchived && !disabled;
|
|
|
|
const isInArchivableGroup =
|
|
|
|
!!stateDetails && [STATE_GROUPS.completed.key, STATE_GROUPS.cancelled.key].includes(stateDetails?.group);
|
|
|
|
const isRestoringAllowed = isArchived && !disabled;
|
2024-02-18 09:58:37 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className={`relative flex items-center justify-between p-4 ${
|
|
|
|
currentMode?.key === "full-screen" ? "border-b border-custom-border-200" : ""
|
|
|
|
}`}
|
|
|
|
>
|
|
|
|
<div className="flex items-center gap-4">
|
2024-04-23 07:19:29 +00:00
|
|
|
<Tooltip tooltipContent="Close the peek view" isMobile={isMobile}>
|
|
|
|
<button onClick={removeRoutePeekId}>
|
|
|
|
<MoveRight className="h-4 w-4 text-custom-text-300 hover:text-custom-text-200" />
|
|
|
|
</button>
|
|
|
|
</Tooltip>
|
2024-02-18 09:58:37 +00:00
|
|
|
|
2024-04-23 07:19:29 +00:00
|
|
|
<Tooltip tooltipContent="Open issue in full screen" isMobile={isMobile}>
|
|
|
|
<Link href={`/${issueLink}`} onClick={() => removeRoutePeekId()}>
|
|
|
|
<MoveDiagonal className="h-4 w-4 text-custom-text-300 hover:text-custom-text-200" />
|
|
|
|
</Link>
|
|
|
|
</Tooltip>
|
2024-02-18 09:58:37 +00:00
|
|
|
{currentMode && (
|
|
|
|
<div className="flex flex-shrink-0 items-center gap-2">
|
|
|
|
<CustomSelect
|
|
|
|
value={currentMode}
|
|
|
|
onChange={(val: any) => setPeekMode(val)}
|
|
|
|
customButton={
|
2024-04-23 07:19:29 +00:00
|
|
|
<Tooltip tooltipContent="Toggle peek view layout" isMobile={isMobile}>
|
|
|
|
<button type="button" className="">
|
|
|
|
<currentMode.icon className="h-4 w-4 text-custom-text-300 hover:text-custom-text-200" />
|
|
|
|
</button>
|
|
|
|
</Tooltip>
|
2024-02-18 09:58:37 +00:00
|
|
|
}
|
|
|
|
>
|
|
|
|
{PEEK_OPTIONS.map((mode) => (
|
|
|
|
<CustomSelect.Option key={mode.key} value={mode.key}>
|
|
|
|
<div
|
|
|
|
className={`flex items-center gap-1.5 ${
|
|
|
|
currentMode.key === mode.key
|
|
|
|
? "text-custom-text-200"
|
|
|
|
: "text-custom-text-400 hover:text-custom-text-200"
|
|
|
|
}`}
|
|
|
|
>
|
|
|
|
<mode.icon className="-my-1 h-4 w-4 flex-shrink-0" />
|
|
|
|
{mode.title}
|
|
|
|
</div>
|
|
|
|
</CustomSelect.Option>
|
|
|
|
))}
|
|
|
|
</CustomSelect>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
<div className="flex items-center gap-x-4">
|
|
|
|
<IssueUpdateStatus isSubmitting={isSubmitting} />
|
|
|
|
<div className="flex items-center gap-4">
|
|
|
|
{currentUser && !isArchived && (
|
|
|
|
<IssueSubscription workspaceSlug={workspaceSlug} projectId={projectId} issueId={issueId} />
|
|
|
|
)}
|
2024-03-12 15:09:36 +00:00
|
|
|
<Tooltip tooltipContent="Copy link" isMobile={isMobile}>
|
2024-02-28 11:23:26 +00:00
|
|
|
<button type="button" onClick={handleCopyText}>
|
|
|
|
<Link2 className="h-4 w-4 -rotate-45 text-custom-text-300 hover:text-custom-text-200" />
|
2024-02-18 09:58:37 +00:00
|
|
|
</button>
|
2024-02-28 11:23:26 +00:00
|
|
|
</Tooltip>
|
|
|
|
{isArchivingAllowed && (
|
|
|
|
<Tooltip
|
2024-03-12 15:09:36 +00:00
|
|
|
isMobile={isMobile}
|
2024-02-28 11:23:26 +00:00
|
|
|
tooltipContent={isInArchivableGroup ? "Archive" : "Only completed or canceled issues can be archived"}
|
|
|
|
>
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
className={cn("text-custom-text-300", {
|
|
|
|
"hover:text-custom-text-200": isInArchivableGroup,
|
|
|
|
"cursor-not-allowed text-custom-text-400": !isInArchivableGroup,
|
|
|
|
})}
|
|
|
|
onClick={() => {
|
|
|
|
if (!isInArchivableGroup) return;
|
|
|
|
toggleArchiveIssueModal(true);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<ArchiveIcon className="h-4 w-4" />
|
|
|
|
</button>
|
|
|
|
</Tooltip>
|
|
|
|
)}
|
|
|
|
{isRestoringAllowed && (
|
2024-03-12 15:09:36 +00:00
|
|
|
<Tooltip tooltipContent="Restore" isMobile={isMobile}>
|
2024-02-28 11:23:26 +00:00
|
|
|
<button type="button" onClick={handleRestoreIssue}>
|
2024-03-20 15:32:58 +00:00
|
|
|
<ArchiveRestoreIcon className="h-4 w-4 text-custom-text-300 hover:text-custom-text-200" />
|
2024-02-28 11:23:26 +00:00
|
|
|
</button>
|
|
|
|
</Tooltip>
|
|
|
|
)}
|
|
|
|
{!disabled && (
|
2024-03-12 15:09:36 +00:00
|
|
|
<Tooltip tooltipContent="Delete" isMobile={isMobile}>
|
2024-03-22 13:07:11 +00:00
|
|
|
<button type="button" onClick={() => toggleDeleteIssueModal(issueId)}>
|
2024-02-28 11:23:26 +00:00
|
|
|
<Trash2 className="h-4 w-4 text-custom-text-300 hover:text-custom-text-200" />
|
|
|
|
</button>
|
|
|
|
</Tooltip>
|
2024-02-18 09:58:37 +00:00
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
});
|