// enhanced-doc-table-toolbar-actions.tsx - 최적화된 버전 "use client" import * as React from "react" import { type Table } from "@tanstack/react-table" import { Download, Upload, Plus, Files, RefreshCw } from "lucide-react" import { toast } from "sonner" import { exportTableToExcel } from "@/lib/export" import { Button } from "@/components/ui/button" import { SimplifiedDocumentsView } from "@/db/schema/vendorDocu" import { SendToSHIButton } from "./send-to-shi-button" import { ImportFromDOLCEButton } from "./import-from-dolce-button" interface EnhancedDocTableToolbarActionsProps { table: Table projectType: "ship" | "plant" } export function EnhancedDocTableToolbarActions({ table, projectType, }: EnhancedDocTableToolbarActionsProps) { const [bulkUploadDialogOpen, setBulkUploadDialogOpen] = React.useState(false) // 🔥 메모이제이션으로 불필요한 재계산 방지 const allDocuments = React.useMemo(() => { return table.getFilteredRowModel().rows.map(row => row.original) }, [ table.getFilteredRowModel().rows.length, // 행 개수가 변경될 때만 재계산 table.getState().columnFilters, // 필터가 변경될 때만 재계산 table.getState().globalFilter, // 전역 필터가 변경될 때만 재계산 ]) // 🔥 projectIds 메모이제이션 (ImportFromDOLCEButton에서 중복 계산 방지) const projectIds = React.useMemo(() => { const uniqueIds = [...new Set(allDocuments.map(doc => doc.projectId).filter(Boolean))] return uniqueIds.sort() }, [allDocuments]) // 🔥 핸들러들을 useCallback으로 메모이제이션 const handleSyncComplete = React.useCallback(() => { table.resetRowSelection() }, [table]) const handleDocumentAdded = React.useCallback(() => { table.resetRowSelection() // 🔥 강제 새로고침 대신 더 효율적인 방법 사용 setTimeout(() => { // 상태 업데이트만으로 충분한 경우가 많음 window.location.reload() }, 500) }, [table]) const handleImportComplete = React.useCallback(() => { table.resetRowSelection() setTimeout(() => { window.location.reload() }, 500) }, [table]) // 🔥 Export 핸들러 메모이제이션 const handleExport = React.useCallback(() => { exportTableToExcel(table, { filename: "Document-list", excludeColumns: ["select", "actions"], }) }, [table]) return (
{/* SHIP: DOLCE에서 목록 가져오기 */} {/* Export 버튼 (공통) */} {/* Send to SHI 버튼 (공통) */}
) }