From bac0228d21b7195065e9cddcc327ae33659c7bcc Mon Sep 17 00:00:00 2001 From: dujinkim Date: Sun, 1 Jun 2025 13:52:21 +0000 Subject: (대표님) 20250601까지 작업사항 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/items/service.ts | 9 +- lib/items/table/items-table-toolbar-actions.tsx | 63 +++++++- lib/items/table/items-table.tsx | 189 ++++++++++++------------ 3 files changed, 156 insertions(+), 105 deletions(-) (limited to 'lib/items') diff --git a/lib/items/service.ts b/lib/items/service.ts index 35d2fa01..c841efad 100644 --- a/lib/items/service.ts +++ b/lib/items/service.ts @@ -45,12 +45,9 @@ export async function getItems(input: GetItemsSchema) { ilike(items.itemLevel, s), ilike(items.itemCode, s), ilike(items.itemName, s), + ilike(items.smCode, s), + ilike(items.packageCode, s), ilike(items.description, s), - ilike(items.parentItemCode, s), - ilike(items.unitOfMeasure, s), - ilike(items.steelType, s), - ilike(items.gradeMaterial, s), - ilike(items.baseUnitOfMeasure, s), ilike(items.changeDate, s) ); } @@ -75,6 +72,8 @@ export async function getItems(input: GetItemsSchema) { return { data, total }; }); + console.log(data) + const pageCount = Math.ceil(total / safePerPage); return { data, pageCount }; } catch (err) { diff --git a/lib/items/table/items-table-toolbar-actions.tsx b/lib/items/table/items-table-toolbar-actions.tsx index b3178ce1..7d8f7fb6 100644 --- a/lib/items/table/items-table-toolbar-actions.tsx +++ b/lib/items/table/items-table-toolbar-actions.tsx @@ -2,9 +2,10 @@ import * as React from "react" import { type Table } from "@tanstack/react-table" -import { Download, FileDown } from "lucide-react" +import { Download, FileDown, Database, Loader2 } from "lucide-react" import * as ExcelJS from 'exceljs' import { saveAs } from "file-saver" +import { toast } from "sonner" import { Button } from "@/components/ui/button" import { @@ -19,6 +20,9 @@ import { DeleteItemsDialog } from "./delete-items-dialog" import { AddItemDialog } from "./add-items-dialog" import { exportItemTemplate } from "./item-excel-template" import { ImportItemButton } from "./import-excel-button" +import { syncItemsFromCodeLists } from "@/lib/sedp/sync-package" + +// 동기화 함수 import (실제 경로로 수정 필요) interface ItemsTableToolbarActionsProps { table: Table @@ -26,12 +30,47 @@ interface ItemsTableToolbarActionsProps { export function ItemsTableToolbarActions({ table }: ItemsTableToolbarActionsProps) { const [refreshKey, setRefreshKey] = React.useState(0) + const [isSyncing, setIsSyncing] = React.useState(false) // 가져오기 성공 후 테이블 갱신 const handleImportSuccess = () => { setRefreshKey(prev => prev + 1) } + // 테이블 새로고침 함수 + const refreshTable = () => { + setRefreshKey(prev => prev + 1) + // 페이지 새로고침 또는 데이터 refetch 로직 + window.location.reload() + } + + // 전체 프로젝트 동기화 + const handleSyncAllProjects = async () => { + if (isSyncing) return + + setIsSyncing(true) + const loadingToast = toast.loading("모든 프로젝트의 아이템을 동기화하는 중...") + + try { + await syncItemsFromCodeLists() + toast.dismiss(loadingToast) + toast.success("모든 프로젝트의 아이템이 성공적으로 동기화되었습니다!") + + // 테이블 새로고침 + setTimeout(() => { + refreshTable() + }, 1000) + } catch (error) { + toast.dismiss(loadingToast) + toast.error("동기화 중 오류가 발생했습니다: " + (error as Error).message) + console.error("동기화 오류:", error) + } finally { + setIsSyncing(false) + } + } + + + // Excel 내보내기 함수 const exportTableToExcel = async ( table: Table, @@ -125,10 +164,28 @@ export function ItemsTableToolbarActions({ table }: ItemsTableToolbarActionsProp ) : null} {/* 새 아이템 추가 다이얼로그 */} - + {/* */} {/* Import 버튼 */} - + {/* */} + + {/* 동기화 버튼 */} + {/* Export 드롭다운 메뉴 */} diff --git a/lib/items/table/items-table.tsx b/lib/items/table/items-table.tsx index c05b4348..92f805eb 100644 --- a/lib/items/table/items-table.tsx +++ b/lib/items/table/items-table.tsx @@ -22,6 +22,7 @@ import { getColumns } from "./items-table-columns" import { ItemsTableToolbarActions } from "./items-table-toolbar-actions" import { UpdateItemSheet } from "./update-item-sheet" import { DeleteItemsDialog } from "./delete-items-dialog" +import { ViewModeToggle } from "@/components/data-table/view-mode-toggle" interface ItemsTableProps { promises?: Promise< @@ -71,7 +72,7 @@ export function ItemsTable({ promises }: ItemsTableProps) { id: "itemName", label: "자재그룹이름", type: "text", - }, + }, { id: "description", label: "상세", @@ -115,13 +116,13 @@ export function ItemsTable({ promises }: ItemsTableProps) { ] // 확장된 useDataTable 훅 사용 (pageSize 기반 자동 전환) - const { - table, - infiniteScroll, - isInfiniteMode, + const { + table, + infiniteScroll, + isInfiniteMode, effectivePageSize, handlePageSizeChange, - urlState + urlState } = useDataTable({ data, columns, @@ -154,98 +155,92 @@ export function ItemsTable({ promises }: ItemsTableProps) { } return ( -
- - {/*
-
- +
+ + {/* 모드 토글 & 새로고침 */} +
+
-
*/} - - {/* 에러 상태 (무한 스크롤 모드) */} - {isInfiniteMode && infiniteScroll?.error && ( - - - 데이터를 불러오는 중 오류가 발생했습니다. - - - - )} - - {/* 로딩 상태가 아닐 때만 테이블 렌더링 */} - {!(isInfiniteMode && infiniteScroll?.isLoading && infiniteScroll?.isEmpty) ? ( - <> - {/* 도구 모음 */} - - - - - {/* 테이블 렌더링 */} - {isInfiniteMode ? ( - // 무한 스크롤 모드: InfiniteDataTable 사용 (자체 페이지네이션 없음) - - ) : ( - // 페이지네이션 모드: DataTable 사용 (내장 페이지네이션 활용) - + + 데이터를 불러오는 중 오류가 발생했습니다. + + + + )} + + {/* 로딩 상태가 아닐 때만 테이블 렌더링 */} + {!(isInfiniteMode && infiniteScroll?.isLoading && infiniteScroll?.isEmpty) ? ( + <> + {/* 도구 모음 */} + - )} - - ) : ( - /* 로딩 스켈레톤 (무한 스크롤 초기 로딩) */ -
-
- 무한 스크롤 모드로 데이터를 로드하고 있습니다... + filterFields={advancedFilterFields} + shallow={false} + > + + + + {/* 테이블 렌더링 */} + {isInfiniteMode ? ( + // 무한 스크롤 모드: InfiniteDataTable 사용 (자체 페이지네이션 없음) + + ) : ( + // 페이지네이션 모드: DataTable 사용 (내장 페이지네이션 활용) + + )} + + ) : ( + /* 로딩 스켈레톤 (무한 스크롤 초기 로딩) */ +
+
+ 무한 스크롤 모드로 데이터를 로드하고 있습니다... +
+ {Array.from({ length: 10 }).map((_, i) => ( +
+ ))}
- {Array.from({ length: 10 }).map((_, i) => ( -
- ))} -
- )} - - {/* 기존 다이얼로그들 */} - setRowAction(null)} - item={rowAction?.row.original ?? null} - /> - setRowAction(null)} - items={rowAction?.row.original ? [rowAction?.row.original] : []} - showTrigger={false} - onSuccess={() => rowAction?.row.toggleSelected(false)} - /> -
- ) + )} + + {/* 기존 다이얼로그들 */} + setRowAction(null)} + item={rowAction?.row.original ?? null} + /> + setRowAction(null)} + items={rowAction?.row.original ? [rowAction?.row.original] : []} + showTrigger={false} + onSuccess={() => rowAction?.row.toggleSelected(false)} + /> +
+ ) } \ No newline at end of file -- cgit v1.2.3