balibabu
commited on
Commit
·
1f55425
1
Parent(s):
7308200
Feat: Add LinkToDatasetDialog #3221 (#4500)
Browse files### What problem does this PR solve?
Feat: Add LinkToDatasetDialog #3221
### Type of change
- [x] New Feature (non-breaking change which adds functionality)
- web/src/components/ui/badge.tsx +1 -1
- web/src/components/ui/button.tsx +2 -1
- web/src/components/ui/loading-button.tsx +2 -0
- web/src/hooks/knowledge-hooks.ts +11 -0
- web/src/pages/files/action-cell.tsx +61 -0
- web/src/pages/files/files-table.tsx +45 -42
- web/src/pages/files/hooks.ts +5 -1
- web/src/pages/files/link-to-dataset-dialog.tsx +130 -0
- web/tailwind.config.js +5 -0
- web/tailwind.css +5 -0
web/src/components/ui/badge.tsx
CHANGED
|
@@ -16,7 +16,7 @@ const badgeVariants = cva(
|
|
| 16 |
'border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80',
|
| 17 |
outline: 'text-foreground',
|
| 18 |
tertiary:
|
| 19 |
-
'border-transparent bg-colors-
|
| 20 |
},
|
| 21 |
},
|
| 22 |
defaultVariants: {
|
|
|
|
| 16 |
'border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80',
|
| 17 |
outline: 'text-foreground',
|
| 18 |
tertiary:
|
| 19 |
+
'border-transparent bg-colors-background-core-strong text-colors-text-persist-light hover:bg-colors-background-core-strong/80',
|
| 20 |
},
|
| 21 |
},
|
| 22 |
defaultVariants: {
|
web/src/components/ui/button.tsx
CHANGED
|
@@ -19,7 +19,7 @@ const buttonVariants = cva(
|
|
| 19 |
ghost: 'hover:bg-accent hover:text-accent-foreground',
|
| 20 |
link: 'text-primary underline-offset-4 hover:underline',
|
| 21 |
tertiary:
|
| 22 |
-
'bg-colors-
|
| 23 |
icon: 'bg-colors-background-inverse-standard text-foreground hover:bg-colors-background-inverse-standard/80',
|
| 24 |
},
|
| 25 |
size: {
|
|
@@ -27,6 +27,7 @@ const buttonVariants = cva(
|
|
| 27 |
sm: 'h-9 rounded-md px-3',
|
| 28 |
lg: 'h-11 rounded-md px-8',
|
| 29 |
icon: 'h-10 w-10',
|
|
|
|
| 30 |
},
|
| 31 |
},
|
| 32 |
defaultVariants: {
|
|
|
|
| 19 |
ghost: 'hover:bg-accent hover:text-accent-foreground',
|
| 20 |
link: 'text-primary underline-offset-4 hover:underline',
|
| 21 |
tertiary:
|
| 22 |
+
'bg-colors-background-sentiment-solid-primary text-colors-text-persist-light hover:bg-colors-background-sentiment-solid-primary/80',
|
| 23 |
icon: 'bg-colors-background-inverse-standard text-foreground hover:bg-colors-background-inverse-standard/80',
|
| 24 |
},
|
| 25 |
size: {
|
|
|
|
| 27 |
sm: 'h-9 rounded-md px-3',
|
| 28 |
lg: 'h-11 rounded-md px-8',
|
| 29 |
icon: 'h-10 w-10',
|
| 30 |
+
auto: 'h-full px-1',
|
| 31 |
},
|
| 32 |
},
|
| 33 |
defaultVariants: {
|
web/src/components/ui/loading-button.tsx
CHANGED
|
@@ -20,6 +20,8 @@ const buttonVariants = cva(
|
|
| 20 |
'bg-secondary text-secondary-foreground hover:bg-secondary/80',
|
| 21 |
ghost: 'hover:bg-accent hover:text-accent-foreground',
|
| 22 |
link: 'text-primary underline-offset-4 hover:underline',
|
|
|
|
|
|
|
| 23 |
},
|
| 24 |
size: {
|
| 25 |
default: 'h-10 px-4 py-2',
|
|
|
|
| 20 |
'bg-secondary text-secondary-foreground hover:bg-secondary/80',
|
| 21 |
ghost: 'hover:bg-accent hover:text-accent-foreground',
|
| 22 |
link: 'text-primary underline-offset-4 hover:underline',
|
| 23 |
+
tertiary:
|
| 24 |
+
'bg-colors-background-sentiment-solid-primary text-colors-text-persist-light hover:bg-colors-background-sentiment-solid-primary/80',
|
| 25 |
},
|
| 26 |
size: {
|
| 27 |
default: 'h-10 px-4 py-2',
|
web/src/hooks/knowledge-hooks.ts
CHANGED
|
@@ -72,6 +72,17 @@ export const useFetchKnowledgeList = (
|
|
| 72 |
return { list: data, loading };
|
| 73 |
};
|
| 74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
export const useInfiniteFetchKnowledgeList = () => {
|
| 76 |
const { searchString, handleInputChange } = useHandleSearchChange();
|
| 77 |
const debouncedSearchString = useDebounce(searchString, { wait: 500 });
|
|
|
|
| 72 |
return { list: data, loading };
|
| 73 |
};
|
| 74 |
|
| 75 |
+
export const useSelectKnowledgeOptions = () => {
|
| 76 |
+
const { list } = useFetchKnowledgeList();
|
| 77 |
+
|
| 78 |
+
const options = list?.map((item) => ({
|
| 79 |
+
label: item.name,
|
| 80 |
+
value: item.id,
|
| 81 |
+
}));
|
| 82 |
+
|
| 83 |
+
return options;
|
| 84 |
+
};
|
| 85 |
+
|
| 86 |
export const useInfiniteFetchKnowledgeList = () => {
|
| 87 |
const { searchString, handleInputChange } = useHandleSearchChange();
|
| 88 |
const debouncedSearchString = useDebounce(searchString, { wait: 500 });
|
web/src/pages/files/action-cell.tsx
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { ConfirmDeleteDialog } from '@/components/confirm-delete-dialog';
|
| 2 |
+
import { Button } from '@/components/ui/button';
|
| 3 |
+
import {
|
| 4 |
+
DropdownMenu,
|
| 5 |
+
DropdownMenuContent,
|
| 6 |
+
DropdownMenuItem,
|
| 7 |
+
DropdownMenuLabel,
|
| 8 |
+
DropdownMenuSeparator,
|
| 9 |
+
DropdownMenuTrigger,
|
| 10 |
+
} from '@/components/ui/dropdown-menu';
|
| 11 |
+
import { IFile } from '@/interfaces/database/file-manager';
|
| 12 |
+
import { CellContext } from '@tanstack/react-table';
|
| 13 |
+
import { EllipsisVertical, Link2, Trash2 } from 'lucide-react';
|
| 14 |
+
import { useCallback } from 'react';
|
| 15 |
+
import { UseHandleConnectToKnowledgeReturnType } from './hooks';
|
| 16 |
+
|
| 17 |
+
type IProps = Pick<CellContext<IFile, unknown>, 'row'> &
|
| 18 |
+
Pick<UseHandleConnectToKnowledgeReturnType, 'showConnectToKnowledgeModal'>;
|
| 19 |
+
|
| 20 |
+
export function ActionCell({ row, showConnectToKnowledgeModal }: IProps) {
|
| 21 |
+
const record = row.original;
|
| 22 |
+
|
| 23 |
+
const handleShowConnectToKnowledgeModal = useCallback(() => {
|
| 24 |
+
showConnectToKnowledgeModal(record);
|
| 25 |
+
}, [record, showConnectToKnowledgeModal]);
|
| 26 |
+
|
| 27 |
+
return (
|
| 28 |
+
<section className="flex gap-4 items-center">
|
| 29 |
+
<Button
|
| 30 |
+
variant="secondary"
|
| 31 |
+
size={'icon'}
|
| 32 |
+
onClick={handleShowConnectToKnowledgeModal}
|
| 33 |
+
>
|
| 34 |
+
<Link2 />
|
| 35 |
+
</Button>
|
| 36 |
+
<ConfirmDeleteDialog>
|
| 37 |
+
<Button variant="secondary" size={'icon'}>
|
| 38 |
+
<Trash2 />
|
| 39 |
+
</Button>
|
| 40 |
+
</ConfirmDeleteDialog>
|
| 41 |
+
<DropdownMenu>
|
| 42 |
+
<DropdownMenuTrigger asChild>
|
| 43 |
+
<Button variant="secondary" size={'icon'}>
|
| 44 |
+
<EllipsisVertical />
|
| 45 |
+
</Button>
|
| 46 |
+
</DropdownMenuTrigger>
|
| 47 |
+
<DropdownMenuContent align="end">
|
| 48 |
+
<DropdownMenuLabel>Actions</DropdownMenuLabel>
|
| 49 |
+
<DropdownMenuItem
|
| 50 |
+
onClick={() => navigator.clipboard.writeText(record.id)}
|
| 51 |
+
>
|
| 52 |
+
Copy payment ID
|
| 53 |
+
</DropdownMenuItem>
|
| 54 |
+
<DropdownMenuSeparator />
|
| 55 |
+
<DropdownMenuItem>View customer</DropdownMenuItem>
|
| 56 |
+
<DropdownMenuItem>View payment details</DropdownMenuItem>
|
| 57 |
+
</DropdownMenuContent>
|
| 58 |
+
</DropdownMenu>
|
| 59 |
+
</section>
|
| 60 |
+
);
|
| 61 |
+
}
|
web/src/pages/files/files-table.tsx
CHANGED
|
@@ -11,22 +11,14 @@ import {
|
|
| 11 |
getSortedRowModel,
|
| 12 |
useReactTable,
|
| 13 |
} from '@tanstack/react-table';
|
| 14 |
-
import { ArrowUpDown
|
| 15 |
import * as React from 'react';
|
| 16 |
|
| 17 |
import SvgIcon from '@/components/svg-icon';
|
| 18 |
import { TableEmpty, TableSkeleton } from '@/components/table-skeleton';
|
|
|
|
| 19 |
import { Button } from '@/components/ui/button';
|
| 20 |
import { Checkbox } from '@/components/ui/checkbox';
|
| 21 |
-
import {
|
| 22 |
-
DropdownMenu,
|
| 23 |
-
DropdownMenuContent,
|
| 24 |
-
DropdownMenuItem,
|
| 25 |
-
DropdownMenuLabel,
|
| 26 |
-
DropdownMenuSeparator,
|
| 27 |
-
DropdownMenuTrigger,
|
| 28 |
-
} from '@/components/ui/dropdown-menu';
|
| 29 |
-
import { Switch } from '@/components/ui/switch';
|
| 30 |
import {
|
| 31 |
Table,
|
| 32 |
TableBody,
|
|
@@ -48,7 +40,9 @@ import { formatDate } from '@/utils/date';
|
|
| 48 |
import { getExtension } from '@/utils/document-util';
|
| 49 |
import { useMemo } from 'react';
|
| 50 |
import { useTranslation } from 'react-i18next';
|
| 51 |
-
import {
|
|
|
|
|
|
|
| 52 |
|
| 53 |
export function FilesTable() {
|
| 54 |
const [sorting, setSorting] = React.useState<SortingState>([]);
|
|
@@ -62,6 +56,14 @@ export function FilesTable() {
|
|
| 62 |
keyPrefix: 'fileManager',
|
| 63 |
});
|
| 64 |
const navigateToOtherFolder = useNavigateToOtherFolder();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
const { pagination, data, loading, setPagination } = useFetchFileList();
|
| 67 |
|
|
@@ -176,44 +178,37 @@ export function FilesTable() {
|
|
| 176 |
{
|
| 177 |
accessorKey: 'kbs_info',
|
| 178 |
header: t('knowledgeBase'),
|
| 179 |
-
cell: ({ row }) =>
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
},
|
| 185 |
{
|
| 186 |
id: 'actions',
|
| 187 |
header: t('action'),
|
| 188 |
enableHiding: false,
|
| 189 |
cell: ({ row }) => {
|
| 190 |
-
const payment = row.original;
|
| 191 |
-
|
| 192 |
return (
|
| 193 |
-
<
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
</Button>
|
| 198 |
-
<DropdownMenu>
|
| 199 |
-
<DropdownMenuTrigger asChild>
|
| 200 |
-
<Button variant="secondary" size={'icon'}>
|
| 201 |
-
<MoreHorizontal />
|
| 202 |
-
</Button>
|
| 203 |
-
</DropdownMenuTrigger>
|
| 204 |
-
<DropdownMenuContent align="end">
|
| 205 |
-
<DropdownMenuLabel>Actions</DropdownMenuLabel>
|
| 206 |
-
<DropdownMenuItem
|
| 207 |
-
onClick={() => navigator.clipboard.writeText(payment.id)}
|
| 208 |
-
>
|
| 209 |
-
Copy payment ID
|
| 210 |
-
</DropdownMenuItem>
|
| 211 |
-
<DropdownMenuSeparator />
|
| 212 |
-
<DropdownMenuItem>View customer</DropdownMenuItem>
|
| 213 |
-
<DropdownMenuItem>View payment details</DropdownMenuItem>
|
| 214 |
-
</DropdownMenuContent>
|
| 215 |
-
</DropdownMenu>
|
| 216 |
-
</section>
|
| 217 |
);
|
| 218 |
},
|
| 219 |
},
|
|
@@ -338,6 +333,14 @@ export function FilesTable() {
|
|
| 338 |
</Button>
|
| 339 |
</div>
|
| 340 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 341 |
</div>
|
| 342 |
);
|
| 343 |
}
|
|
|
|
| 11 |
getSortedRowModel,
|
| 12 |
useReactTable,
|
| 13 |
} from '@tanstack/react-table';
|
| 14 |
+
import { ArrowUpDown } from 'lucide-react';
|
| 15 |
import * as React from 'react';
|
| 16 |
|
| 17 |
import SvgIcon from '@/components/svg-icon';
|
| 18 |
import { TableEmpty, TableSkeleton } from '@/components/table-skeleton';
|
| 19 |
+
import { Badge } from '@/components/ui/badge';
|
| 20 |
import { Button } from '@/components/ui/button';
|
| 21 |
import { Checkbox } from '@/components/ui/checkbox';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
import {
|
| 23 |
Table,
|
| 24 |
TableBody,
|
|
|
|
| 40 |
import { getExtension } from '@/utils/document-util';
|
| 41 |
import { useMemo } from 'react';
|
| 42 |
import { useTranslation } from 'react-i18next';
|
| 43 |
+
import { ActionCell } from './action-cell';
|
| 44 |
+
import { useHandleConnectToKnowledge, useNavigateToOtherFolder } from './hooks';
|
| 45 |
+
import { LinkToDatasetDialog } from './link-to-dataset-dialog';
|
| 46 |
|
| 47 |
export function FilesTable() {
|
| 48 |
const [sorting, setSorting] = React.useState<SortingState>([]);
|
|
|
|
| 56 |
keyPrefix: 'fileManager',
|
| 57 |
});
|
| 58 |
const navigateToOtherFolder = useNavigateToOtherFolder();
|
| 59 |
+
const {
|
| 60 |
+
connectToKnowledgeVisible,
|
| 61 |
+
hideConnectToKnowledgeModal,
|
| 62 |
+
showConnectToKnowledgeModal,
|
| 63 |
+
initialConnectedIds,
|
| 64 |
+
onConnectToKnowledgeOk,
|
| 65 |
+
connectToKnowledgeLoading,
|
| 66 |
+
} = useHandleConnectToKnowledge();
|
| 67 |
|
| 68 |
const { pagination, data, loading, setPagination } = useFetchFileList();
|
| 69 |
|
|
|
|
| 178 |
{
|
| 179 |
accessorKey: 'kbs_info',
|
| 180 |
header: t('knowledgeBase'),
|
| 181 |
+
cell: ({ row }) => {
|
| 182 |
+
const value = row.getValue('kbs_info');
|
| 183 |
+
return Array.isArray(value) ? (
|
| 184 |
+
<section className="flex gap-2 items-center">
|
| 185 |
+
{value?.slice(0, 2).map((x) => (
|
| 186 |
+
<Badge key={x.kb_id} className="" variant={'tertiary'}>
|
| 187 |
+
{x.kb_name}
|
| 188 |
+
</Badge>
|
| 189 |
+
))}
|
| 190 |
+
|
| 191 |
+
{value.length > 2 && (
|
| 192 |
+
<Button variant={'icon'} size={'auto'}>
|
| 193 |
+
+{value.length - 2}
|
| 194 |
+
</Button>
|
| 195 |
+
)}
|
| 196 |
+
</section>
|
| 197 |
+
) : (
|
| 198 |
+
''
|
| 199 |
+
);
|
| 200 |
+
},
|
| 201 |
},
|
| 202 |
{
|
| 203 |
id: 'actions',
|
| 204 |
header: t('action'),
|
| 205 |
enableHiding: false,
|
| 206 |
cell: ({ row }) => {
|
|
|
|
|
|
|
| 207 |
return (
|
| 208 |
+
<ActionCell
|
| 209 |
+
row={row}
|
| 210 |
+
showConnectToKnowledgeModal={showConnectToKnowledgeModal}
|
| 211 |
+
></ActionCell>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 212 |
);
|
| 213 |
},
|
| 214 |
},
|
|
|
|
| 333 |
</Button>
|
| 334 |
</div>
|
| 335 |
</div>
|
| 336 |
+
{connectToKnowledgeVisible && (
|
| 337 |
+
<LinkToDatasetDialog
|
| 338 |
+
hideModal={hideConnectToKnowledgeModal}
|
| 339 |
+
initialConnectedIds={initialConnectedIds}
|
| 340 |
+
onConnectToKnowledgeOk={onConnectToKnowledgeOk}
|
| 341 |
+
loading={connectToKnowledgeLoading}
|
| 342 |
+
></LinkToDatasetDialog>
|
| 343 |
+
)}
|
| 344 |
</div>
|
| 345 |
);
|
| 346 |
}
|
web/src/pages/files/hooks.ts
CHANGED
|
@@ -224,7 +224,7 @@ export const useHandleConnectToKnowledge = () => {
|
|
| 224 |
);
|
| 225 |
|
| 226 |
return {
|
| 227 |
-
initialValue,
|
| 228 |
connectToKnowledgeLoading: loading,
|
| 229 |
onConnectToKnowledgeOk,
|
| 230 |
connectToKnowledgeVisible,
|
|
@@ -233,6 +233,10 @@ export const useHandleConnectToKnowledge = () => {
|
|
| 233 |
};
|
| 234 |
};
|
| 235 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 236 |
export const useHandleBreadcrumbClick = () => {
|
| 237 |
const navigate = useNavigate();
|
| 238 |
|
|
|
|
| 224 |
);
|
| 225 |
|
| 226 |
return {
|
| 227 |
+
initialConnectedIds: initialValue,
|
| 228 |
connectToKnowledgeLoading: loading,
|
| 229 |
onConnectToKnowledgeOk,
|
| 230 |
connectToKnowledgeVisible,
|
|
|
|
| 233 |
};
|
| 234 |
};
|
| 235 |
|
| 236 |
+
export type UseHandleConnectToKnowledgeReturnType = ReturnType<
|
| 237 |
+
typeof useHandleConnectToKnowledge
|
| 238 |
+
>;
|
| 239 |
+
|
| 240 |
export const useHandleBreadcrumbClick = () => {
|
| 241 |
const navigate = useNavigate();
|
| 242 |
|
web/src/pages/files/link-to-dataset-dialog.tsx
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import {
|
| 2 |
+
Dialog,
|
| 3 |
+
DialogContent,
|
| 4 |
+
DialogFooter,
|
| 5 |
+
DialogHeader,
|
| 6 |
+
DialogTitle,
|
| 7 |
+
} from '@/components/ui/dialog';
|
| 8 |
+
import {
|
| 9 |
+
Form,
|
| 10 |
+
FormControl,
|
| 11 |
+
FormField,
|
| 12 |
+
FormItem,
|
| 13 |
+
FormLabel,
|
| 14 |
+
FormMessage,
|
| 15 |
+
} from '@/components/ui/form';
|
| 16 |
+
import { LoadingButton } from '@/components/ui/loading-button';
|
| 17 |
+
import { MultiSelect } from '@/components/ui/multi-select';
|
| 18 |
+
import { useSelectKnowledgeOptions } from '@/hooks/knowledge-hooks';
|
| 19 |
+
import { IModalProps } from '@/interfaces/common';
|
| 20 |
+
import { zodResolver } from '@hookform/resolvers/zod';
|
| 21 |
+
import { Link2 } from 'lucide-react';
|
| 22 |
+
import { useForm } from 'react-hook-form';
|
| 23 |
+
import { useTranslation } from 'react-i18next';
|
| 24 |
+
import { z } from 'zod';
|
| 25 |
+
import { UseHandleConnectToKnowledgeReturnType } from './hooks';
|
| 26 |
+
|
| 27 |
+
const FormId = 'LinkToDatasetForm';
|
| 28 |
+
|
| 29 |
+
const FormSchema = z.object({
|
| 30 |
+
knowledgeIds: z.array(z.string()).min(0, {
|
| 31 |
+
message: 'Username must be at least 1 characters.',
|
| 32 |
+
}),
|
| 33 |
+
});
|
| 34 |
+
|
| 35 |
+
function LinkToDatasetForm({
|
| 36 |
+
initialConnectedIds,
|
| 37 |
+
onConnectToKnowledgeOk,
|
| 38 |
+
}: Pick<
|
| 39 |
+
UseHandleConnectToKnowledgeReturnType,
|
| 40 |
+
'initialConnectedIds' | 'onConnectToKnowledgeOk'
|
| 41 |
+
>) {
|
| 42 |
+
const { t } = useTranslation();
|
| 43 |
+
const form = useForm<z.infer<typeof FormSchema>>({
|
| 44 |
+
resolver: zodResolver(FormSchema),
|
| 45 |
+
defaultValues: {
|
| 46 |
+
knowledgeIds: initialConnectedIds,
|
| 47 |
+
},
|
| 48 |
+
});
|
| 49 |
+
|
| 50 |
+
const options = useSelectKnowledgeOptions();
|
| 51 |
+
|
| 52 |
+
function onSubmit(data: z.infer<typeof FormSchema>) {
|
| 53 |
+
onConnectToKnowledgeOk(data.knowledgeIds);
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
// useEffect(() => {
|
| 57 |
+
// form.setValue('knowledgeIds', initialConnectedIds); // this is invalid
|
| 58 |
+
// }, [form, initialConnectedIds]);
|
| 59 |
+
|
| 60 |
+
return (
|
| 61 |
+
<Form {...form}>
|
| 62 |
+
<form
|
| 63 |
+
onSubmit={form.handleSubmit(onSubmit)}
|
| 64 |
+
className="space-y-6"
|
| 65 |
+
id={FormId}
|
| 66 |
+
>
|
| 67 |
+
<FormField
|
| 68 |
+
control={form.control}
|
| 69 |
+
name="knowledgeIds"
|
| 70 |
+
render={({ field }) => (
|
| 71 |
+
<FormItem>
|
| 72 |
+
<FormLabel>Name</FormLabel>
|
| 73 |
+
<FormControl>
|
| 74 |
+
<MultiSelect
|
| 75 |
+
options={options}
|
| 76 |
+
onValueChange={field.onChange}
|
| 77 |
+
defaultValue={field.value}
|
| 78 |
+
placeholder={t('fileManager.pleaseSelect')}
|
| 79 |
+
maxCount={100}
|
| 80 |
+
// {...field}
|
| 81 |
+
modalPopover
|
| 82 |
+
/>
|
| 83 |
+
</FormControl>
|
| 84 |
+
|
| 85 |
+
<FormMessage />
|
| 86 |
+
</FormItem>
|
| 87 |
+
)}
|
| 88 |
+
/>
|
| 89 |
+
</form>
|
| 90 |
+
</Form>
|
| 91 |
+
);
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
export function LinkToDatasetDialog({
|
| 95 |
+
hideModal,
|
| 96 |
+
initialConnectedIds,
|
| 97 |
+
onConnectToKnowledgeOk,
|
| 98 |
+
loading,
|
| 99 |
+
}: IModalProps<any> &
|
| 100 |
+
Pick<
|
| 101 |
+
UseHandleConnectToKnowledgeReturnType,
|
| 102 |
+
'initialConnectedIds' | 'onConnectToKnowledgeOk'
|
| 103 |
+
>) {
|
| 104 |
+
const { t } = useTranslation();
|
| 105 |
+
return (
|
| 106 |
+
<Dialog open onOpenChange={hideModal}>
|
| 107 |
+
<DialogContent className="sm:max-w-[425px]">
|
| 108 |
+
<DialogHeader>
|
| 109 |
+
<DialogTitle>{t('fileManager.addToKnowledge')}</DialogTitle>
|
| 110 |
+
</DialogHeader>
|
| 111 |
+
<LinkToDatasetForm
|
| 112 |
+
initialConnectedIds={initialConnectedIds}
|
| 113 |
+
onConnectToKnowledgeOk={onConnectToKnowledgeOk}
|
| 114 |
+
></LinkToDatasetForm>
|
| 115 |
+
<DialogFooter>
|
| 116 |
+
<LoadingButton
|
| 117 |
+
type="submit"
|
| 118 |
+
variant={'tertiary'}
|
| 119 |
+
form={FormId}
|
| 120 |
+
loading={loading}
|
| 121 |
+
>
|
| 122 |
+
<div className="flex gap-2 items-center">
|
| 123 |
+
<Link2 /> Save
|
| 124 |
+
</div>
|
| 125 |
+
</LoadingButton>
|
| 126 |
+
</DialogFooter>
|
| 127 |
+
</DialogContent>
|
| 128 |
+
</Dialog>
|
| 129 |
+
);
|
| 130 |
+
}
|
web/tailwind.config.js
CHANGED
|
@@ -37,6 +37,7 @@ module.exports = {
|
|
| 37 |
'colors-text-neutral-standard': 'var(--colors-text-neutral-standard)',
|
| 38 |
'colors-text-functional-danger': 'var(--colors-text-functional-danger)',
|
| 39 |
'colors-text-inverse-strong': 'var(--colors-text-inverse-strong)',
|
|
|
|
| 40 |
|
| 41 |
primary: {
|
| 42 |
DEFAULT: 'hsl(var(--primary))',
|
|
@@ -156,6 +157,10 @@ module.exports = {
|
|
| 156 |
DEFAULT: 'var(--colors-background-neutral-weak)',
|
| 157 |
foreground: 'var(--background-inverse-standard-foreground)',
|
| 158 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
},
|
| 160 |
borderRadius: {
|
| 161 |
lg: `var(--radius)`,
|
|
|
|
| 37 |
'colors-text-neutral-standard': 'var(--colors-text-neutral-standard)',
|
| 38 |
'colors-text-functional-danger': 'var(--colors-text-functional-danger)',
|
| 39 |
'colors-text-inverse-strong': 'var(--colors-text-inverse-strong)',
|
| 40 |
+
'colors-text-persist-light': 'var(--colors-text-persist-light)',
|
| 41 |
|
| 42 |
primary: {
|
| 43 |
DEFAULT: 'hsl(var(--primary))',
|
|
|
|
| 157 |
DEFAULT: 'var(--colors-background-neutral-weak)',
|
| 158 |
foreground: 'var(--background-inverse-standard-foreground)',
|
| 159 |
},
|
| 160 |
+
'colors-background-sentiment-solid-primary': {
|
| 161 |
+
DEFAULT: 'var(--colors-background-sentiment-solid-primary)',
|
| 162 |
+
foreground: 'var(--background-inverse-standard-foreground)',
|
| 163 |
+
},
|
| 164 |
},
|
| 165 |
borderRadius: {
|
| 166 |
lg: `var(--radius)`,
|
web/tailwind.css
CHANGED
|
@@ -42,6 +42,8 @@
|
|
| 42 |
--colors-background-inverse-weak: rgba(17, 16, 23, 0.1);
|
| 43 |
--colors-background-neutral-standard: white;
|
| 44 |
--colors-background-functional-solid-danger: rgba(222, 17, 53, 1);
|
|
|
|
|
|
|
| 45 |
|
| 46 |
--button-blue-text: rgb(22, 119, 255);
|
| 47 |
|
|
@@ -54,6 +56,7 @@
|
|
| 54 |
--colors-text-neutral-standard: rgba(53, 51, 65, 1);
|
| 55 |
--colors-text-functional-danger: rgba(255, 81, 81, 1);
|
| 56 |
--colors-text-inverse-strong: rgba(255, 255, 255, 1);
|
|
|
|
| 57 |
}
|
| 58 |
|
| 59 |
.dark {
|
|
@@ -123,6 +126,7 @@
|
|
| 123 |
--colors-background-neutral-standard: rgba(11, 10, 18, 1);
|
| 124 |
--colors-background-neutral-strong: rgba(29, 26, 44, 1);
|
| 125 |
--colors-background-neutral-weak: rgba(17, 16, 23, 1);
|
|
|
|
| 126 |
|
| 127 |
--colors-outline-sentiment-primary: rgba(146, 118, 255, 1);
|
| 128 |
--colors-outline-neutral-strong: rgba(255, 255, 255, 0.15);
|
|
@@ -133,6 +137,7 @@
|
|
| 133 |
--colors-text-neutral-standard: rgba(230, 227, 246, 1);
|
| 134 |
--colors-text-functional-danger: rgba(255, 81, 81, 1);
|
| 135 |
--colors-text-inverse-strong: rgba(17, 16, 23, 1);
|
|
|
|
| 136 |
}
|
| 137 |
}
|
| 138 |
|
|
|
|
| 42 |
--colors-background-inverse-weak: rgba(17, 16, 23, 0.1);
|
| 43 |
--colors-background-neutral-standard: white;
|
| 44 |
--colors-background-functional-solid-danger: rgba(222, 17, 53, 1);
|
| 45 |
+
--colors-background-core-strong: rgba(98, 72, 246, 1);
|
| 46 |
+
--colors-background-sentiment-solid-primary: rgba(127, 105, 255, 1);
|
| 47 |
|
| 48 |
--button-blue-text: rgb(22, 119, 255);
|
| 49 |
|
|
|
|
| 56 |
--colors-text-neutral-standard: rgba(53, 51, 65, 1);
|
| 57 |
--colors-text-functional-danger: rgba(255, 81, 81, 1);
|
| 58 |
--colors-text-inverse-strong: rgba(255, 255, 255, 1);
|
| 59 |
+
--colors-text-persist-light: rgba(255, 255, 255, 1);
|
| 60 |
}
|
| 61 |
|
| 62 |
.dark {
|
|
|
|
| 126 |
--colors-background-neutral-standard: rgba(11, 10, 18, 1);
|
| 127 |
--colors-background-neutral-strong: rgba(29, 26, 44, 1);
|
| 128 |
--colors-background-neutral-weak: rgba(17, 16, 23, 1);
|
| 129 |
+
--colors-background-sentiment-solid-primary: rgba(146, 118, 255, 1);
|
| 130 |
|
| 131 |
--colors-outline-sentiment-primary: rgba(146, 118, 255, 1);
|
| 132 |
--colors-outline-neutral-strong: rgba(255, 255, 255, 0.15);
|
|
|
|
| 137 |
--colors-text-neutral-standard: rgba(230, 227, 246, 1);
|
| 138 |
--colors-text-functional-danger: rgba(255, 81, 81, 1);
|
| 139 |
--colors-text-inverse-strong: rgba(17, 16, 23, 1);
|
| 140 |
+
--colors-text-persist-light: rgba(255, 255, 255, 1);
|
| 141 |
}
|
| 142 |
}
|
| 143 |
|