-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(frontend): more datasource support
- Loading branch information
Showing
9 changed files
with
346 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
frontend/app/src/app/(main)/(admin)/datasources/create/web-single-page/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
'use client'; | ||
|
||
import { type BaseCreateDatasourceParams, createDatasource } from '@/api/datasources'; | ||
import { Button } from '@/components/ui/button'; | ||
import { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage } from '@/components/ui/form'; | ||
import { Input } from '@/components/ui/input'; | ||
import { Separator } from '@/components/ui/separator'; | ||
import { Switch } from '@/components/ui/switch'; | ||
import { zodResolver } from '@hookform/resolvers/zod'; | ||
import { Loader2Icon } from 'lucide-react'; | ||
import { useRouter } from 'next/navigation'; | ||
import { useTransition } from 'react'; | ||
import { useForm } from 'react-hook-form'; | ||
import { z, type ZodType } from 'zod'; | ||
|
||
const schema = z.object({ | ||
name: z.string(), | ||
description: z.string(), | ||
build_kg_index: z.boolean(), | ||
url: z.string().url(), | ||
}) satisfies ZodType<BaseCreateDatasourceParams, any, any>; | ||
|
||
export default function Page () { | ||
const [navigating, startNavigation] = useTransition(); | ||
const router = useRouter(); | ||
const form = useForm({ | ||
resolver: zodResolver(schema), | ||
defaultValues: { | ||
name: '', | ||
description: '', | ||
build_kg_index: false, | ||
url: '', | ||
}, | ||
}); | ||
|
||
const handleSubmit = form.handleSubmit(async ({ url, ...data }) => { | ||
const createdDatasource = await createDatasource({ | ||
...data, | ||
data_source_type: 'web_single_page', | ||
config: { url }, | ||
}); | ||
startNavigation(() => { | ||
router.push(`/datasources/${createdDatasource.id}`); | ||
}); | ||
}); | ||
|
||
return ( | ||
<Form {...form}> | ||
<form id="create-datasource-form" className="space-y-4" onSubmit={handleSubmit}> | ||
<FormField | ||
name="name" | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormLabel>Name</FormLabel> | ||
<FormControl> | ||
<Input {...field} /> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
<FormField | ||
name="description" | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormLabel>Description</FormLabel> | ||
<FormControl> | ||
<Input {...field} /> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
<FormField | ||
name="url" | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormLabel>URL</FormLabel> | ||
<FormControl> | ||
<Input {...field} /> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
</form> | ||
<div className="mt-4 space-y-4"> | ||
<Separator /> | ||
<FormField | ||
name="build_kg_index" | ||
render={({ field }) => ( | ||
<FormItem className="rounded-lg border p-4 flex items-center justify-between text-sky-500 bg-sky-500/5 border-sky-500/30"> | ||
<div className="space-y-2"> | ||
<FormLabel>Build KnowledgeGraph Index</FormLabel> | ||
<FormDescription className="text-sky-500/70"> | ||
Enable to build knowledge graph index. | ||
</FormDescription> | ||
</div> | ||
<FormControl> | ||
<Switch {...field} onChange={undefined} checked={field.value} onCheckedChange={field.onChange} /> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
<Button type="submit" disabled={navigating || form.formState.isSubmitting} className="gap-2" form="create-datasource-form"> | ||
{(navigating || form.formState.isSubmitting) && <Loader2Icon className="size-4 animate-spin repeat-infinite" />} | ||
<span>Create</span> | ||
</Button> | ||
</div> | ||
</Form> | ||
); | ||
} |
Oops, something went wrong.