mirror of
https://github.com/fosrl/pangolin.git
synced 2026-07-09 07:30:40 +02:00
🚧 WIP: copy command bar from existing PR
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import type { ReactNode } from "react";
|
||||
import type {
|
||||
SidebarNavItem,
|
||||
SidebarNavSection
|
||||
} from "@app/components/SidebarNav";
|
||||
|
||||
export type FlatNavItem = {
|
||||
title: string;
|
||||
href: string;
|
||||
icon?: ReactNode;
|
||||
sectionHeading: string;
|
||||
};
|
||||
|
||||
function flattenItems(
|
||||
items: SidebarNavItem[],
|
||||
sectionHeading: string,
|
||||
result: FlatNavItem[]
|
||||
) {
|
||||
for (const item of items) {
|
||||
if (item.href) {
|
||||
result.push({
|
||||
title: item.title,
|
||||
href: item.href,
|
||||
icon: item.icon,
|
||||
sectionHeading
|
||||
});
|
||||
}
|
||||
if (item.items?.length) {
|
||||
flattenItems(item.items, sectionHeading, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function flattenNavSections(
|
||||
sections: SidebarNavSection[]
|
||||
): FlatNavItem[] {
|
||||
const result: FlatNavItem[] = [];
|
||||
for (const section of sections) {
|
||||
flattenItems(section.items, section.heading, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
export type NavHrefParams = {
|
||||
orgId?: string;
|
||||
niceId?: string;
|
||||
resourceId?: string;
|
||||
userId?: string;
|
||||
apiKeyId?: string;
|
||||
clientId?: string;
|
||||
};
|
||||
|
||||
export function hydrateNavHref(
|
||||
val: string | undefined,
|
||||
params: NavHrefParams
|
||||
): string | undefined {
|
||||
if (!val) return undefined;
|
||||
return val
|
||||
.replace("{orgId}", params.orgId ?? "")
|
||||
.replace("{niceId}", params.niceId ?? "")
|
||||
.replace("{resourceId}", params.resourceId ?? "")
|
||||
.replace("{userId}", params.userId ?? "")
|
||||
.replace("{apiKeyId}", params.apiKeyId ?? "")
|
||||
.replace("{clientId}", params.clientId ?? "");
|
||||
}
|
||||
|
||||
export function navHrefParamsFromRoute(
|
||||
params: Record<string, string | string[] | undefined>
|
||||
): NavHrefParams {
|
||||
return {
|
||||
orgId: params.orgId as string | undefined,
|
||||
niceId: params.niceId as string | undefined,
|
||||
resourceId: params.resourceId as string | undefined,
|
||||
userId: params.userId as string | undefined,
|
||||
apiKeyId: params.apiKeyId as string | undefined,
|
||||
clientId: params.clientId as string | undefined
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user