2025-08-02 22:46:15 -07:00
|
|
|
"use client";
|
|
|
|
|
|
2025-11-15 03:42:42 +02:00
|
|
|
import { useAtomValue } from "jotai";
|
2025-08-02 22:46:15 -07:00
|
|
|
import { usePathname } from "next/navigation";
|
feat(i18n): Add next-intl framework with full bilingual support (EN/ZH)
- Implement next-intl framework for scalable i18n
- Add complete Chinese (Simplified) localization
- Support 400+ translated strings across all pages
- Add language switcher with persistent preference
- Zero breaking changes to existing functionality
Framework additions:
- i18n routing and middleware
- LocaleContext for client-side state
- LanguageSwitcher component
- Translation files (en.json, zh.json)
Translated components:
- Homepage: Hero, features, CTA, navbar
- Auth: Login, register
- Dashboard: Main page, layout
- Connectors: Management, add page (all categories)
- Documents: Upload, manage, filters
- Settings: LLM configs, role assignments
- Onboarding: Add provider, assign roles
- Logs: Task logs viewer
Adding a new language now requires only:
1. Create messages/<locale>.json
2. Add locale to i18n/routing.ts
2025-10-26 14:05:46 +08:00
|
|
|
import { useTranslations } from "next-intl";
|
2025-11-15 03:42:42 +02:00
|
|
|
import React, { useEffect } from "react";
|
2025-11-19 08:29:33 +02:00
|
|
|
import { activeChatAtom } from "@/atoms/chats/chat-query.atoms";
|
2025-08-02 22:46:15 -07:00
|
|
|
import {
|
|
|
|
|
Breadcrumb,
|
|
|
|
|
BreadcrumbItem,
|
|
|
|
|
BreadcrumbLink,
|
|
|
|
|
BreadcrumbList,
|
|
|
|
|
BreadcrumbPage,
|
|
|
|
|
BreadcrumbSeparator,
|
|
|
|
|
} from "@/components/ui/breadcrumb";
|
2025-11-11 18:07:32 -08:00
|
|
|
import { useSearchSpace } from "@/hooks/use-search-space";
|
2025-08-02 22:46:15 -07:00
|
|
|
|
|
|
|
|
interface BreadcrumbItemInterface {
|
|
|
|
|
label: string;
|
|
|
|
|
href?: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function DashboardBreadcrumb() {
|
2025-10-27 20:30:10 -07:00
|
|
|
const t = useTranslations("breadcrumb");
|
2025-08-02 22:46:15 -07:00
|
|
|
const pathname = usePathname();
|
2025-11-15 03:42:42 +02:00
|
|
|
const { data: activeChatState } = useAtomValue(activeChatAtom);
|
2025-11-11 18:07:32 -08:00
|
|
|
// Extract search space ID and chat ID from pathname
|
|
|
|
|
const segments = pathname.split("/").filter(Boolean);
|
|
|
|
|
const searchSpaceId = segments[0] === "dashboard" && segments[1] ? segments[1] : null;
|
|
|
|
|
|
|
|
|
|
// Fetch search space details if we have an ID
|
|
|
|
|
const { searchSpace } = useSearchSpace({
|
|
|
|
|
searchSpaceId: searchSpaceId || "",
|
|
|
|
|
autoFetch: !!searchSpaceId,
|
|
|
|
|
});
|
|
|
|
|
|
2025-08-02 22:46:15 -07:00
|
|
|
// Parse the pathname to create breadcrumb items
|
|
|
|
|
const generateBreadcrumbs = (path: string): BreadcrumbItemInterface[] => {
|
|
|
|
|
const segments = path.split("/").filter(Boolean);
|
|
|
|
|
const breadcrumbs: BreadcrumbItemInterface[] = [];
|
|
|
|
|
|
|
|
|
|
// Always start with Dashboard
|
2025-10-27 20:30:10 -07:00
|
|
|
breadcrumbs.push({ label: t("dashboard"), href: "/dashboard" });
|
2025-08-02 22:46:15 -07:00
|
|
|
|
|
|
|
|
// Handle search space
|
|
|
|
|
if (segments[0] === "dashboard" && segments[1]) {
|
2025-11-11 18:07:32 -08:00
|
|
|
// Use the actual search space name if available, otherwise fall back to the ID
|
|
|
|
|
const searchSpaceLabel = searchSpace?.name || `${t("search_space")} ${segments[1]}`;
|
2025-10-27 20:30:10 -07:00
|
|
|
breadcrumbs.push({
|
2025-11-11 18:07:32 -08:00
|
|
|
label: searchSpaceLabel,
|
2025-10-27 20:30:10 -07:00
|
|
|
href: `/dashboard/${segments[1]}`,
|
|
|
|
|
});
|
2025-08-02 22:46:15 -07:00
|
|
|
|
|
|
|
|
// Handle specific sections
|
|
|
|
|
if (segments[2]) {
|
|
|
|
|
const section = segments[2];
|
|
|
|
|
let sectionLabel = section.charAt(0).toUpperCase() + section.slice(1);
|
|
|
|
|
|
|
|
|
|
// Map section names to more readable labels
|
|
|
|
|
const sectionLabels: Record<string, string> = {
|
2025-10-27 20:30:10 -07:00
|
|
|
researcher: t("researcher"),
|
|
|
|
|
documents: t("documents"),
|
|
|
|
|
connectors: t("connectors"),
|
2025-11-07 14:28:30 -08:00
|
|
|
sources: "Sources",
|
2025-10-27 20:30:10 -07:00
|
|
|
podcasts: t("podcasts"),
|
|
|
|
|
logs: t("logs"),
|
|
|
|
|
chats: t("chats"),
|
|
|
|
|
settings: t("settings"),
|
2025-08-02 22:46:15 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
sectionLabel = sectionLabels[section] || sectionLabel;
|
|
|
|
|
|
|
|
|
|
// Handle sub-sections
|
|
|
|
|
if (segments[3]) {
|
|
|
|
|
const subSection = segments[3];
|
|
|
|
|
let subSectionLabel = subSection.charAt(0).toUpperCase() + subSection.slice(1);
|
|
|
|
|
|
2025-11-07 14:28:30 -08:00
|
|
|
// Handle sources sub-sections
|
|
|
|
|
if (section === "sources") {
|
|
|
|
|
const sourceLabels: Record<string, string> = {
|
|
|
|
|
add: "Add Sources",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const sourceLabel = sourceLabels[subSection] || subSectionLabel;
|
|
|
|
|
breadcrumbs.push({
|
|
|
|
|
label: "Sources",
|
|
|
|
|
href: `/dashboard/${segments[1]}/sources`,
|
|
|
|
|
});
|
|
|
|
|
breadcrumbs.push({ label: sourceLabel });
|
|
|
|
|
return breadcrumbs;
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-02 22:46:15 -07:00
|
|
|
// Handle documents sub-sections
|
|
|
|
|
if (section === "documents") {
|
|
|
|
|
const documentLabels: Record<string, string> = {
|
2025-10-27 20:30:10 -07:00
|
|
|
upload: t("upload_documents"),
|
|
|
|
|
youtube: t("add_youtube"),
|
|
|
|
|
webpage: t("add_webpages"),
|
2025-08-02 22:46:15 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const documentLabel = documentLabels[subSection] || subSectionLabel;
|
|
|
|
|
breadcrumbs.push({
|
2025-10-27 20:30:10 -07:00
|
|
|
label: t("documents"),
|
2025-08-02 22:46:15 -07:00
|
|
|
href: `/dashboard/${segments[1]}/documents`,
|
|
|
|
|
});
|
|
|
|
|
breadcrumbs.push({ label: documentLabel });
|
|
|
|
|
return breadcrumbs;
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-11 18:07:32 -08:00
|
|
|
// Handle researcher sub-sections (chat IDs)
|
|
|
|
|
if (section === "researcher") {
|
|
|
|
|
// Use the actual chat title if available, otherwise fall back to the ID
|
2025-11-15 03:42:42 +02:00
|
|
|
const chatLabel = activeChatState?.chatDetails?.title || subSection;
|
2025-11-11 18:07:32 -08:00
|
|
|
breadcrumbs.push({
|
|
|
|
|
label: t("researcher"),
|
|
|
|
|
href: `/dashboard/${segments[1]}/researcher`,
|
|
|
|
|
});
|
|
|
|
|
breadcrumbs.push({ label: chatLabel });
|
|
|
|
|
return breadcrumbs;
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-02 22:46:15 -07:00
|
|
|
// Handle connector sub-sections
|
|
|
|
|
if (section === "connectors") {
|
|
|
|
|
// Handle specific connector types
|
|
|
|
|
if (subSection === "add" && segments[4]) {
|
|
|
|
|
const connectorType = segments[4];
|
|
|
|
|
const connectorLabels: Record<string, string> = {
|
|
|
|
|
"github-connector": "GitHub",
|
|
|
|
|
"jira-connector": "Jira",
|
|
|
|
|
"confluence-connector": "Confluence",
|
2025-12-04 14:08:44 +08:00
|
|
|
"bookstack-connector": "BookStack",
|
2025-08-02 22:46:15 -07:00
|
|
|
"discord-connector": "Discord",
|
|
|
|
|
"linear-connector": "Linear",
|
|
|
|
|
"clickup-connector": "ClickUp",
|
|
|
|
|
"slack-connector": "Slack",
|
|
|
|
|
"notion-connector": "Notion",
|
|
|
|
|
"tavily-api": "Tavily API",
|
|
|
|
|
"serper-api": "Serper API",
|
|
|
|
|
"linkup-api": "LinkUp API",
|
2025-09-28 22:31:55 -07:00
|
|
|
"luma-connector": "Luma",
|
2025-10-12 09:39:04 +05:30
|
|
|
"elasticsearch-connector": "Elasticsearch",
|
2025-11-22 19:19:00 -08:00
|
|
|
"webcrawler-connector": "Web Pages",
|
2025-08-02 22:46:15 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const connectorLabel = connectorLabels[connectorType] || connectorType;
|
|
|
|
|
breadcrumbs.push({
|
|
|
|
|
label: "Connectors",
|
|
|
|
|
href: `/dashboard/${segments[1]}/connectors`,
|
|
|
|
|
});
|
|
|
|
|
breadcrumbs.push({
|
|
|
|
|
label: "Add Connector",
|
|
|
|
|
href: `/dashboard/${segments[1]}/connectors/add`,
|
|
|
|
|
});
|
|
|
|
|
breadcrumbs.push({ label: connectorLabel });
|
|
|
|
|
return breadcrumbs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const connectorLabels: Record<string, string> = {
|
2025-10-27 20:30:10 -07:00
|
|
|
add: t("add_connector"),
|
|
|
|
|
manage: t("manage_connectors"),
|
2025-08-02 22:46:15 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const connectorLabel = connectorLabels[subSection] || subSectionLabel;
|
|
|
|
|
breadcrumbs.push({
|
2025-10-27 20:30:10 -07:00
|
|
|
label: t("connectors"),
|
2025-08-02 22:46:15 -07:00
|
|
|
href: `/dashboard/${segments[1]}/connectors`,
|
|
|
|
|
});
|
|
|
|
|
breadcrumbs.push({ label: connectorLabel });
|
|
|
|
|
return breadcrumbs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Handle other sub-sections
|
|
|
|
|
const subSectionLabels: Record<string, string> = {
|
2025-10-27 20:30:10 -07:00
|
|
|
upload: t("upload_documents"),
|
|
|
|
|
youtube: t("add_youtube"),
|
|
|
|
|
webpage: t("add_webpages"),
|
|
|
|
|
add: t("add_connector"),
|
|
|
|
|
edit: t("edit_connector"),
|
|
|
|
|
manage: t("manage"),
|
2025-08-02 22:46:15 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
subSectionLabel = subSectionLabels[subSection] || subSectionLabel;
|
|
|
|
|
|
|
|
|
|
breadcrumbs.push({
|
|
|
|
|
label: sectionLabel,
|
|
|
|
|
href: `/dashboard/${segments[1]}/${section}`,
|
|
|
|
|
});
|
|
|
|
|
breadcrumbs.push({ label: subSectionLabel });
|
|
|
|
|
} else {
|
|
|
|
|
breadcrumbs.push({ label: sectionLabel });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return breadcrumbs;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const breadcrumbs = generateBreadcrumbs(pathname);
|
|
|
|
|
|
|
|
|
|
if (breadcrumbs.length <= 1) {
|
|
|
|
|
return null; // Don't show breadcrumbs for root dashboard
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Breadcrumb>
|
|
|
|
|
<BreadcrumbList>
|
|
|
|
|
{breadcrumbs.map((item, index) => (
|
|
|
|
|
<React.Fragment key={index}>
|
|
|
|
|
<BreadcrumbItem>
|
|
|
|
|
{index === breadcrumbs.length - 1 ? (
|
|
|
|
|
<BreadcrumbPage>{item.label}</BreadcrumbPage>
|
|
|
|
|
) : (
|
|
|
|
|
<BreadcrumbLink href={item.href}>{item.label}</BreadcrumbLink>
|
|
|
|
|
)}
|
|
|
|
|
</BreadcrumbItem>
|
|
|
|
|
{index < breadcrumbs.length - 1 && <BreadcrumbSeparator />}
|
|
|
|
|
</React.Fragment>
|
|
|
|
|
))}
|
|
|
|
|
</BreadcrumbList>
|
|
|
|
|
</Breadcrumb>
|
|
|
|
|
);
|
|
|
|
|
}
|