[WEB-4429] fix: url path generation #7317
This commit is contained in:
parent
e624a17868
commit
6ea24bfdcd
3 changed files with 50 additions and 9 deletions
|
|
@ -318,3 +318,39 @@ export const copyTextToClipboard = async (text: string): Promise<void> => {
|
||||||
}
|
}
|
||||||
await navigator.clipboard.writeText(text);
|
await navigator.clipboard.writeText(text);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Joins URL path segments properly, removing duplicate slashes
|
||||||
|
* @param {...string} segments - URL path segments to join
|
||||||
|
* @returns {string} Properly joined URL path
|
||||||
|
* @example
|
||||||
|
* joinUrlPath("/workspace", "/projects") => "/workspace/projects"
|
||||||
|
* joinUrlPath("/workspace", "projects") => "/workspace/projects"
|
||||||
|
* joinUrlPath("workspace", "projects") => "workspace/projects"
|
||||||
|
* joinUrlPath("/workspace/", "/projects/") => "/workspace/projects/"
|
||||||
|
*/
|
||||||
|
export const joinUrlPath = (...segments: string[]): string => {
|
||||||
|
if (segments.length === 0) return "";
|
||||||
|
|
||||||
|
// Filter out empty segments
|
||||||
|
const validSegments = segments.filter((segment) => segment !== "");
|
||||||
|
if (validSegments.length === 0) return "";
|
||||||
|
|
||||||
|
// Join segments and normalize slashes
|
||||||
|
const joined = validSegments
|
||||||
|
.map((segment, index) => {
|
||||||
|
// Remove leading slashes from all segments except the first
|
||||||
|
if (index > 0) {
|
||||||
|
segment = segment.replace(/^\/+/, "");
|
||||||
|
}
|
||||||
|
// Remove trailing slashes from all segments except the last
|
||||||
|
if (index < validSegments.length - 1) {
|
||||||
|
segment = segment.replace(/\/+$/, "");
|
||||||
|
}
|
||||||
|
return segment;
|
||||||
|
})
|
||||||
|
.join("/");
|
||||||
|
|
||||||
|
// Clean up any duplicate slashes that might have been created
|
||||||
|
return joined.replace(/\/+/g, "/");
|
||||||
|
};
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import { Disclosure } from "@headlessui/react";
|
||||||
// plane imports
|
// plane imports
|
||||||
import { EUserWorkspaceRoles } from "@plane/constants";
|
import { EUserWorkspaceRoles } from "@plane/constants";
|
||||||
import { useTranslation } from "@plane/i18n";
|
import { useTranslation } from "@plane/i18n";
|
||||||
import { cn } from "@plane/utils";
|
import { cn, joinUrlPath } from "@plane/utils";
|
||||||
// hooks
|
// hooks
|
||||||
import { useUserSettings } from "@/hooks/store";
|
import { useUserSettings } from "@/hooks/store";
|
||||||
|
|
||||||
|
|
@ -72,7 +72,11 @@ const SettingsSidebarNavItem = observer((props: TSettingsSidebarNavItemProps) =>
|
||||||
{renderChildren ? (
|
{renderChildren ? (
|
||||||
<div className={buttonClass}>{titleElement}</div>
|
<div className={buttonClass}>{titleElement}</div>
|
||||||
) : (
|
) : (
|
||||||
<Link href={`/${workspaceSlug}/${setting.href}`} className={buttonClass} onClick={() => toggleSidebar(true)}>
|
<Link
|
||||||
|
href={joinUrlPath("/", workspaceSlug, setting.href)}
|
||||||
|
className={buttonClass}
|
||||||
|
onClick={() => toggleSidebar(true)}
|
||||||
|
>
|
||||||
{titleElement}
|
{titleElement}
|
||||||
</Link>
|
</Link>
|
||||||
)}
|
)}
|
||||||
|
|
|
||||||
|
|
@ -46,10 +46,11 @@ export const SettingsSidebar = observer((props: SettingsSidebarProps) => {
|
||||||
<SettingsSidebarHeader customHeader={customHeader} />
|
<SettingsSidebarHeader customHeader={customHeader} />
|
||||||
{/* Navigation */}
|
{/* Navigation */}
|
||||||
<div className="divide-y divide-custom-border-100 overflow-x-hidden w-full h-full overflow-y-scroll">
|
<div className="divide-y divide-custom-border-100 overflow-x-hidden w-full h-full overflow-y-scroll">
|
||||||
{categories.map((category) => (
|
{categories.map((category) => {
|
||||||
<div key={category} className="py-3">
|
if (groupedSettings[category].length === 0) return null;
|
||||||
<span className="text-sm font-semibold text-custom-text-350 capitalize mb-2">{t(category)}</span>
|
return (
|
||||||
{groupedSettings[category].length > 0 && (
|
<div key={category} className="py-3">
|
||||||
|
<span className="text-sm font-semibold text-custom-text-350 capitalize mb-2">{t(category)}</span>
|
||||||
<div className="relative flex flex-col gap-0.5 h-full mt-2">
|
<div className="relative flex flex-col gap-0.5 h-full mt-2">
|
||||||
{groupedSettings[category].map(
|
{groupedSettings[category].map(
|
||||||
(setting) =>
|
(setting) =>
|
||||||
|
|
@ -66,9 +67,9 @@ export const SettingsSidebar = observer((props: SettingsSidebarProps) => {
|
||||||
)
|
)
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
</div>
|
||||||
</div>
|
);
|
||||||
))}
|
})}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue