From 4e63d8427d26d0d1b366ddc53650e15f3481fc75 Mon Sep 17 00:00:00 2001
From: dujinkim <dujin.kim@dtsolution.co.kr>
Date: Tue, 24 Jun 2025 01:44:03 +0000
Subject: (대표님/최겸) 20250624 작업사항 10시43분
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 lib/evaluation/table/evaluation-table.tsx | 72 +++++++++++++++++--------------
 1 file changed, 40 insertions(+), 32 deletions(-)

(limited to 'lib/evaluation/table/evaluation-table.tsx')

diff --git a/lib/evaluation/table/evaluation-table.tsx b/lib/evaluation/table/evaluation-table.tsx
index 16f70592..a628475d 100644
--- a/lib/evaluation/table/evaluation-table.tsx
+++ b/lib/evaluation/table/evaluation-table.tsx
@@ -23,6 +23,7 @@ import { useMemo } from "react"
 import { PeriodicEvaluationFilterSheet } from "./evaluation-filter-sheet"
 import { getPeriodicEvaluationsColumns } from "./evaluation-columns"
 import { PeriodicEvaluationView } from "@/db/schema"
+import { getPeriodicEvaluations } from "../service"
 
 interface PeriodicEvaluationsTableProps {
   promises: Promise<[Awaited<ReturnType<typeof getPeriodicEvaluations>>]>
@@ -229,16 +230,33 @@ export function PeriodicEvaluationsTable({ promises, evaluationYear, className }
   const [promiseData] = React.use(promises)
   const tableData = promiseData
 
+  const getSearchParam = React.useCallback((key: string, defaultValue?: string): string => {
+    return searchParams?.get(key) ?? defaultValue ?? "";
+  }, [searchParams]);
+
+  const parseSearchParamHelper = React.useCallback((key: string, defaultValue: any): any => {
+    try {
+      const value = getSearchParam(key);
+      return value ? JSON.parse(value) : defaultValue;
+    } catch {
+      return defaultValue;
+    }
+  }, [getSearchParam]);
+
+  const parseSearchParam = <T,>(key: string, defaultValue: T): T => {
+    return parseSearchParamHelper(key, defaultValue);
+  };
+
   const initialSettings = React.useMemo(() => ({
-    page: parseInt(searchParams.get('page') || '1'),
-    perPage: parseInt(searchParams.get('perPage') || '10'),
-    sort: searchParams.get('sort') ? JSON.parse(searchParams.get('sort')!) : [{ id: "createdAt", desc: true }],
-    filters: searchParams.get('filters') ? JSON.parse(searchParams.get('filters')!) : [],
-    joinOperator: (searchParams.get('joinOperator') as "and" | "or") || "and",
-    basicFilters: searchParams.get('basicFilters') ?
-      JSON.parse(searchParams.get('basicFilters')!) : [],
-    basicJoinOperator: (searchParams.get('basicJoinOperator') as "and" | "or") || "and",
-    search: searchParams.get('search') || '',
+    page: parseInt(getSearchParam('page') || '1'),
+    perPage: parseInt(getSearchParam('perPage') || '10'),
+    sort: getSearchParam('sort') ? JSON.parse(getSearchParam('sort')!) : [{ id: "createdAt", desc: true }],
+    filters: getSearchParam('filters') ? JSON.parse(getSearchParam('filters')!) : [],
+    joinOperator: (getSearchParam('joinOperator') as "and" | "or") || "and",
+    basicFilters: getSearchParam('basicFilters') ?
+      JSON.parse(getSearchParam('basicFilters')!) : [],
+    basicJoinOperator: (getSearchParam('basicJoinOperator') as "and" | "or") || "and",
+    search: getSearchParam('search') || '',
     columnVisibility: {},
     columnOrder: [],
     pinnedColumns: { left: [], right: ["actions"] },
@@ -267,22 +285,22 @@ export function PeriodicEvaluationsTable({ promises, evaluationYear, className }
   )
 
   const filterFields: DataTableFilterField<PeriodicEvaluationView>[] = [
-    { id: "evaluationTarget.vendorCode", label: "벤더 코드" },
-    { id: "evaluationTarget.vendorName", label: "벤더명" },
+    { id: "vendorCode", label: "벤더 코드" },
+    { id: "vendorName", label: "벤더명" },
     { id: "status", label: "진행상태" },
   ]
 
   const advancedFilterFields: DataTableAdvancedFilterField<PeriodicEvaluationView>[] = [
-    { id: "evaluationTarget.evaluationYear", label: "평가년도", type: "number" },
+    { id: "evaluationYear", label: "평가년도", type: "number" },
     { id: "evaluationPeriod", label: "평가기간", type: "text" },
     {
-      id: "evaluationTarget.division", label: "구분", type: "select", options: [
+      id: "division", label: "구분", type: "select", options: [
         { label: "해양", value: "PLANT" },
         { label: "조선", value: "SHIP" },
       ]
     },
-    { id: "evaluationTarget.vendorCode", label: "벤더 코드", type: "text" },
-    { id: "evaluationTarget.vendorName", label: "벤더명", type: "text" },
+    { id: "vendorCode", label: "벤더 코드", type: "text" },
+    { id: "vendorName", label: "벤더명", type: "text" },
     {
       id: "status", label: "진행상태", type: "select", options: [
         { label: "제출대기", value: "PENDING_SUBMISSION" },
@@ -305,24 +323,14 @@ export function PeriodicEvaluationsTable({ promises, evaluationYear, className }
     { id: "finalizedAt", label: "최종확정일", type: "date" },
   ]
 
-  const currentSettings = useMemo(() => {
-    return getCurrentSettings()
-  }, [getCurrentSettings])
+  const currentSettings = React.useMemo(() => getCurrentSettings(), [getCurrentSettings]);
 
-  function getColKey<T>(c: ColumnDef<T>): string | undefined {
-    if ("accessorKey" in c && c.accessorKey) return c.accessorKey as string
-    if ("id" in c && c.id) return c.id as string
-    return undefined
-  }
+  const initialState = React.useMemo(() => ({
+    sorting: initialSettings.sort.filter((s: any) => columns.some((c: any) => ("accessorKey" in c ? c.accessorKey : c.id) === s.id)),
+    columnVisibility: currentSettings.columnVisibility,
+    columnPinning: currentSettings.pinnedColumns,
+  }), [columns, currentSettings, initialSettings.sort]);
 
-  const initialState = useMemo(() => {
-    return {
-      sorting: initialSettings.sort.filter(s =>
-        columns.some(c => getColKey(c) === s.id)),
-      columnVisibility: currentSettings.columnVisibility,
-      columnPinning: currentSettings.pinnedColumns,
-    }
-  }, [columns, currentSettings, initialSettings.sort])
 
   const { table } = useDataTable({
     data: tableData.data,
@@ -344,7 +352,7 @@ export function PeriodicEvaluationsTable({ promises, evaluationYear, className }
 
   const getActiveBasicFilterCount = () => {
     try {
-      const basicFilters = searchParams.get('basicFilters')
+      const basicFilters = getSearchParam('basicFilters')
       return basicFilters ? JSON.parse(basicFilters).length : 0
     } catch (e) {
       return 0
-- 
cgit v1.2.3

