[WEB-2601] improvement: add click to copy issue identifier on peek-overview and issue detail page. (#5760)
This commit is contained in:
parent
c3c1ea727d
commit
6e52f1b434
2 changed files with 50 additions and 6 deletions
|
|
@ -1,6 +1,8 @@
|
||||||
import { observer } from "mobx-react";
|
import { observer } from "mobx-react";
|
||||||
// types
|
// types
|
||||||
import { IIssueDisplayProperties } from "@plane/types";
|
import { IIssueDisplayProperties } from "@plane/types";
|
||||||
|
// ui
|
||||||
|
import { setToast, TOAST_TYPE, Tooltip } from "@plane/ui";
|
||||||
// helpers
|
// helpers
|
||||||
import { cn } from "@/helpers/common.helper";
|
import { cn } from "@/helpers/common.helper";
|
||||||
// hooks
|
// hooks
|
||||||
|
|
@ -11,6 +13,7 @@ type TIssueIdentifierBaseProps = {
|
||||||
size?: "xs" | "sm" | "md" | "lg";
|
size?: "xs" | "sm" | "md" | "lg";
|
||||||
textContainerClassName?: string;
|
textContainerClassName?: string;
|
||||||
displayProperties?: IIssueDisplayProperties | undefined;
|
displayProperties?: IIssueDisplayProperties | undefined;
|
||||||
|
enableClickToCopyIdentifier?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
type TIssueIdentifierFromStore = TIssueIdentifierBaseProps & {
|
type TIssueIdentifierFromStore = TIssueIdentifierBaseProps & {
|
||||||
|
|
@ -23,9 +26,48 @@ type TIssueIdentifierWithDetails = TIssueIdentifierBaseProps & {
|
||||||
issueSequenceId: string | number;
|
issueSequenceId: string | number;
|
||||||
};
|
};
|
||||||
|
|
||||||
type TIssueIdentifierProps = TIssueIdentifierFromStore | TIssueIdentifierWithDetails;
|
export type TIssueIdentifierProps = TIssueIdentifierFromStore | TIssueIdentifierWithDetails;
|
||||||
|
|
||||||
|
type TIdentifierTextProps = {
|
||||||
|
identifier: string;
|
||||||
|
enableClickToCopyIdentifier?: boolean;
|
||||||
|
textContainerClassName?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const IdentifierText: React.FC<TIdentifierTextProps> = (props) => {
|
||||||
|
const { identifier, enableClickToCopyIdentifier = false, textContainerClassName } = props;
|
||||||
|
// handlers
|
||||||
|
const handleCopyIssueIdentifier = () => {
|
||||||
|
if (enableClickToCopyIdentifier) {
|
||||||
|
navigator.clipboard.writeText(identifier).then(() => {
|
||||||
|
setToast({
|
||||||
|
type: TOAST_TYPE.SUCCESS,
|
||||||
|
title: "Issue ID copied to clipboard",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Tooltip tooltipContent="Click to copy" disabled={!enableClickToCopyIdentifier} position="top">
|
||||||
|
<span
|
||||||
|
className={cn(
|
||||||
|
"text-base font-medium text-custom-text-300",
|
||||||
|
{
|
||||||
|
"cursor-pointer": enableClickToCopyIdentifier,
|
||||||
|
},
|
||||||
|
textContainerClassName
|
||||||
|
)}
|
||||||
|
onClick={handleCopyIssueIdentifier}
|
||||||
|
>
|
||||||
|
{identifier}
|
||||||
|
</span>
|
||||||
|
</Tooltip>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
export const IssueIdentifier: React.FC<TIssueIdentifierProps> = observer((props) => {
|
export const IssueIdentifier: React.FC<TIssueIdentifierProps> = observer((props) => {
|
||||||
const { projectId, textContainerClassName, displayProperties } = props;
|
const { projectId, textContainerClassName, displayProperties, enableClickToCopyIdentifier = false } = props;
|
||||||
// store hooks
|
// store hooks
|
||||||
const { getProjectIdentifierById } = useProject();
|
const { getProjectIdentifierById } = useProject();
|
||||||
const {
|
const {
|
||||||
|
|
@ -43,9 +85,11 @@ export const IssueIdentifier: React.FC<TIssueIdentifierProps> = observer((props)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex items-center space-x-2">
|
<div className="flex items-center space-x-2">
|
||||||
<span className={cn("text-base font-medium text-custom-text-300", textContainerClassName)}>
|
<IdentifierText
|
||||||
{projectIdentifier}-{issueSequenceId}
|
identifier={`${projectIdentifier}-${issueSequenceId}`}
|
||||||
</span>
|
enableClickToCopyIdentifier={enableClickToCopyIdentifier}
|
||||||
|
textContainerClassName={textContainerClassName}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -20,5 +20,5 @@ export const IssueTypeSwitcher: React.FC<TIssueTypeSwitcherProps> = observer((pr
|
||||||
|
|
||||||
if (!issue || !issue.project_id) return <></>;
|
if (!issue || !issue.project_id) return <></>;
|
||||||
|
|
||||||
return <IssueIdentifier issueId={issueId} projectId={issue.project_id} size="md" />;
|
return <IssueIdentifier issueId={issueId} projectId={issue.project_id} size="md" enableClickToCopyIdentifier />;
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue