balibabu commited on
Commit
e64a1ed
·
1 Parent(s): ccfdde3

Feat: Add DatasetCreatingDialog #3221 (#4313)

Browse files

### What problem does this PR solve?

Feat: Add DatasetCreatingDialog #3221

### Type of change


- [x] New Feature (non-breaking change which adds functionality)

web/src/components/list-filter-bar.tsx CHANGED
@@ -4,11 +4,13 @@ import { Button } from './ui/button';
4
 
5
  interface IProps {
6
  title: string;
 
7
  }
8
 
9
  export default function ListFilterBar({
10
  title,
11
  children,
 
12
  }: PropsWithChildren<IProps>) {
13
  return (
14
  <div className="flex justify-between mb-6">
@@ -16,7 +18,7 @@ export default function ListFilterBar({
16
  <div className="flex gap-4 items-center">
17
  <Filter className="size-5" />
18
  <Search className="size-5" />
19
- <Button variant={'tertiary'} size={'sm'}>
20
  {children}
21
  </Button>
22
  </div>
 
4
 
5
  interface IProps {
6
  title: string;
7
+ showDialog?: () => void;
8
  }
9
 
10
  export default function ListFilterBar({
11
  title,
12
  children,
13
+ showDialog,
14
  }: PropsWithChildren<IProps>) {
15
  return (
16
  <div className="flex justify-between mb-6">
 
18
  <div className="flex gap-4 items-center">
19
  <Filter className="size-5" />
20
  <Search className="size-5" />
21
+ <Button variant={'tertiary'} size={'sm'} onClick={showDialog}>
22
  {children}
23
  </Button>
24
  </div>
web/src/components/rename-dialog/index.tsx ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { Button } from '@/components/ui/button';
2
+ import {
3
+ Dialog,
4
+ DialogContent,
5
+ DialogDescription,
6
+ DialogFooter,
7
+ DialogHeader,
8
+ DialogTitle,
9
+ DialogTrigger,
10
+ } from '@/components/ui/dialog';
11
+ import { Input } from '@/components/ui/input';
12
+ import { Label } from '@/components/ui/label';
13
+
14
+ export function DialogDemo() {
15
+ return (
16
+ <Dialog>
17
+ <DialogTrigger asChild>
18
+ <Button variant="outline">Edit Profile</Button>
19
+ </DialogTrigger>
20
+ <DialogContent className="sm:max-w-[425px]">
21
+ <DialogHeader>
22
+ <DialogTitle>Edit profile</DialogTitle>
23
+ <DialogDescription>
24
+ Make changes to your profile here. Click save when you're done.
25
+ </DialogDescription>
26
+ </DialogHeader>
27
+ <div className="grid gap-4 py-4">
28
+ <div className="grid grid-cols-4 items-center gap-4">
29
+ <Label htmlFor="name" className="text-right">
30
+ Name
31
+ </Label>
32
+ <Input
33
+ id="name"
34
+ defaultValue="Pedro Duarte"
35
+ className="col-span-3"
36
+ />
37
+ </div>
38
+ <div className="grid grid-cols-4 items-center gap-4">
39
+ <Label htmlFor="username" className="text-right">
40
+ Username
41
+ </Label>
42
+ <Input
43
+ id="username"
44
+ defaultValue="@peduarte"
45
+ className="col-span-3"
46
+ />
47
+ </div>
48
+ </div>
49
+ <DialogFooter>
50
+ <Button type="submit">Save changes</Button>
51
+ </DialogFooter>
52
+ </DialogContent>
53
+ </Dialog>
54
+ );
55
+ }
web/src/components/ui/dialog.tsx CHANGED
@@ -38,7 +38,7 @@ const DialogContent = React.forwardRef<
38
  <DialogPrimitive.Content
39
  ref={ref}
40
  className={cn(
41
- 'fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg',
42
  className,
43
  )}
44
  {...props}
 
38
  <DialogPrimitive.Content
39
  ref={ref}
40
  className={cn(
41
+ 'fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-colors-background-neutral-standard p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg',
42
  className,
43
  )}
44
  {...props}
web/src/components/ui/input.tsx CHANGED
@@ -11,7 +11,7 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(
11
  <input
12
  type={type}
13
  className={cn(
14
- 'flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50',
15
  className,
16
  )}
17
  ref={ref}
 
11
  <input
12
  type={type}
13
  className={cn(
14
+ 'flex h-10 w-full rounded-md border border-input bg-colors-background-inverse-weak px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50',
15
  className,
16
  )}
17
  ref={ref}
web/src/components/ui/select.tsx CHANGED
@@ -19,7 +19,7 @@ const SelectTrigger = React.forwardRef<
19
  <SelectPrimitive.Trigger
20
  ref={ref}
21
  className={cn(
22
- 'flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1',
23
  className,
24
  )}
25
  {...props}
 
19
  <SelectPrimitive.Trigger
20
  ref={ref}
21
  className={cn(
22
+ 'flex h-10 w-full items-center justify-between rounded-md border border-input bg-colors-background-inverse-weak px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1',
23
  className,
24
  )}
25
  {...props}
web/src/components/ui/textarea.tsx CHANGED
@@ -9,7 +9,7 @@ const Textarea = React.forwardRef<
9
  return (
10
  <textarea
11
  className={cn(
12
- 'flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm',
13
  className,
14
  )}
15
  ref={ref}
 
9
  return (
10
  <textarea
11
  className={cn(
12
+ 'flex min-h-[80px] w-full rounded-md border border-input bg-colors-background-inverse-weak px-3 py-2 text-base ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm',
13
  className,
14
  )}
15
  ref={ref}
web/src/pages/dataset/setting/advanced-setting-form.tsx CHANGED
@@ -99,7 +99,7 @@ export default function AdvancedSettingForm() {
99
  <FormLabel>Username</FormLabel>
100
  <Select onValueChange={field.onChange} defaultValue={field.value}>
101
  <FormControl>
102
- <SelectTrigger className="bg-colors-background-inverse-weak">
103
  <SelectValue placeholder="Select a verified email to display" />
104
  </SelectTrigger>
105
  </FormControl>
@@ -139,10 +139,7 @@ export default function AdvancedSettingForm() {
139
  <FormItem className="w-2/5">
140
  <FormLabel>Username</FormLabel>
141
  <FormControl>
142
- <Textarea
143
- {...field}
144
- className="bg-colors-background-inverse-weak"
145
- ></Textarea>
146
  </FormControl>
147
  <FormDescription>
148
  This is your public display name.
 
99
  <FormLabel>Username</FormLabel>
100
  <Select onValueChange={field.onChange} defaultValue={field.value}>
101
  <FormControl>
102
+ <SelectTrigger>
103
  <SelectValue placeholder="Select a verified email to display" />
104
  </SelectTrigger>
105
  </FormControl>
 
139
  <FormItem className="w-2/5">
140
  <FormLabel>Username</FormLabel>
141
  <FormControl>
142
+ <Textarea {...field}></Textarea>
 
 
 
143
  </FormControl>
144
  <FormDescription>
145
  This is your public display name.
web/src/pages/dataset/setting/basic-setting-form.tsx CHANGED
@@ -78,10 +78,7 @@ export default function BasicSettingForm() {
78
  <FormItem>
79
  <FormLabel>{t('name')}</FormLabel>
80
  <FormControl>
81
- <Input
82
- {...field}
83
- className="bg-colors-background-inverse-weak"
84
- ></Input>
85
  </FormControl>
86
  <FormMessage />
87
  </FormItem>
@@ -94,10 +91,7 @@ export default function BasicSettingForm() {
94
  <FormItem>
95
  <FormLabel>Username</FormLabel>
96
  <FormControl>
97
- <Input
98
- {...field}
99
- className="bg-colors-background-inverse-weak"
100
- ></Input>
101
  </FormControl>
102
  <FormMessage />
103
  </FormItem>
@@ -111,7 +105,7 @@ export default function BasicSettingForm() {
111
  <FormLabel>{t('language')}</FormLabel>
112
  <Select onValueChange={field.onChange} defaultValue={field.value}>
113
  <FormControl>
114
- <SelectTrigger className="bg-colors-background-inverse-weak">
115
  <SelectValue placeholder="Select a verified email to display" />
116
  </SelectTrigger>
117
  </FormControl>
 
78
  <FormItem>
79
  <FormLabel>{t('name')}</FormLabel>
80
  <FormControl>
81
+ <Input {...field}></Input>
 
 
 
82
  </FormControl>
83
  <FormMessage />
84
  </FormItem>
 
91
  <FormItem>
92
  <FormLabel>Username</FormLabel>
93
  <FormControl>
94
+ <Input {...field}></Input>
 
 
 
95
  </FormControl>
96
  <FormMessage />
97
  </FormItem>
 
105
  <FormLabel>{t('language')}</FormLabel>
106
  <Select onValueChange={field.onChange} defaultValue={field.value}>
107
  <FormControl>
108
+ <SelectTrigger>
109
  <SelectValue placeholder="Select a verified email to display" />
110
  </SelectTrigger>
111
  </FormControl>
web/src/pages/datasets/dataset-creating-dialog.tsx ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { Button } from '@/components/ui/button';
2
+ import {
3
+ Dialog,
4
+ DialogContent,
5
+ DialogFooter,
6
+ DialogHeader,
7
+ DialogTitle,
8
+ } from '@/components/ui/dialog';
9
+ import {
10
+ Form,
11
+ FormControl,
12
+ FormField,
13
+ FormItem,
14
+ FormLabel,
15
+ FormMessage,
16
+ } from '@/components/ui/form';
17
+ import { Input } from '@/components/ui/input';
18
+ import { IModalProps } from '@/interfaces/common';
19
+ import { zodResolver } from '@hookform/resolvers/zod';
20
+ import { useForm } from 'react-hook-form';
21
+ import { useTranslation } from 'react-i18next';
22
+ import { z } from 'zod';
23
+
24
+ const FormId = 'dataset-creating-form';
25
+
26
+ export function InputForm() {
27
+ const { t } = useTranslation();
28
+
29
+ const FormSchema = z.object({
30
+ name: z
31
+ .string()
32
+ .min(1, {
33
+ message: t('knowledgeList.namePlaceholder'),
34
+ })
35
+ .trim(),
36
+ });
37
+
38
+ const form = useForm<z.infer<typeof FormSchema>>({
39
+ resolver: zodResolver(FormSchema),
40
+ defaultValues: {
41
+ name: '',
42
+ },
43
+ });
44
+
45
+ function onSubmit(data: z.infer<typeof FormSchema>) {
46
+ console.log('🚀 ~ onSubmit ~ data:', data);
47
+ }
48
+
49
+ return (
50
+ <Form {...form}>
51
+ <form
52
+ onSubmit={form.handleSubmit(onSubmit)}
53
+ className="w-2/3 space-y-6"
54
+ id={FormId}
55
+ >
56
+ <FormField
57
+ control={form.control}
58
+ name="name"
59
+ render={({ field }) => (
60
+ <FormItem>
61
+ <FormLabel>{t('knowledgeList.name')}</FormLabel>
62
+ <FormControl>
63
+ <Input
64
+ placeholder={t('knowledgeList.namePlaceholder')}
65
+ {...field}
66
+ />
67
+ </FormControl>
68
+ <FormMessage />
69
+ </FormItem>
70
+ )}
71
+ />
72
+ </form>
73
+ </Form>
74
+ );
75
+ }
76
+
77
+ export function DatasetCreatingDialog({ hideModal }: IModalProps<any>) {
78
+ const { t } = useTranslation();
79
+
80
+ return (
81
+ <Dialog open onOpenChange={hideModal}>
82
+ <DialogContent className="sm:max-w-[425px]">
83
+ <DialogHeader>
84
+ <DialogTitle>{t('knowledgeList.createKnowledgeBase')}</DialogTitle>
85
+ </DialogHeader>
86
+ <InputForm></InputForm>
87
+ <DialogFooter>
88
+ <Button type="submit" variant={'tertiary'} size={'sm'} form={FormId}>
89
+ {t('common.save')}
90
+ </Button>
91
+ </DialogFooter>
92
+ </DialogContent>
93
+ </Dialog>
94
+ );
95
+ }
web/src/pages/datasets/hooks.ts ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { KnowledgeRouteKey } from '@/constants/knowledge';
2
+ import { useSetModalState } from '@/hooks/common-hooks';
3
+ import { useCreateKnowledge } from '@/hooks/knowledge-hooks';
4
+ import { useCallback, useState } from 'react';
5
+ import { useNavigate } from 'umi';
6
+
7
+ export const useSearchKnowledge = () => {
8
+ const [searchString, setSearchString] = useState<string>('');
9
+
10
+ const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
11
+ setSearchString(e.target.value);
12
+ };
13
+ return {
14
+ searchString,
15
+ handleInputChange,
16
+ };
17
+ };
18
+
19
+ export const useSaveKnowledge = () => {
20
+ const { visible: visible, hideModal, showModal } = useSetModalState();
21
+ const { loading, createKnowledge } = useCreateKnowledge();
22
+ const navigate = useNavigate();
23
+
24
+ const onCreateOk = useCallback(
25
+ async (name: string) => {
26
+ const ret = await createKnowledge({
27
+ name,
28
+ });
29
+
30
+ if (ret?.code === 0) {
31
+ hideModal();
32
+ navigate(
33
+ `/knowledge/${KnowledgeRouteKey.Configuration}?id=${ret.data.kb_id}`,
34
+ );
35
+ }
36
+ },
37
+ [createKnowledge, hideModal, navigate],
38
+ );
39
+
40
+ return {
41
+ loading,
42
+ onCreateOk,
43
+ visible,
44
+ hideModal,
45
+ showModal,
46
+ };
47
+ };
web/src/pages/datasets/index.tsx CHANGED
@@ -2,6 +2,8 @@ import ListFilterBar from '@/components/list-filter-bar';
2
  import { Button } from '@/components/ui/button';
3
  import { Card, CardContent } from '@/components/ui/card';
4
  import { ChevronRight, MoreHorizontal, Plus } from 'lucide-react';
 
 
5
 
6
  const datasets = [
7
  {
@@ -79,9 +81,16 @@ const datasets = [
79
  ];
80
 
81
  export default function Datasets() {
 
 
 
 
 
 
 
82
  return (
83
  <section className="p-8 text-foreground">
84
- <ListFilterBar title="Datasets">
85
  <Plus className="mr-2 h-4 w-4" />
86
  Create dataset
87
  </ListFilterBar>
@@ -121,6 +130,13 @@ export default function Datasets() {
121
  </Card>
122
  ))}
123
  </div>
 
 
 
 
 
 
 
124
  </section>
125
  );
126
  }
 
2
  import { Button } from '@/components/ui/button';
3
  import { Card, CardContent } from '@/components/ui/card';
4
  import { ChevronRight, MoreHorizontal, Plus } from 'lucide-react';
5
+ import { DatasetCreatingDialog } from './dataset-creating-dialog';
6
+ import { useSaveKnowledge } from './hooks';
7
 
8
  const datasets = [
9
  {
 
81
  ];
82
 
83
  export default function Datasets() {
84
+ const {
85
+ visible,
86
+ hideModal,
87
+ showModal,
88
+ onCreateOk,
89
+ loading: creatingLoading,
90
+ } = useSaveKnowledge();
91
  return (
92
  <section className="p-8 text-foreground">
93
+ <ListFilterBar title="Datasets" showDialog={showModal}>
94
  <Plus className="mr-2 h-4 w-4" />
95
  Create dataset
96
  </ListFilterBar>
 
130
  </Card>
131
  ))}
132
  </div>
133
+ {visible && (
134
+ <DatasetCreatingDialog
135
+ hideModal={hideModal}
136
+ onOk={onCreateOk}
137
+ loading={creatingLoading}
138
+ ></DatasetCreatingDialog>
139
+ )}
140
  </section>
141
  );
142
  }
web/src/pages/profile-setting/model/model-card.tsx CHANGED
@@ -62,7 +62,7 @@ export function SystemModelSetting() {
62
  </div>
63
  <div className="flex-1">
64
  <Select defaultValue="english">
65
- <SelectTrigger className="bg-colors-background-inverse-weak">
66
  <SelectValue />
67
  </SelectTrigger>
68
  <SelectContent>
 
62
  </div>
63
  <div className="flex-1">
64
  <Select defaultValue="english">
65
+ <SelectTrigger>
66
  <SelectValue />
67
  </SelectTrigger>
68
  <SelectContent>
web/src/pages/profile-setting/profile/index.tsx CHANGED
@@ -26,24 +26,18 @@ export default function Profile() {
26
  <div className="space-y-6 max-w-[600px]">
27
  <div className="space-y-2">
28
  <label className="text-sm text-muted-foreground">User name</label>
29
- <Input
30
- defaultValue="yifanwu92"
31
- className="bg-colors-background-inverse-weak"
32
- />
33
  </div>
34
 
35
  <div className="space-y-2">
36
  <label className="text-sm text-muted-foreground">Email</label>
37
- <Input
38
- defaultValue="yifanwu92@gmail.com"
39
- className="bg-colors-background-inverse-weak"
40
- />
41
  </div>
42
 
43
  <div className="space-y-2">
44
  <label className="text-sm text-muted-foreground">Language</label>
45
  <Select defaultValue="english">
46
- <SelectTrigger className="bg-colors-background-inverse-weak">
47
  <SelectValue />
48
  </SelectTrigger>
49
  <SelectContent>
@@ -55,7 +49,7 @@ export default function Profile() {
55
  <div className="space-y-2">
56
  <label className="text-sm text-muted-foreground">Timezone</label>
57
  <Select defaultValue="utc9">
58
- <SelectTrigger className="bg-colors-background-inverse-weak">
59
  <SelectValue />
60
  </SelectTrigger>
61
  <SelectContent>
 
26
  <div className="space-y-6 max-w-[600px]">
27
  <div className="space-y-2">
28
  <label className="text-sm text-muted-foreground">User name</label>
29
+ <Input defaultValue="yifanwu92" />
 
 
 
30
  </div>
31
 
32
  <div className="space-y-2">
33
  <label className="text-sm text-muted-foreground">Email</label>
34
+ <Input defaultValue="yifanwu92@gmail.com" />
 
 
 
35
  </div>
36
 
37
  <div className="space-y-2">
38
  <label className="text-sm text-muted-foreground">Language</label>
39
  <Select defaultValue="english">
40
+ <SelectTrigger>
41
  <SelectValue />
42
  </SelectTrigger>
43
  <SelectContent>
 
49
  <div className="space-y-2">
50
  <label className="text-sm text-muted-foreground">Timezone</label>
51
  <Select defaultValue="utc9">
52
+ <SelectTrigger>
53
  <SelectValue />
54
  </SelectTrigger>
55
  <SelectContent>
web/tailwind.config.js CHANGED
@@ -19,7 +19,7 @@ module.exports = {
19
  },
20
  extend: {
21
  colors: {
22
- border: 'hsl(var(--border))',
23
  input: 'hsl(var(--input))',
24
  ring: 'hsl(var(--ring))',
25
  background: 'var(--background)',
 
19
  },
20
  extend: {
21
  colors: {
22
+ border: 'var(--colors-outline-neutral-strong)',
23
  input: 'hsl(var(--input))',
24
  ring: 'hsl(var(--ring))',
25
  background: 'var(--background)',
web/tailwind.css CHANGED
@@ -40,6 +40,7 @@
40
  --colors-background-inverse-standard: rgba(29, 26, 44, 0.1);
41
  --colors-background-inverse-strong: rgba(11, 10, 18, 0.8);
42
  --colors-background-inverse-weak: rgba(17, 16, 23, 0.1);
 
43
 
44
  --button-blue-text: rgb(22, 119, 255);
45
 
 
40
  --colors-background-inverse-standard: rgba(29, 26, 44, 0.1);
41
  --colors-background-inverse-strong: rgba(11, 10, 18, 0.8);
42
  --colors-background-inverse-weak: rgba(17, 16, 23, 0.1);
43
+ --colors-background-neutral-standard: white;
44
 
45
  --button-blue-text: rgb(22, 119, 255);
46