diff options
Diffstat (limited to 'components/form-data/import-excel-form.tsx')
| -rw-r--r-- | components/form-data/import-excel-form.tsx | 49 |
1 files changed, 9 insertions, 40 deletions
diff --git a/components/form-data/import-excel-form.tsx b/components/form-data/import-excel-form.tsx index f32e44d8..6f0828b0 100644 --- a/components/form-data/import-excel-form.tsx +++ b/components/form-data/import-excel-form.tsx @@ -5,14 +5,13 @@ import { DataTableColumnJSON } from "./form-data-table-columns"; import { updateFormDataInDB } from "@/lib/forms/services"; import { decryptWithServerAction } from "../drm/drmUtils"; -// Enhanced options interface with editableFieldsMap +// Simplified options interface without editableFieldsMap export interface ImportExcelOptions { file: File; tableData: GenericData[]; columnsJSON: DataTableColumnJSON[]; formCode?: string; contractItemId?: number; - editableFieldsMap?: Map<string, string[]>; // 새로 추가 onPendingChange?: (isPending: boolean) => void; onDataUpdate?: (updater: ((prev: GenericData[]) => GenericData[]) | GenericData[]) => void; } @@ -42,7 +41,6 @@ export async function importExcelData({ columnsJSON, formCode, contractItemId, - editableFieldsMap = new Map(), // 기본값으로 빈 Map onPendingChange, onDataUpdate }: ImportExcelOptions): Promise<ImportExcelResult> { @@ -141,47 +139,18 @@ export async function importExcelData({ const rowObj: Record<string, any> = {}; const skippedFields: string[] = []; // 현재 행에서 건너뛴 필드들 - // Get the TAG_NO first to identify existing data and editable fields + // Get the TAG_NO first to identify existing data const tagNoColIndex = keyToIndexMap.get("TAG_NO"); const tagNo = tagNoColIndex ? String(rowValues[tagNoColIndex] ?? "").trim() : ""; const existingRowData = existingDataMap.get(tagNo); - - // Get editable fields for this specific TAG - const editableFields = editableFieldsMap.has(tagNo) ? editableFieldsMap.get(tagNo)! : []; // Process each column columnsJSON.forEach((col) => { const colIndex = keyToIndexMap.get(col.key); if (colIndex === undefined) return; - // Determine if this field is editable - let isFieldEditable = true; - let skipReason = ""; - - // 1. Check if this is a SHI-only field + // Check if this is a SHI-only field (skip processing but preserve existing value) if (col.shi === true) { - isFieldEditable = false; - skipReason = "SHI-only field"; - } - // 2. Check if this field is editable based on TAG class attributes - else if (col.key !== "TAG_NO" && col.key !== "TAG_DESC") { - // For non-basic fields, check if they're in the editable list - if (tagNo && editableFieldsMap.has(tagNo)) { - if (!editableFields.includes(col.key)) { - isFieldEditable = false; - skipReason = "Not editable for this TAG class"; - } - } else if (tagNo) { - // If TAG exists but no editable fields info, treat as not editable - isFieldEditable = false; - skipReason = "No editable fields info for this TAG"; - } - } - // 3. TAG_NO and TAG_DESC are always considered basic fields - // (They should be editable, but you might want to add specific logic here) - - // If field is not editable, use existing value or default - if (!isFieldEditable) { if (existingRowData && existingRowData[col.key] !== undefined) { rowObj[col.key] = existingRowData[col.key]; } else { @@ -199,7 +168,7 @@ export async function importExcelData({ } // Log skipped field - skippedFields.push(`${col.label} (${skipReason})`); + skippedFields.push(`${col.label} (SHI-only field)`); return; // Skip processing Excel value for this column } @@ -254,7 +223,7 @@ export async function importExcelData({ tagNo: tagNo, fields: skippedFields }); - warningMessage += `Skipped ${skippedFields.length} non-editable fields. `; + warningMessage += `Skipped ${skippedFields.length} SHI-only fields. `; } // Validate TAG_NO @@ -283,7 +252,7 @@ export async function importExcelData({ const totalSkippedFields = skippedFieldsLog.reduce((sum, log) => sum + log.fields.length, 0); console.log("Skipped fields summary:", skippedFieldsLog); toast.info( - `${totalSkippedFields} non-editable fields were skipped across ${skippedFieldsLog.length} rows. Check console for details.` + `${totalSkippedFields} SHI-only fields were skipped across ${skippedFieldsLog.length} rows. Check console for details.` ); } @@ -391,7 +360,7 @@ export async function importExcelData({ } const successMessage = skippedFieldsLog.length > 0 - ? `Successfully updated ${successCount} rows (some non-editable fields were preserved)` + ? `Successfully updated ${successCount} rows (SHI-only fields were preserved)` : `Successfully updated ${successCount} rows`; toast.success(successMessage); @@ -417,7 +386,7 @@ export async function importExcelData({ } const successMessage = skippedFieldsLog.length > 0 - ? `Imported ${importedData.length} rows successfully (some fields preserved)` + ? `Imported ${importedData.length} rows successfully (SHI-only fields preserved)` : `Imported ${importedData.length} rows successfully`; toast.success(`${successMessage} (local only)`); @@ -435,4 +404,4 @@ export async function importExcelData({ } finally { if (onPendingChange) onPendingChange(false); } -} +}
\ No newline at end of file |
