π₯π₯π₯ Open-source Jira, Linear, Monday, and ClickUp alternative. Plane is a modern project management platform to manage tasks, sprints, docs, and triage.
TypeScript boardsbug-trackerdjangodockerganttissue-trackerjirajira-alternativekanbanlinearpostgresqlproduct-managementproject-managementproject-planningpythonreactredistypesciptvitework-management
[WEB-3797] fix: remove leading slash from URL to copy (#6890)
Aaryan Khandelwal37699362ad9a
diff --git a/packages/utils/src/string.ts b/packages/utils/src/string.tsindex 2fc52a254e..1ad761f972 100644--- a/packages/utils/src/string.ts+++ b/packages/utils/src/string.ts@@ -86,8 +86,11 @@ export const copyTextToClipboard = async (text: string): Promise<void> => {* await copyUrlToClipboard("issues/123") // copies "https://example.com/issues/123"*/export const copyUrlToClipboard = async (path: string) => {- const originUrl = typeof window !== "undefined" && window.location.origin ? window.location.origin : "";- await copyTextToClipboard(`${originUrl}/${path}`);+ // get origin or default to empty string if not in browser+ const originUrl = typeof window !== "undefined" ? window.location.origin : "";+ // create URL object and ensure proper path formatting+ const url = new URL(path, originUrl);+ await copyTextToClipboard(url.toString());};/**diff --git a/web/core/components/issues/create-issue-toast-action-items.tsx b/web/core/components/issues/create-issue-toast-action-items.tsxindex 16f2a2d757..f324710f21 100644--- a/web/core/components/issues/create-issue-toast-action-items.tsx+++ b/web/core/components/issues/create-issue-toast-action-items.tsx@@ -1,9 +1,10 @@"use client";import React, { FC, useState } from "react";import { observer } from "mobx-react";+// plane imports+import { copyUrlToClipboard } from "@plane/utils";// helpersimport { generateWorkItemLink } from "@/helpers/issue.helper";-import { copyUrlToClipboard } from "@/helpers/string.helper";// hooksimport { useIssueDetail, useProject } from "@/hooks/store";@@ -41,7 +42,7 @@ export const CreateIssueToastActionItems: FC<TCreateIssueToastActionItems> = obsconst copyToClipboard = async (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {try {- await copyUrlToClipboard(workItemLink, false);+ await copyUrlToClipboard(workItemLink);setCopied(true);setTimeout(() => setCopied(false), 3000);} catch (error) {diff --git a/web/core/components/issues/issue-layouts/quick-action-dropdowns/all-issue.tsx b/web/core/components/issues/issue-layouts/quick-action-dropdowns/all-issue.tsxindex 1dca91a934..752f909a75 100644--- a/web/core/components/issues/issue-layouts/quick-action-dropdowns/all-issue.tsx+++ b/web/core/components/issues/issue-layouts/quick-action-dropdowns/all-issue.tsx@@ -5,17 +5,16 @@ import omit from "lodash/omit";import { observer } from "mobx-react";import { useParams } from "next/navigation";import { Copy, ExternalLink, Link, Pencil, Trash2 } from "lucide-react";-// types+// plane importsimport { ARCHIVABLE_STATE_GROUPS, EIssuesStoreType } from "@plane/constants";import { TIssue } from "@plane/types";-// uiimport { ArchiveIcon, ContextMenu, CustomMenu, TContextMenuItem, TOAST_TYPE, setToast } from "@plane/ui";+import { copyUrlToClipboard } from "@plane/utils";// componentsimport { ArchiveIssueModal, CreateUpdateIssueModal, DeleteIssueModal } from "@/components/issues";// helpersimport { cn } from "@/helpers/common.helper";import { generateWorkItemLink } from "@/helpers/issue.helper";-import { copyUrlToClipboard } from "@/helpers/string.helper";// hooksimport { useEventTracker, useProject, useProjectState } from "@/hooks/store";// types@@ -62,7 +61,7 @@ export const AllIssueQuickActions: React.FC<IQuickActionProps> = observer((propsconst handleOpenInNewTab = () => window.open(workItemLink, "_blank");const handleCopyIssueLink = () =>- copyUrlToClipboard(workItemLink, false).then(() =>+ copyUrlToClipboard(workItemLink).then(() =>setToast({type: TOAST_TYPE.SUCCESS,title: "Link copied",diff --git a/web/core/components/issues/issue-layouts/quick-action-dropdowns/cycle-issue.tsx b/web/core/components/issues/issue-layouts/quick-action-dropdowns/cycle-issue.tsxindex 9d752b6308..d6af3bf1f7 100644--- a/web/core/components/issues/issue-layouts/quick-action-dropdowns/cycle-issue.tsx+++ b/web/core/components/issues/issue-layouts/quick-action-dropdowns/cycle-issue.tsx@@ -5,17 +5,16 @@ import omit from "lodash/omit";import { observer } from "mobx-react";import { useParams } from "next/navigation";import { Copy, ExternalLink, Link, Pencil, Trash2, XCircle } from "lucide-react";-// types+// plane importsimport { ARCHIVABLE_STATE_GROUPS, EIssuesStoreType, EUserPermissions, EUserPermissionsLevel } from "@plane/constants";import { TIssue } from "@plane/types";-// uiimport { ArchiveIcon, ContextMenu, CustomMenu, TContextMenuItem, TOAST_TYPE, setToast } from "@plane/ui";+import { copyUrlToClipboard } from "@plane/utils";// componentsimport { ArchiveIssueModal, CreateUpdateIssueModal, DeleteIssueModal } from "@/components/issues";// helpersimport { cn } from "@/helpers/common.helper";import { generateWorkItemLink } from "@/helpers/issue.helper";-import { copyUrlToClipboard } from "@/helpers/string.helper";// hooksimport { useEventTracker, useIssues, useProject, useProjectState, useUserPermissions } from "@/hooks/store";// types@@ -70,7 +69,7 @@ export const CycleIssueQuickActions: React.FC<IQuickActionProps> = observer((proconst handleOpenInNewTab = () => window.open(workItemLink, "_blank");const handleCopyIssueLink = () =>- copyUrlToClipboard(workItemLink, false).then(() =>+ copyUrlToClipboard(workItemLink).then(() =>setToast({type: TOAST_TYPE.SUCCESS,title: "Link copied",diff --git a/web/core/components/issues/issue-layouts/quick-action-dropdowns/module-issue.tsx b/web/core/components/issues/issue-layouts/quick-action-dropdowns/module-issue.tsxindex c2f0aa9941..c7f949fcf9 100644--- a/web/core/components/issues/issue-layouts/quick-action-dropdowns/module-issue.tsx+++ b/web/core/components/issues/issue-layouts/quick-action-dropdowns/module-issue.tsx@@ -5,17 +5,16 @@ import omit from "lodash/omit";import { observer } from "mobx-react";import { useParams } from "next/navigation";import { Copy, ExternalLink, Link, Pencil, Trash2, XCircle } from "lucide-react";-// types+// plane importsimport { ARCHIVABLE_STATE_GROUPS, EIssuesStoreType, EUserPermissions, EUserPermissionsLevel } from "@plane/constants";import { TIssue } from "@plane/types";-// uiimport { ArchiveIcon, ContextMenu, CustomMenu, TContextMenuItem, TOAST_TYPE, setToast } from "@plane/ui";+import { copyUrlToClipboard } from "@plane/utils";// componentsimport { ArchiveIssueModal, CreateUpdateIssueModal, DeleteIssueModal } from "@/components/issues";// helpersimport { cn } from "@/helpers/common.helper";import { generateWorkItemLink } from "@/helpers/issue.helper";-import { copyUrlToClipboard } from "@/helpers/string.helper";// hooksimport { useIssues, useEventTracker, useProjectState, useUserPermissions, useProject } from "@/hooks/store";// types@@ -70,7 +69,7 @@ export const ModuleIssueQuickActions: React.FC<IQuickActionProps> = observer((prconst handleOpenInNewTab = () => window.open(workItemLink, "_blank");const handleCopyIssueLink = () =>- copyUrlToClipboard(workItemLink, false).then(() =>+ copyUrlToClipboard(workItemLink).then(() =>setToast({type: TOAST_TYPE.SUCCESS,title: "Link copied",diff --git a/web/core/components/issues/issue-layouts/quick-action-dropdowns/project-issue.tsx b/web/core/components/issues/issue-layouts/quick-action-dropdowns/project-issue.tsxindex ac346a4f4a..902351f2bb 100644--- a/web/core/components/issues/issue-layouts/quick-action-dropdowns/project-issue.tsx+++ b/web/core/components/issues/issue-layouts/quick-action-dropdowns/project-issue.tsx@@ -5,18 +5,17 @@ import omit from "lodash/omit";import { observer } from "mobx-react";import { useParams, usePathname } from "next/navigation";import { Copy, ExternalLink, Link, Pencil, Trash2 } from "lucide-react";+// plane importsimport { ARCHIVABLE_STATE_GROUPS, EIssuesStoreType, EUserPermissions, EUserPermissionsLevel } from "@plane/constants";import { useTranslation } from "@plane/i18n";-// typesimport { TIssue } from "@plane/types";-// uiimport { ArchiveIcon, ContextMenu, CustomMenu, TContextMenuItem, TOAST_TYPE, setToast } from "@plane/ui";+import { copyUrlToClipboard } from "@plane/utils";// componentsimport { ArchiveIssueModal, CreateUpdateIssueModal, DeleteIssueModal } from "@/components/issues";// helpersimport { cn } from "@/helpers/common.helper";import { generateWorkItemLink } from "@/helpers/issue.helper";-import { copyUrlToClipboard } from "@/helpers/string.helper";// hooksimport { useEventTracker, useIssues, useProject, useProjectState, useUserPermissions } from "@/hooks/store";// types@@ -75,7 +74,7 @@ export const ProjectIssueQuickActions: React.FC<IQuickActionProps> = observer((p});const handleCopyIssueLink = () =>- copyUrlToClipboard(workItemLink, false).then(() =>+ copyUrlToClipboard(workItemLink).then(() =>setToast({type: TOAST_TYPE.SUCCESS,title: "Link copied",diff --git a/web/core/components/issues/peek-overview/header.tsx b/web/core/components/issues/peek-overview/header.tsxindex b877183dc8..a489ad1746 100644--- a/web/core/components/issues/peek-overview/header.tsx+++ b/web/core/components/issues/peek-overview/header.tsx@@ -6,11 +6,8 @@ import Link from "next/link";import { ArchiveRestoreIcon, Link2, MoveDiagonal, MoveRight, Trash2 } from "lucide-react";// plane importsimport { ARCHIVABLE_STATE_GROUPS } from "@plane/constants";-// i18nimport { useTranslation } from "@plane/i18n";-// typesimport { TNameDescriptionLoader } from "@plane/types";-// uiimport {ArchiveIcon,CenterPanelIcon,@@ -21,12 +18,12 @@ import {Tooltip,setToast,} from "@plane/ui";+import { copyUrlToClipboard } from "@plane/utils";// componentsimport { IssueSubscription, NameDescriptionUpdateStatus } from "@/components/issues";// helpersimport { cn } from "@/helpers/common.helper";import { generateWorkItemLink } from "@/helpers/issue.helper";-import { copyUrlToClipboard } from "@/helpers/string.helper";// store hooksimport { useIssueDetail, useProject, useProjectState, useUser } from "@/hooks/store";// hooks@@ -110,7 +107,7 @@ export const IssuePeekOverviewHeader: FC<PeekOverviewHeaderProps> = observer((prconst handleCopyText = (e: React.MouseEvent<HTMLButtonElement>) => {e.stopPropagation();e.preventDefault();- copyUrlToClipboard(workItemLink, false).then(() => {+ copyUrlToClipboard(workItemLink).then(() => {setToast({type: TOAST_TYPE.SUCCESS,title: t("common.link_copied"),diff --git a/web/core/hooks/use-page-operations.ts b/web/core/hooks/use-page-operations.tsindex 85862d828b..c893126b8b 100644--- a/web/core/hooks/use-page-operations.ts+++ b/web/core/hooks/use-page-operations.ts@@ -1,14 +1,10 @@import { useMemo } from "react";-// plane constants+// plane importsimport { IS_FAVORITE_MENU_OPEN } from "@plane/constants";-// plane editorimport { EditorRefApi } from "@plane/editor";-// plane typesimport { EPageAccess } from "@plane/types/src/enums";-// plane uiimport { setToast, TOAST_TYPE } from "@plane/ui";-// helpers-import { copyUrlToClipboard } from "@/helpers/string.helper";+import { copyUrlToClipboard } from "@plane/utils";// hooksimport { useCollaborativePageActions } from "@/hooks/use-collaborative-page-actions";// store typesdiff --git a/web/helpers/string.helper.ts b/web/helpers/string.helper.tsindex 3f31d73ac1..d097310917 100644--- a/web/helpers/string.helper.ts+++ b/web/helpers/string.helper.ts@@ -65,20 +65,6 @@ export const copyTextToClipboard = async (text: string) => {await navigator.clipboard.writeText(text);};-/**- * @description: This function copies the url to clipboard after prepending the origin URL to it- * @param {string} path- * @param {boolean} addSlash- * @example:- * const text = copyUrlToClipboard("path");- * copied URL: origin_url/path- */-export const copyUrlToClipboard = async (path: string, addSlash: boolean = true) => {- const originUrl = typeof window !== "undefined" && window.location.origin ? window.location.origin : "";-- await copyTextToClipboard(`${originUrl}${addSlash ? "/" : ""}${path}`);-};-export const generateRandomColor = (string: string): string => {if (!string) return "rgb(var(--color-primary-100))";