mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-25 00:36:31 +02:00
refactor: replace ModelConfigDialog with a shared component and update related imports for better organization and clarity
This commit is contained in:
parent
f4adfb54fc
commit
d88236d43b
5 changed files with 441 additions and 586 deletions
|
|
@ -12,18 +12,16 @@ import {
|
|||
Trash2,
|
||||
Wand2,
|
||||
} from "lucide-react";
|
||||
import { useCallback, useMemo, useState } from "react";
|
||||
import { useMemo, useState } from "react";
|
||||
import { membersAtom, myAccessAtom } from "@/atoms/members/members-query.atoms";
|
||||
import {
|
||||
createNewLLMConfigMutationAtom,
|
||||
deleteNewLLMConfigMutationAtom,
|
||||
updateNewLLMConfigMutationAtom,
|
||||
} from "@/atoms/new-llm-config/new-llm-config-mutation.atoms";
|
||||
import {
|
||||
globalNewLLMConfigsAtom,
|
||||
newLLMConfigsAtom,
|
||||
} from "@/atoms/new-llm-config/new-llm-config-query.atoms";
|
||||
import { LLMConfigForm, type LLMConfigFormData } from "@/components/shared/llm-config-form";
|
||||
import { ModelConfigDialog } from "@/components/shared/model-config-dialog";
|
||||
import { Alert, AlertDescription } from "@/components/ui/alert";
|
||||
import {
|
||||
AlertDialog,
|
||||
|
|
@ -39,13 +37,6 @@ import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
|||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card, CardContent } from "@/components/ui/card";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from "@/components/ui/dialog";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { Spinner } from "@/components/ui/spinner";
|
||||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip";
|
||||
|
|
@ -69,12 +60,6 @@ function getInitials(name: string): string {
|
|||
export function ModelConfigManager({ searchSpaceId }: ModelConfigManagerProps) {
|
||||
const isDesktop = useMediaQuery("(min-width: 768px)");
|
||||
// Mutations
|
||||
const { mutateAsync: createConfig, isPending: isCreating } = useAtomValue(
|
||||
createNewLLMConfigMutationAtom
|
||||
);
|
||||
const { mutateAsync: updateConfig, isPending: isUpdating } = useAtomValue(
|
||||
updateNewLLMConfigMutationAtom
|
||||
);
|
||||
const { mutateAsync: deleteConfig, isPending: isDeleting } = useAtomValue(
|
||||
deleteNewLLMConfigMutationAtom
|
||||
);
|
||||
|
|
@ -128,29 +113,6 @@ export function ModelConfigManager({ searchSpaceId }: ModelConfigManagerProps) {
|
|||
const [editingConfig, setEditingConfig] = useState<NewLLMConfig | null>(null);
|
||||
const [configToDelete, setConfigToDelete] = useState<NewLLMConfig | null>(null);
|
||||
|
||||
const isSubmitting = isCreating || isUpdating;
|
||||
|
||||
const handleFormSubmit = useCallback(
|
||||
async (formData: LLMConfigFormData) => {
|
||||
try {
|
||||
if (editingConfig) {
|
||||
const { search_space_id, ...updateData } = formData;
|
||||
await updateConfig({
|
||||
id: editingConfig.id,
|
||||
data: updateData,
|
||||
});
|
||||
} else {
|
||||
await createConfig(formData);
|
||||
}
|
||||
setIsDialogOpen(false);
|
||||
setEditingConfig(null);
|
||||
} catch {
|
||||
// Error is displayed inside the dialog by the form
|
||||
}
|
||||
},
|
||||
[editingConfig, createConfig, updateConfig]
|
||||
);
|
||||
|
||||
const handleDelete = async () => {
|
||||
if (!configToDelete) return;
|
||||
try {
|
||||
|
|
@ -171,11 +133,6 @@ export function ModelConfigManager({ searchSpaceId }: ModelConfigManagerProps) {
|
|||
setIsDialogOpen(true);
|
||||
};
|
||||
|
||||
const closeDialog = () => {
|
||||
setIsDialogOpen(false);
|
||||
setEditingConfig(null);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-5 md:space-y-6">
|
||||
{/* Header actions */}
|
||||
|
|
@ -457,54 +414,17 @@ export function ModelConfigManager({ searchSpaceId }: ModelConfigManagerProps) {
|
|||
)}
|
||||
|
||||
{/* Add/Edit Configuration Dialog */}
|
||||
<Dialog open={isDialogOpen} onOpenChange={(open) => !open && closeDialog()}>
|
||||
<DialogContent
|
||||
className="max-w-2xl max-h-[90vh] overflow-y-auto"
|
||||
onOpenAutoFocus={(e) => e.preventDefault()}
|
||||
>
|
||||
<DialogHeader>
|
||||
<DialogTitle>
|
||||
{editingConfig ? "Edit Configuration" : "Create New Configuration"}
|
||||
</DialogTitle>
|
||||
<DialogDescription>
|
||||
{editingConfig
|
||||
? "Update your AI model and prompt configuration"
|
||||
: "Set up a new AI model with custom prompts and citation settings"}
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
<LLMConfigForm
|
||||
key={editingConfig ? `edit-${editingConfig.id}` : "create"}
|
||||
searchSpaceId={searchSpaceId}
|
||||
initialData={
|
||||
editingConfig
|
||||
? {
|
||||
name: editingConfig.name,
|
||||
description: editingConfig.description || "",
|
||||
provider: editingConfig.provider,
|
||||
custom_provider: editingConfig.custom_provider || "",
|
||||
model_name: editingConfig.model_name,
|
||||
api_key: editingConfig.api_key,
|
||||
api_base: editingConfig.api_base || "",
|
||||
litellm_params: editingConfig.litellm_params || {},
|
||||
system_instructions: editingConfig.system_instructions || "",
|
||||
use_default_system_instructions: editingConfig.use_default_system_instructions,
|
||||
citations_enabled: editingConfig.citations_enabled,
|
||||
}
|
||||
: {
|
||||
citations_enabled: true,
|
||||
use_default_system_instructions: true,
|
||||
}
|
||||
}
|
||||
onSubmit={handleFormSubmit}
|
||||
onCancel={closeDialog}
|
||||
isSubmitting={isSubmitting}
|
||||
mode={editingConfig ? "edit" : "create"}
|
||||
showAdvanced={true}
|
||||
compact={true}
|
||||
/>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
<ModelConfigDialog
|
||||
open={isDialogOpen}
|
||||
onOpenChange={(open) => {
|
||||
setIsDialogOpen(open);
|
||||
if (!open) setEditingConfig(null);
|
||||
}}
|
||||
config={editingConfig}
|
||||
isGlobal={false}
|
||||
searchSpaceId={searchSpaceId}
|
||||
mode={editingConfig ? "edit" : "create"}
|
||||
/>
|
||||
|
||||
{/* Delete Confirmation Dialog */}
|
||||
<AlertDialog
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue