Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Add LinkToDatasetDialog #3221 #4500

Merged
merged 2 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion web/src/components/ui/badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const badgeVariants = cva(
'border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80',
outline: 'text-foreground',
tertiary:
'border-transparent bg-colors-text-core-standard text-foreground hover:bg-colors-text-core-standard/80',
'border-transparent bg-colors-background-core-strong text-colors-text-persist-light hover:bg-colors-background-core-strong/80',
},
},
defaultVariants: {
Expand Down
3 changes: 2 additions & 1 deletion web/src/components/ui/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ const buttonVariants = cva(
ghost: 'hover:bg-accent hover:text-accent-foreground',
link: 'text-primary underline-offset-4 hover:underline',
tertiary:
'bg-colors-text-core-standard text-foreground hover:bg-colors-text-core-standard/80',
'bg-colors-background-sentiment-solid-primary text-colors-text-persist-light hover:bg-colors-background-sentiment-solid-primary/80',
icon: 'bg-colors-background-inverse-standard text-foreground hover:bg-colors-background-inverse-standard/80',
},
size: {
default: 'h-10 px-4 py-2',
sm: 'h-9 rounded-md px-3',
lg: 'h-11 rounded-md px-8',
icon: 'h-10 w-10',
auto: 'h-full px-1',
},
},
defaultVariants: {
Expand Down
2 changes: 2 additions & 0 deletions web/src/components/ui/loading-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const buttonVariants = cva(
'bg-secondary text-secondary-foreground hover:bg-secondary/80',
ghost: 'hover:bg-accent hover:text-accent-foreground',
link: 'text-primary underline-offset-4 hover:underline',
tertiary:
'bg-colors-background-sentiment-solid-primary text-colors-text-persist-light hover:bg-colors-background-sentiment-solid-primary/80',
},
size: {
default: 'h-10 px-4 py-2',
Expand Down
11 changes: 11 additions & 0 deletions web/src/hooks/knowledge-hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,17 @@ export const useFetchKnowledgeList = (
return { list: data, loading };
};

export const useSelectKnowledgeOptions = () => {
const { list } = useFetchKnowledgeList();

const options = list?.map((item) => ({
label: item.name,
value: item.id,
}));

return options;
};

export const useInfiniteFetchKnowledgeList = () => {
const { searchString, handleInputChange } = useHandleSearchChange();
const debouncedSearchString = useDebounce(searchString, { wait: 500 });
Expand Down
61 changes: 61 additions & 0 deletions web/src/pages/files/action-cell.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { ConfirmDeleteDialog } from '@/components/confirm-delete-dialog';
import { Button } from '@/components/ui/button';
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from '@/components/ui/dropdown-menu';
import { IFile } from '@/interfaces/database/file-manager';
import { CellContext } from '@tanstack/react-table';
import { EllipsisVertical, Link2, Trash2 } from 'lucide-react';
import { useCallback } from 'react';
import { UseHandleConnectToKnowledgeReturnType } from './hooks';

type IProps = Pick<CellContext<IFile, unknown>, 'row'> &
Pick<UseHandleConnectToKnowledgeReturnType, 'showConnectToKnowledgeModal'>;

export function ActionCell({ row, showConnectToKnowledgeModal }: IProps) {
const record = row.original;

const handleShowConnectToKnowledgeModal = useCallback(() => {
showConnectToKnowledgeModal(record);
}, [record, showConnectToKnowledgeModal]);

return (
<section className="flex gap-4 items-center">
<Button
variant="secondary"
size={'icon'}
onClick={handleShowConnectToKnowledgeModal}
>
<Link2 />
</Button>
<ConfirmDeleteDialog>
<Button variant="secondary" size={'icon'}>
<Trash2 />
</Button>
</ConfirmDeleteDialog>
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="secondary" size={'icon'}>
<EllipsisVertical />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuLabel>Actions</DropdownMenuLabel>
<DropdownMenuItem
onClick={() => navigator.clipboard.writeText(record.id)}
>
Copy payment ID
</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem>View customer</DropdownMenuItem>
<DropdownMenuItem>View payment details</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</section>
);
}
87 changes: 45 additions & 42 deletions web/src/pages/files/files-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,14 @@ import {
getSortedRowModel,
useReactTable,
} from '@tanstack/react-table';
import { ArrowUpDown, MoreHorizontal, Pencil } from 'lucide-react';
import { ArrowUpDown } from 'lucide-react';
import * as React from 'react';

import SvgIcon from '@/components/svg-icon';
import { TableEmpty, TableSkeleton } from '@/components/table-skeleton';
import { Badge } from '@/components/ui/badge';
import { Button } from '@/components/ui/button';
import { Checkbox } from '@/components/ui/checkbox';
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from '@/components/ui/dropdown-menu';
import { Switch } from '@/components/ui/switch';
import {
Table,
TableBody,
Expand All @@ -48,7 +40,9 @@ import { formatDate } from '@/utils/date';
import { getExtension } from '@/utils/document-util';
import { useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { useNavigateToOtherFolder } from './hooks';
import { ActionCell } from './action-cell';
import { useHandleConnectToKnowledge, useNavigateToOtherFolder } from './hooks';
import { LinkToDatasetDialog } from './link-to-dataset-dialog';

export function FilesTable() {
const [sorting, setSorting] = React.useState<SortingState>([]);
Expand All @@ -62,6 +56,14 @@ export function FilesTable() {
keyPrefix: 'fileManager',
});
const navigateToOtherFolder = useNavigateToOtherFolder();
const {
connectToKnowledgeVisible,
hideConnectToKnowledgeModal,
showConnectToKnowledgeModal,
initialConnectedIds,
onConnectToKnowledgeOk,
connectToKnowledgeLoading,
} = useHandleConnectToKnowledge();

const { pagination, data, loading, setPagination } = useFetchFileList();

Expand Down Expand Up @@ -176,44 +178,37 @@ export function FilesTable() {
{
accessorKey: 'kbs_info',
header: t('knowledgeBase'),
cell: ({ row }) => (
<Button variant="destructive" size={'sm'}>
{row.getValue('kbs_info')}
</Button>
),
cell: ({ row }) => {
const value = row.getValue('kbs_info');
return Array.isArray(value) ? (
<section className="flex gap-2 items-center">
{value?.slice(0, 2).map((x) => (
<Badge key={x.kb_id} className="" variant={'tertiary'}>
{x.kb_name}
</Badge>
))}

{value.length > 2 && (
<Button variant={'icon'} size={'auto'}>
+{value.length - 2}
</Button>
)}
</section>
) : (
''
);
},
},
{
id: 'actions',
header: t('action'),
enableHiding: false,
cell: ({ row }) => {
const payment = row.original;

return (
<section className="flex gap-4 items-center">
<Switch id="airplane-mode" />
<Button variant="secondary" size={'icon'}>
<Pencil />
</Button>
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="secondary" size={'icon'}>
<MoreHorizontal />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuLabel>Actions</DropdownMenuLabel>
<DropdownMenuItem
onClick={() => navigator.clipboard.writeText(payment.id)}
>
Copy payment ID
</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem>View customer</DropdownMenuItem>
<DropdownMenuItem>View payment details</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</section>
<ActionCell
row={row}
showConnectToKnowledgeModal={showConnectToKnowledgeModal}
></ActionCell>
);
},
},
Expand Down Expand Up @@ -338,6 +333,14 @@ export function FilesTable() {
</Button>
</div>
</div>
{connectToKnowledgeVisible && (
<LinkToDatasetDialog
hideModal={hideConnectToKnowledgeModal}
initialConnectedIds={initialConnectedIds}
onConnectToKnowledgeOk={onConnectToKnowledgeOk}
loading={connectToKnowledgeLoading}
></LinkToDatasetDialog>
)}
</div>
);
}
6 changes: 5 additions & 1 deletion web/src/pages/files/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ export const useHandleConnectToKnowledge = () => {
);

return {
initialValue,
initialConnectedIds: initialValue,
connectToKnowledgeLoading: loading,
onConnectToKnowledgeOk,
connectToKnowledgeVisible,
Expand All @@ -233,6 +233,10 @@ export const useHandleConnectToKnowledge = () => {
};
};

export type UseHandleConnectToKnowledgeReturnType = ReturnType<
typeof useHandleConnectToKnowledge
>;

export const useHandleBreadcrumbClick = () => {
const navigate = useNavigate();

Expand Down
Loading