You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mcp-card.tsx 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import { MoreButton } from '@/components/more-button';
  2. import { Card, CardContent } from '@/components/ui/card';
  3. import { Checkbox } from '@/components/ui/checkbox';
  4. import { IMcpServer } from '@/interfaces/database/mcp';
  5. import { formatDate } from '@/utils/date';
  6. import { isPlainObject } from 'lodash';
  7. import { useMemo } from 'react';
  8. import { McpDropdown } from './mcp-dropdown';
  9. import { UseBulkOperateMCPReturnType } from './use-bulk-operate-mcp';
  10. import { UseEditMcpReturnType } from './use-edit-mcp';
  11. export type DatasetCardProps = {
  12. data: IMcpServer;
  13. } & Pick<UseBulkOperateMCPReturnType, 'handleSelectChange' | 'selectedList'> &
  14. Pick<UseEditMcpReturnType, 'showEditModal'>;
  15. export function McpCard({
  16. data,
  17. selectedList,
  18. handleSelectChange,
  19. showEditModal,
  20. }: DatasetCardProps) {
  21. const toolLength = useMemo(() => {
  22. const tools = data.variables?.tools;
  23. if (isPlainObject(tools)) {
  24. return Object.keys(tools || {}).length;
  25. }
  26. return 0;
  27. }, [data.variables?.tools]);
  28. const onCheckedChange = (checked: boolean) => {
  29. if (typeof checked === 'boolean') {
  30. handleSelectChange(data.id, checked);
  31. }
  32. };
  33. return (
  34. <Card key={data.id} className="w-64">
  35. <CardContent className="p-2.5 pt-2 group">
  36. <section className="flex justify-between pb-2">
  37. <h3 className="text-lg font-semibold line-clamp-1">{data.name}</h3>
  38. <div className="space-x-4">
  39. <McpDropdown mcpId={data.id} showEditModal={showEditModal}>
  40. <MoreButton></MoreButton>
  41. </McpDropdown>
  42. <Checkbox
  43. checked={selectedList.includes(data.id)}
  44. onCheckedChange={onCheckedChange}
  45. onClick={(e) => {
  46. e.stopPropagation();
  47. }}
  48. />
  49. </div>
  50. </section>
  51. <div className="flex justify-between items-end">
  52. <div className="w-full">
  53. <div className="text-base font-semibold mb-3 line-clamp-1 text-text-sub-title">
  54. {toolLength} cached tools
  55. </div>
  56. <p className="text-sm text-text-sub-title">
  57. {formatDate(data.update_date)}
  58. </p>
  59. </div>
  60. </div>
  61. </CardContent>
  62. </Card>
  63. );
  64. }