mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-23 19:05:16 +02:00
refactor: implement SearchSpaceSettingsPage and SearchSpaceSettingsPanel components, replacing the previous settings dialog and enhancing tab navigation for search space settings
This commit is contained in:
parent
08142f9add
commit
b6aed05683
13 changed files with 330 additions and 329 deletions
|
|
@ -1,140 +0,0 @@
|
|||
"use client";
|
||||
|
||||
import { useAtom } from "jotai";
|
||||
import {
|
||||
BookText,
|
||||
Bot,
|
||||
Brain,
|
||||
CircleUser,
|
||||
Earth,
|
||||
ImageIcon,
|
||||
ListChecks,
|
||||
ScanEye,
|
||||
UserKey,
|
||||
} from "lucide-react";
|
||||
import dynamic from "next/dynamic";
|
||||
import { useTranslations } from "next-intl";
|
||||
import type React from "react";
|
||||
import { searchSpaceSettingsDialogAtom } from "@/atoms/settings/settings-dialog.atoms";
|
||||
import { SettingsDialog } from "@/components/settings/settings-dialog";
|
||||
|
||||
const GeneralSettingsManager = dynamic(
|
||||
() =>
|
||||
import("@/components/settings/general-settings-manager").then((m) => ({
|
||||
default: m.GeneralSettingsManager,
|
||||
})),
|
||||
{ ssr: false }
|
||||
);
|
||||
const AgentModelManager = dynamic(
|
||||
() =>
|
||||
import("@/components/settings/agent-model-manager").then((m) => ({
|
||||
default: m.AgentModelManager,
|
||||
})),
|
||||
{ ssr: false }
|
||||
);
|
||||
const LLMRoleManager = dynamic(
|
||||
() =>
|
||||
import("@/components/settings/llm-role-manager").then((m) => ({ default: m.LLMRoleManager })),
|
||||
{ ssr: false }
|
||||
);
|
||||
const ImageModelManager = dynamic(
|
||||
() =>
|
||||
import("@/components/settings/image-model-manager").then((m) => ({
|
||||
default: m.ImageModelManager,
|
||||
})),
|
||||
{ ssr: false }
|
||||
);
|
||||
const VisionModelManager = dynamic(
|
||||
() =>
|
||||
import("@/components/settings/vision-model-manager").then((m) => ({
|
||||
default: m.VisionModelManager,
|
||||
})),
|
||||
{ ssr: false }
|
||||
);
|
||||
const RolesManager = dynamic(
|
||||
() => import("@/components/settings/roles-manager").then((m) => ({ default: m.RolesManager })),
|
||||
{ ssr: false }
|
||||
);
|
||||
const PromptConfigManager = dynamic(
|
||||
() =>
|
||||
import("@/components/settings/prompt-config-manager").then((m) => ({
|
||||
default: m.PromptConfigManager,
|
||||
})),
|
||||
{ ssr: false }
|
||||
);
|
||||
const PublicChatSnapshotsManager = dynamic(
|
||||
() =>
|
||||
import("@/components/public-chat-snapshots/public-chat-snapshots-manager").then((m) => ({
|
||||
default: m.PublicChatSnapshotsManager,
|
||||
})),
|
||||
{ ssr: false }
|
||||
);
|
||||
const TeamMemoryManager = dynamic(
|
||||
() =>
|
||||
import("@/components/settings/team-memory-manager").then((m) => ({
|
||||
default: m.TeamMemoryManager,
|
||||
})),
|
||||
{ ssr: false }
|
||||
);
|
||||
|
||||
interface SearchSpaceSettingsDialogProps {
|
||||
searchSpaceId: number;
|
||||
}
|
||||
|
||||
export function SearchSpaceSettingsDialog({ searchSpaceId }: SearchSpaceSettingsDialogProps) {
|
||||
const t = useTranslations("searchSpaceSettings");
|
||||
const [state, setState] = useAtom(searchSpaceSettingsDialogAtom);
|
||||
|
||||
const navItems = [
|
||||
{ value: "general", label: t("nav_general"), icon: <CircleUser className="h-4 w-4" /> },
|
||||
{ value: "roles", label: t("nav_role_assignments"), icon: <ListChecks className="h-4 w-4" /> },
|
||||
{ value: "models", label: t("nav_agent_models"), icon: <Bot className="h-4 w-4" /> },
|
||||
{
|
||||
value: "image-models",
|
||||
label: t("nav_image_models"),
|
||||
icon: <ImageIcon className="h-4 w-4" />,
|
||||
},
|
||||
{
|
||||
value: "vision-models",
|
||||
label: t("nav_vision_models"),
|
||||
icon: <ScanEye className="h-4 w-4" />,
|
||||
},
|
||||
{ value: "team-roles", label: t("nav_team_roles"), icon: <UserKey className="h-4 w-4" /> },
|
||||
{
|
||||
value: "prompts",
|
||||
label: t("nav_system_instructions"),
|
||||
icon: <BookText className="h-4 w-4" />,
|
||||
},
|
||||
{
|
||||
value: "team-memory",
|
||||
label: "Team Memory",
|
||||
icon: <Brain className="h-4 w-4" />,
|
||||
},
|
||||
{ value: "public-links", label: t("nav_public_links"), icon: <Earth className="h-4 w-4" /> },
|
||||
];
|
||||
|
||||
const content: Record<string, React.ReactNode> = {
|
||||
general: <GeneralSettingsManager searchSpaceId={searchSpaceId} />,
|
||||
models: <AgentModelManager searchSpaceId={searchSpaceId} />,
|
||||
roles: <LLMRoleManager key={searchSpaceId} searchSpaceId={searchSpaceId} />,
|
||||
"image-models": <ImageModelManager searchSpaceId={searchSpaceId} />,
|
||||
"vision-models": <VisionModelManager searchSpaceId={searchSpaceId} />,
|
||||
"team-roles": <RolesManager searchSpaceId={searchSpaceId} />,
|
||||
prompts: <PromptConfigManager searchSpaceId={searchSpaceId} />,
|
||||
"team-memory": <TeamMemoryManager searchSpaceId={searchSpaceId} />,
|
||||
"public-links": <PublicChatSnapshotsManager searchSpaceId={searchSpaceId} />,
|
||||
};
|
||||
|
||||
return (
|
||||
<SettingsDialog
|
||||
open={state.open}
|
||||
onOpenChange={(open) => setState((prev) => ({ ...prev, open }))}
|
||||
title={t("title")}
|
||||
navItems={navItems}
|
||||
activeItem={state.initialTab}
|
||||
onItemChange={(tab) => setState((prev) => ({ ...prev, initialTab: tab }))}
|
||||
>
|
||||
<div className="pt-4">{content[state.initialTab]}</div>
|
||||
</SettingsDialog>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,245 @@
|
|||
"use client";
|
||||
|
||||
import {
|
||||
BookText,
|
||||
Bot,
|
||||
Brain,
|
||||
CircleUser,
|
||||
Earth,
|
||||
ImageIcon,
|
||||
ListChecks,
|
||||
ScanEye,
|
||||
UserKey,
|
||||
} from "lucide-react";
|
||||
import dynamic from "next/dynamic";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useTranslations } from "next-intl";
|
||||
import type React from "react";
|
||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Separator } from "@/components/ui/separator";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
const GeneralSettingsManager = dynamic(
|
||||
() =>
|
||||
import("@/components/settings/general-settings-manager").then((m) => ({
|
||||
default: m.GeneralSettingsManager,
|
||||
})),
|
||||
{ ssr: false }
|
||||
);
|
||||
const AgentModelManager = dynamic(
|
||||
() =>
|
||||
import("@/components/settings/agent-model-manager").then((m) => ({
|
||||
default: m.AgentModelManager,
|
||||
})),
|
||||
{ ssr: false }
|
||||
);
|
||||
const LLMRoleManager = dynamic(
|
||||
() =>
|
||||
import("@/components/settings/llm-role-manager").then((m) => ({ default: m.LLMRoleManager })),
|
||||
{ ssr: false }
|
||||
);
|
||||
const ImageModelManager = dynamic(
|
||||
() =>
|
||||
import("@/components/settings/image-model-manager").then((m) => ({
|
||||
default: m.ImageModelManager,
|
||||
})),
|
||||
{ ssr: false }
|
||||
);
|
||||
const VisionModelManager = dynamic(
|
||||
() =>
|
||||
import("@/components/settings/vision-model-manager").then((m) => ({
|
||||
default: m.VisionModelManager,
|
||||
})),
|
||||
{ ssr: false }
|
||||
);
|
||||
const RolesManager = dynamic(
|
||||
() => import("@/components/settings/roles-manager").then((m) => ({ default: m.RolesManager })),
|
||||
{ ssr: false }
|
||||
);
|
||||
const PromptConfigManager = dynamic(
|
||||
() =>
|
||||
import("@/components/settings/prompt-config-manager").then((m) => ({
|
||||
default: m.PromptConfigManager,
|
||||
})),
|
||||
{ ssr: false }
|
||||
);
|
||||
const PublicChatSnapshotsManager = dynamic(
|
||||
() =>
|
||||
import("@/components/public-chat-snapshots/public-chat-snapshots-manager").then((m) => ({
|
||||
default: m.PublicChatSnapshotsManager,
|
||||
})),
|
||||
{ ssr: false }
|
||||
);
|
||||
const TeamMemoryManager = dynamic(
|
||||
() =>
|
||||
import("@/components/settings/team-memory-manager").then((m) => ({
|
||||
default: m.TeamMemoryManager,
|
||||
})),
|
||||
{ ssr: false }
|
||||
);
|
||||
|
||||
export type SearchSpaceSettingsTab =
|
||||
| "general"
|
||||
| "roles"
|
||||
| "models"
|
||||
| "image-models"
|
||||
| "vision-models"
|
||||
| "team-roles"
|
||||
| "prompts"
|
||||
| "team-memory"
|
||||
| "public-links";
|
||||
|
||||
interface SearchSpaceSettingsPanelProps {
|
||||
searchSpaceId: string;
|
||||
initialTab?: SearchSpaceSettingsTab;
|
||||
}
|
||||
|
||||
export function SearchSpaceSettingsPanel({
|
||||
searchSpaceId,
|
||||
initialTab = "general",
|
||||
}: SearchSpaceSettingsPanelProps) {
|
||||
const t = useTranslations("searchSpaceSettings");
|
||||
const router = useRouter();
|
||||
const numericSearchSpaceId = Number(searchSpaceId);
|
||||
const [activeTab, setActiveTab] = useState<SearchSpaceSettingsTab>(initialTab);
|
||||
const [tabScrollPos, setTabScrollPos] = useState<"start" | "middle" | "end">("start");
|
||||
|
||||
useEffect(() => {
|
||||
setActiveTab(initialTab);
|
||||
}, [initialTab]);
|
||||
|
||||
const handleTabScroll = useCallback((e: React.UIEvent<HTMLDivElement>) => {
|
||||
const el = e.currentTarget;
|
||||
const atStart = el.scrollLeft <= 2;
|
||||
const atEnd = el.scrollWidth - el.scrollLeft - el.clientWidth <= 2;
|
||||
setTabScrollPos(atStart ? "start" : atEnd ? "end" : "middle");
|
||||
}, []);
|
||||
|
||||
const navItems = useMemo(
|
||||
() => [
|
||||
{ value: "general", label: t("nav_general"), icon: <CircleUser className="h-4 w-4" /> },
|
||||
{ value: "roles", label: t("nav_role_assignments"), icon: <ListChecks className="h-4 w-4" /> },
|
||||
{ value: "models", label: t("nav_agent_models"), icon: <Bot className="h-4 w-4" /> },
|
||||
{
|
||||
value: "image-models",
|
||||
label: t("nav_image_models"),
|
||||
icon: <ImageIcon className="h-4 w-4" />,
|
||||
},
|
||||
{
|
||||
value: "vision-models",
|
||||
label: t("nav_vision_models"),
|
||||
icon: <ScanEye className="h-4 w-4" />,
|
||||
},
|
||||
{ value: "team-roles", label: t("nav_team_roles"), icon: <UserKey className="h-4 w-4" /> },
|
||||
{
|
||||
value: "prompts",
|
||||
label: t("nav_system_instructions"),
|
||||
icon: <BookText className="h-4 w-4" />,
|
||||
},
|
||||
{
|
||||
value: "team-memory",
|
||||
label: "Team Memory",
|
||||
icon: <Brain className="h-4 w-4" />,
|
||||
},
|
||||
{ value: "public-links", label: t("nav_public_links"), icon: <Earth className="h-4 w-4" /> },
|
||||
],
|
||||
[t]
|
||||
);
|
||||
|
||||
const selectedTab = navItems.some((item) => item.value === activeTab) ? activeTab : "general";
|
||||
const selectedLabel = navItems.find((item) => item.value === selectedTab)?.label ?? t("title");
|
||||
|
||||
const handleItemChange = (tab: SearchSpaceSettingsTab) => {
|
||||
setActiveTab(tab);
|
||||
const suffix = tab === "general" ? "" : `?tab=${tab}`;
|
||||
router.replace(`/dashboard/${searchSpaceId}/search-space-settings${suffix}`, { scroll: false });
|
||||
};
|
||||
|
||||
return (
|
||||
<section className="flex h-full min-h-[min(680px,calc(100vh-5rem))] w-full select-none flex-col gap-6 md:pt-6 md:flex-row">
|
||||
<div className="md:w-[220px] md:shrink-0">
|
||||
<h1 className="mb-4 px-1 text-2xl font-semibold tracking-tight">{t("title")}</h1>
|
||||
<nav className="hidden flex-col gap-0.5 md:flex">
|
||||
{navItems.map((item) => (
|
||||
<Button
|
||||
key={item.value}
|
||||
type="button"
|
||||
variant="ghost"
|
||||
onClick={() => handleItemChange(item.value as SearchSpaceSettingsTab)}
|
||||
className={cn(
|
||||
"h-auto justify-start gap-3 px-3 py-2.5 text-left text-sm font-medium transition-colors duration-150 focus:outline-none focus-visible:outline-none",
|
||||
selectedTab === item.value
|
||||
? "bg-accent text-accent-foreground"
|
||||
: "bg-transparent text-muted-foreground hover:bg-accent hover:text-accent-foreground"
|
||||
)}
|
||||
>
|
||||
{item.icon}
|
||||
{item.label}
|
||||
</Button>
|
||||
))}
|
||||
</nav>
|
||||
<div
|
||||
className="overflow-x-auto border-b border-border pb-3 md:hidden"
|
||||
onScroll={handleTabScroll}
|
||||
style={{
|
||||
maskImage: `linear-gradient(to right, ${tabScrollPos === "start" ? "black" : "transparent"}, black 24px, black calc(100% - 24px), ${tabScrollPos === "end" ? "black" : "transparent"})`,
|
||||
WebkitMaskImage: `linear-gradient(to right, ${tabScrollPos === "start" ? "black" : "transparent"}, black 24px, black calc(100% - 24px), ${tabScrollPos === "end" ? "black" : "transparent"})`,
|
||||
}}
|
||||
>
|
||||
<div className="flex gap-1">
|
||||
{navItems.map((item) => (
|
||||
<Button
|
||||
key={item.value}
|
||||
type="button"
|
||||
variant="ghost"
|
||||
onClick={() => handleItemChange(item.value as SearchSpaceSettingsTab)}
|
||||
className={cn(
|
||||
"h-auto shrink-0 gap-2 px-3 py-1.5 text-xs font-medium transition-colors duration-150 focus:outline-none focus-visible:outline-none",
|
||||
selectedTab === item.value
|
||||
? "bg-accent text-accent-foreground"
|
||||
: "bg-transparent text-muted-foreground hover:bg-accent hover:text-accent-foreground"
|
||||
)}
|
||||
>
|
||||
{item.icon}
|
||||
{item.label}
|
||||
</Button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="hidden md:block">
|
||||
<h2 className="text-lg font-semibold">{selectedLabel}</h2>
|
||||
<Separator className="mt-4" />
|
||||
</div>
|
||||
<div className="min-w-0 pt-4 md:max-w-3xl">
|
||||
{selectedTab === "general" && (
|
||||
<GeneralSettingsManager searchSpaceId={numericSearchSpaceId} />
|
||||
)}
|
||||
{selectedTab === "models" && <AgentModelManager searchSpaceId={numericSearchSpaceId} />}
|
||||
{selectedTab === "roles" && (
|
||||
<LLMRoleManager key={searchSpaceId} searchSpaceId={numericSearchSpaceId} />
|
||||
)}
|
||||
{selectedTab === "image-models" && (
|
||||
<ImageModelManager searchSpaceId={numericSearchSpaceId} />
|
||||
)}
|
||||
{selectedTab === "vision-models" && (
|
||||
<VisionModelManager searchSpaceId={numericSearchSpaceId} />
|
||||
)}
|
||||
{selectedTab === "team-roles" && <RolesManager searchSpaceId={numericSearchSpaceId} />}
|
||||
{selectedTab === "prompts" && (
|
||||
<PromptConfigManager searchSpaceId={numericSearchSpaceId} />
|
||||
)}
|
||||
{selectedTab === "team-memory" && (
|
||||
<TeamMemoryManager searchSpaceId={numericSearchSpaceId} />
|
||||
)}
|
||||
{selectedTab === "public-links" && (
|
||||
<PublicChatSnapshotsManager searchSpaceId={numericSearchSpaceId} />
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
|
@ -1,129 +0,0 @@
|
|||
"use client";
|
||||
|
||||
import type * as React from "react";
|
||||
import { useCallback, useRef, useState } from "react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Dialog, DialogContent, DialogTitle } from "@/components/ui/dialog";
|
||||
import { Separator } from "@/components/ui/separator";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
interface NavItem {
|
||||
value: string;
|
||||
label: string;
|
||||
icon: React.ReactNode;
|
||||
}
|
||||
|
||||
interface SettingsDialogProps {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
title: string;
|
||||
navItems: NavItem[];
|
||||
activeItem: string;
|
||||
onItemChange: (value: string) => void;
|
||||
children: React.ReactNode;
|
||||
}
|
||||
|
||||
export function SettingsDialog({
|
||||
open,
|
||||
onOpenChange,
|
||||
title,
|
||||
navItems,
|
||||
activeItem,
|
||||
onItemChange,
|
||||
children,
|
||||
}: SettingsDialogProps) {
|
||||
const activeRef = useRef<HTMLButtonElement>(null);
|
||||
const [tabScrollPos, setTabScrollPos] = useState<"start" | "middle" | "end">("start");
|
||||
|
||||
const handleTabScroll = useCallback((e: React.UIEvent<HTMLDivElement>) => {
|
||||
const el = e.currentTarget;
|
||||
const atStart = el.scrollLeft <= 2;
|
||||
const atEnd = el.scrollWidth - el.scrollLeft - el.clientWidth <= 2;
|
||||
setTabScrollPos(atStart ? "start" : atEnd ? "end" : "middle");
|
||||
}, []);
|
||||
|
||||
const handleItemChange = (value: string) => {
|
||||
onItemChange(value);
|
||||
activeRef.current?.scrollIntoView({ inline: "center", block: "nearest", behavior: "smooth" });
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="select-none max-w-[900px] w-[95vw] md:w-[90vw] h-[90vh] md:h-[80vh] max-h-[640px] flex flex-col md:flex-row p-0 gap-0 overflow-hidden [--card:var(--popover)]">
|
||||
<DialogTitle className="sr-only">{title}</DialogTitle>
|
||||
|
||||
{/* Desktop: Left sidebar */}
|
||||
<nav className="hidden md:flex w-[220px] shrink-0 flex-col border-r border-border p-3 pt-6">
|
||||
<div className="flex flex-col gap-0.5">
|
||||
{navItems.map((item) => (
|
||||
<Button
|
||||
key={item.value}
|
||||
type="button"
|
||||
variant="ghost"
|
||||
onClick={() => onItemChange(item.value)}
|
||||
className={cn(
|
||||
"h-auto justify-start gap-3 rounded-lg px-3 py-2.5 text-left text-sm font-medium transition-colors focus:outline-none focus-visible:outline-none",
|
||||
activeItem === item.value
|
||||
? "bg-accent text-accent-foreground"
|
||||
: "text-muted-foreground hover:bg-accent hover:text-accent-foreground"
|
||||
)}
|
||||
>
|
||||
{item.icon}
|
||||
{item.label}
|
||||
</Button>
|
||||
))}
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
{/* Mobile: Top header + horizontal tabs */}
|
||||
<div className="flex md:hidden flex-col shrink-0">
|
||||
<div className="px-4 pt-4 pb-2">
|
||||
<h2 className="text-base font-semibold">{title}</h2>
|
||||
</div>
|
||||
<div
|
||||
className="overflow-x-auto scrollbar-hide border-b border-border"
|
||||
onScroll={handleTabScroll}
|
||||
style={{
|
||||
maskImage: `linear-gradient(to right, ${tabScrollPos === "start" ? "black" : "transparent"}, black 24px, black calc(100% - 24px), ${tabScrollPos === "end" ? "black" : "transparent"})`,
|
||||
WebkitMaskImage: `linear-gradient(to right, ${tabScrollPos === "start" ? "black" : "transparent"}, black 24px, black calc(100% - 24px), ${tabScrollPos === "end" ? "black" : "transparent"})`,
|
||||
}}
|
||||
>
|
||||
<div className="flex gap-1 px-4 pb-2">
|
||||
{navItems.map((item) => (
|
||||
<Button
|
||||
key={item.value}
|
||||
ref={activeItem === item.value ? activeRef : undefined}
|
||||
type="button"
|
||||
variant="ghost"
|
||||
onClick={() => handleItemChange(item.value)}
|
||||
className={cn(
|
||||
"h-auto shrink-0 gap-2 rounded-full px-3 py-1.5 text-xs font-medium transition-colors focus:outline-none focus-visible:outline-none",
|
||||
activeItem === item.value
|
||||
? "bg-accent text-accent-foreground"
|
||||
: "text-muted-foreground hover:bg-accent hover:text-accent-foreground"
|
||||
)}
|
||||
>
|
||||
{item.icon}
|
||||
{item.label}
|
||||
</Button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Content area */}
|
||||
<div className="flex flex-1 flex-col overflow-hidden min-w-0">
|
||||
<div className="hidden md:block px-8 pt-6 pb-2">
|
||||
<h2 className="text-lg font-semibold">
|
||||
{navItems.find((i) => i.value === activeItem)?.label ?? title}
|
||||
</h2>
|
||||
<Separator className="mt-4" />
|
||||
</div>
|
||||
<div className="flex-1 overflow-y-auto overflow-x-hidden">
|
||||
<div className="px-4 md:px-8 pb-6 pt-4 md:pt-0 min-w-0">{children}</div>
|
||||
</div>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
import { useAtom } from "jotai";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { TeamContent } from "@/app/dashboard/[search_space_id]/team/team-content";
|
||||
import { teamDialogAtom } from "@/atoms/settings/settings-dialog.atoms";
|
||||
import { teamDialogAtom } from "@/atoms/layout/dialogs.atom";
|
||||
import { Dialog, DialogContent, DialogTitle } from "@/components/ui/dialog";
|
||||
|
||||
interface TeamDialogProps {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue