Initial commit: Plane
Some checks failed
Branch Build CE / Build Setup (push) Has been cancelled
Branch Build CE / Build-Push Admin Docker Image (push) Has been cancelled
Branch Build CE / Build-Push Web Docker Image (push) Has been cancelled
Branch Build CE / Build-Push Space Docker Image (push) Has been cancelled
Branch Build CE / Build-Push Live Collaboration Docker Image (push) Has been cancelled
Branch Build CE / Build-Push API Server Docker Image (push) Has been cancelled
Branch Build CE / Build-Push Proxy Docker Image (push) Has been cancelled
Branch Build CE / Build-Push AIO Docker Image (push) Has been cancelled
Branch Build CE / Upload Build Assets (push) Has been cancelled
Branch Build CE / Build Release (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Codespell / Check for spelling errors (push) Has been cancelled
Sync Repositories / sync_changes (push) Has been cancelled
Some checks failed
Branch Build CE / Build Setup (push) Has been cancelled
Branch Build CE / Build-Push Admin Docker Image (push) Has been cancelled
Branch Build CE / Build-Push Web Docker Image (push) Has been cancelled
Branch Build CE / Build-Push Space Docker Image (push) Has been cancelled
Branch Build CE / Build-Push Live Collaboration Docker Image (push) Has been cancelled
Branch Build CE / Build-Push API Server Docker Image (push) Has been cancelled
Branch Build CE / Build-Push Proxy Docker Image (push) Has been cancelled
Branch Build CE / Build-Push AIO Docker Image (push) Has been cancelled
Branch Build CE / Upload Build Assets (push) Has been cancelled
Branch Build CE / Build Release (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Codespell / Check for spelling errors (push) Has been cancelled
Sync Repositories / sync_changes (push) Has been cancelled
Synced from upstream: 8853637e981ed7d8a6cff32bd98e7afe20f54362
This commit is contained in:
56
apps/web/core/components/settings/helper.ts
Normal file
56
apps/web/core/components/settings/helper.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import { GROUPED_PROFILE_SETTINGS, GROUPED_WORKSPACE_SETTINGS } from "@plane/constants";
|
||||
import { PROJECT_SETTINGS_LINKS } from "@/plane-web/constants/project";
|
||||
|
||||
const hrefToLabelMap = (options: Record<string, Array<{ href: string; i18n_label: string; [key: string]: any }>>) =>
|
||||
Object.values(options)
|
||||
.flat()
|
||||
.reduce(
|
||||
(acc, setting) => {
|
||||
acc[setting.href] = setting.i18n_label;
|
||||
return acc;
|
||||
},
|
||||
{} as Record<string, string>
|
||||
);
|
||||
|
||||
const workspaceHrefToLabelMap = hrefToLabelMap(GROUPED_WORKSPACE_SETTINGS);
|
||||
|
||||
const profiletHrefToLabelMap = hrefToLabelMap(GROUPED_PROFILE_SETTINGS);
|
||||
|
||||
const projectHrefToLabelMap = PROJECT_SETTINGS_LINKS.reduce(
|
||||
(acc, setting) => {
|
||||
acc[setting.href] = setting.i18n_label;
|
||||
return acc;
|
||||
},
|
||||
{} as Record<string, string>
|
||||
);
|
||||
|
||||
export const pathnameToAccessKey = (pathname: string) => {
|
||||
const pathArray = pathname.replace(/^\/|\/$/g, "").split("/"); // Regex removes leading and trailing slashes
|
||||
const workspaceSlug = pathArray[0];
|
||||
const accessKey = pathArray.slice(1, 3).join("/");
|
||||
return { workspaceSlug, accessKey: `/${accessKey}` || "" };
|
||||
};
|
||||
|
||||
export const getWorkspaceActivePath = (pathname: string) => {
|
||||
const parts = pathname.split("/").filter(Boolean);
|
||||
const settingsIndex = parts.indexOf("settings");
|
||||
if (settingsIndex === -1) return null;
|
||||
const subPath = "/" + parts.slice(settingsIndex, settingsIndex + 2).join("/");
|
||||
return workspaceHrefToLabelMap[subPath];
|
||||
};
|
||||
|
||||
export const getProfileActivePath = (pathname: string) => {
|
||||
const parts = pathname.split("/").filter(Boolean);
|
||||
const settingsIndex = parts.indexOf("settings");
|
||||
if (settingsIndex === -1) return null;
|
||||
const subPath = "/" + parts.slice(settingsIndex, settingsIndex + 3).join("/");
|
||||
return profiletHrefToLabelMap[subPath];
|
||||
};
|
||||
|
||||
export const getProjectActivePath = (pathname: string) => {
|
||||
const parts = pathname.split("/").filter(Boolean);
|
||||
const settingsIndex = parts.indexOf("settings");
|
||||
if (settingsIndex === -1) return null;
|
||||
const subPath = parts.slice(settingsIndex + 3, settingsIndex + 4).join("/");
|
||||
return subPath ? projectHrefToLabelMap["/" + subPath] : projectHrefToLabelMap[subPath];
|
||||
};
|
||||
Reference in New Issue
Block a user