summaryrefslogtreecommitdiff
path: root/components/form-data/sedp-excel-download.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'components/form-data/sedp-excel-download.tsx')
-rw-r--r--components/form-data/sedp-excel-download.tsx213
1 files changed, 152 insertions, 61 deletions
diff --git a/components/form-data/sedp-excel-download.tsx b/components/form-data/sedp-excel-download.tsx
index 70f5c46a..24e1003d 100644
--- a/components/form-data/sedp-excel-download.tsx
+++ b/components/form-data/sedp-excel-download.tsx
@@ -18,11 +18,15 @@ interface ExcelDownloadProps {
uom?: string;
}>;
}>;
+ missingTags: {
+ localOnly: Array<{ tagNo: string; tagDesc: string }>;
+ sedpOnly: Array<{ tagNo: string; tagDesc: string }>;
+ };
formCode: string;
disabled: boolean;
}
-export function ExcelDownload({ comparisonResults, formCode, disabled }: ExcelDownloadProps) {
+export function ExcelDownload({ comparisonResults, missingTags, formCode, disabled }: ExcelDownloadProps) {
const [isExporting, setIsExporting] = React.useState(false);
// Function to generate and download Excel file with differences
@@ -32,8 +36,9 @@ export function ExcelDownload({ comparisonResults, formCode, disabled }: ExcelDo
// Get only items with differences
const itemsWithDifferences = comparisonResults.filter(item => !item.isMatching);
+ const hasMissingTags = missingTags.localOnly.length > 0 || missingTags.sedpOnly.length > 0;
- if (itemsWithDifferences.length === 0) {
+ if (itemsWithDifferences.length === 0 && !hasMissingTags) {
toast.info("차이가 없어 다운로드할 내용이 없습니다");
return;
}
@@ -43,65 +48,122 @@ export function ExcelDownload({ comparisonResults, formCode, disabled }: ExcelDo
workbook.creator = 'SEDP Compare Tool';
workbook.created = new Date();
- // Add a worksheet
- const worksheet = workbook.addWorksheet('SEDP Differences');
-
- // Add headers
- worksheet.columns = [
- { header: 'Tag Number', key: 'tagNo', width: 20 },
- { header: 'Tag Description', key: 'tagDesc', width: 30 },
- { header: 'Attribute', key: 'attribute', width: 25 },
- { header: 'Local Value', key: 'localValue', width: 20 },
- { header: 'SEDP Value', key: 'sedpValue', width: 20 }
- ];
-
- // Style the header row
- const headerRow = worksheet.getRow(1);
- headerRow.eachCell((cell) => {
- cell.font = { bold: true };
- cell.fill = {
- type: 'pattern',
- pattern: 'solid',
- fgColor: { argb: 'FFE0E0E0' }
- };
- cell.border = {
- top: { style: 'thin' },
- left: { style: 'thin' },
- bottom: { style: 'thin' },
- right: { style: 'thin' }
- };
- });
-
- // Add data rows
- let rowIndex = 2;
- itemsWithDifferences.forEach(item => {
- const differences = item.attributes.filter(attr => !attr.isMatching);
+ // Add a worksheet for attribute differences
+ if (itemsWithDifferences.length > 0) {
+ const worksheet = workbook.addWorksheet('속성 차이');
- if (differences.length === 0) return;
+ // Add headers
+ worksheet.columns = [
+ { header: 'Tag Number', key: 'tagNo', width: 20 },
+ { header: 'Tag Description', key: 'tagDesc', width: 30 },
+ { header: 'Attribute', key: 'attribute', width: 25 },
+ { header: 'Local Value', key: 'localValue', width: 20 },
+ { header: 'SEDP Value', key: 'sedpValue', width: 20 }
+ ];
- differences.forEach(diff => {
- const row = worksheet.getRow(rowIndex++);
+ // Style the header row
+ const headerRow = worksheet.getRow(1);
+ headerRow.eachCell((cell) => {
+ cell.font = { bold: true };
+ cell.fill = {
+ type: 'pattern',
+ pattern: 'solid',
+ fgColor: { argb: 'FFE0E0E0' }
+ };
+ cell.border = {
+ top: { style: 'thin' },
+ left: { style: 'thin' },
+ bottom: { style: 'thin' },
+ right: { style: 'thin' }
+ };
+ });
+
+ // Add data rows
+ let rowIndex = 2;
+ itemsWithDifferences.forEach(item => {
+ const differences = item.attributes.filter(attr => !attr.isMatching);
+
+ if (differences.length === 0) return;
- // Format local value with UOM
- const localDisplay = diff.localValue === null || diff.localValue === undefined || diff.localValue === ''
- ? "(empty)"
- : diff.uom ? `${diff.localValue} ${diff.uom}` : diff.localValue;
+ differences.forEach(diff => {
+ const row = worksheet.getRow(rowIndex++);
+
+ // Format local value with UOM
+ const localDisplay = diff.localValue === null || diff.localValue === undefined || diff.localValue === ''
+ ? "(empty)"
+ : diff.uom ? `${diff.localValue} ${diff.uom}` : diff.localValue;
+
+ // SEDP value is displayed as-is
+ const sedpDisplay = diff.sedpValue === null || diff.sedpValue === undefined || diff.sedpValue === ''
+ ? "(empty)"
+ : diff.sedpValue;
+
+ // Set cell values
+ row.getCell('tagNo').value = item.tagNo;
+ row.getCell('tagDesc').value = item.tagDesc;
+ row.getCell('attribute').value = diff.label;
+ row.getCell('localValue').value = localDisplay;
+ row.getCell('sedpValue').value = sedpDisplay;
- // SEDP value is displayed as-is
- const sedpDisplay = diff.sedpValue === null || diff.sedpValue === undefined || diff.sedpValue === ''
- ? "(empty)"
- : diff.sedpValue;
+ // Style the row
+ row.getCell('localValue').font = { color: { argb: 'FFFF0000' } }; // Red for local value
+ row.getCell('sedpValue').font = { color: { argb: 'FF008000' } }; // Green for SEDP value
+
+ // Add borders
+ row.eachCell((cell) => {
+ cell.border = {
+ top: { style: 'thin' },
+ left: { style: 'thin' },
+ bottom: { style: 'thin' },
+ right: { style: 'thin' }
+ };
+ });
+ });
- // Set cell values
- row.getCell('tagNo').value = item.tagNo;
- row.getCell('tagDesc').value = item.tagDesc;
- row.getCell('attribute').value = diff.label;
- row.getCell('localValue').value = localDisplay;
- row.getCell('sedpValue').value = sedpDisplay;
+ // Add a blank row after each tag for better readability
+ rowIndex++;
+ });
+ }
+
+ // Add a worksheet for missing tags if there are any
+ if (hasMissingTags) {
+ const missingWorksheet = workbook.addWorksheet('누락된 태그');
+
+ // Add headers
+ missingWorksheet.columns = [
+ { header: 'Tag Number', key: 'tagNo', width: 20 },
+ { header: 'Tag Description', key: 'tagDesc', width: 30 },
+ { header: 'Status', key: 'status', width: 20 }
+ ];
+
+ // Style the header row
+ const headerRow = missingWorksheet.getRow(1);
+ headerRow.eachCell((cell) => {
+ cell.font = { bold: true };
+ cell.fill = {
+ type: 'pattern',
+ pattern: 'solid',
+ fgColor: { argb: 'FFE0E0E0' }
+ };
+ cell.border = {
+ top: { style: 'thin' },
+ left: { style: 'thin' },
+ bottom: { style: 'thin' },
+ right: { style: 'thin' }
+ };
+ });
+
+ // Add local-only tags
+ let rowIndex = 2;
+ missingTags.localOnly.forEach(tag => {
+ const row = missingWorksheet.getRow(rowIndex++);
- // Style the row
- row.getCell('localValue').font = { color: { argb: 'FFFF0000' } }; // Red for local value
- row.getCell('sedpValue').font = { color: { argb: 'FF008000' } }; // Green for SEDP value
+ row.getCell('tagNo').value = tag.tagNo;
+ row.getCell('tagDesc').value = tag.tagDesc;
+ row.getCell('status').value = '로컬에만 존재';
+
+ // Style the status cell
+ row.getCell('status').font = { color: { argb: 'FFFF8C00' } }; // Orange for local-only
// Add borders
row.eachCell((cell) => {
@@ -114,9 +176,33 @@ export function ExcelDownload({ comparisonResults, formCode, disabled }: ExcelDo
});
});
- // Add a blank row after each tag for better readability
- rowIndex++;
- });
+ // Add a blank row
+ if (missingTags.localOnly.length > 0 && missingTags.sedpOnly.length > 0) {
+ rowIndex++;
+ }
+
+ // Add SEDP-only tags
+ missingTags.sedpOnly.forEach(tag => {
+ const row = missingWorksheet.getRow(rowIndex++);
+
+ row.getCell('tagNo').value = tag.tagNo;
+ row.getCell('tagDesc').value = tag.tagDesc;
+ row.getCell('status').value = 'SEDP에만 존재';
+
+ // Style the status cell
+ row.getCell('status').font = { color: { argb: 'FF0000FF' } }; // Blue for SEDP-only
+
+ // Add borders
+ row.eachCell((cell) => {
+ cell.border = {
+ top: { style: 'thin' },
+ left: { style: 'thin' },
+ bottom: { style: 'thin' },
+ right: { style: 'thin' }
+ };
+ });
+ });
+ }
// Generate Excel file
const buffer = await workbook.xlsx.writeBuffer();
@@ -128,7 +214,7 @@ export function ExcelDownload({ comparisonResults, formCode, disabled }: ExcelDo
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
- a.download = `SEDP_Differences_${formCode}_${new Date().toISOString().slice(0, 10)}.xlsx`;
+ a.download = `SEDP_차이점_${formCode}_${new Date().toISOString().slice(0, 10)}.xlsx`;
document.body.appendChild(a);
a.click();
@@ -136,7 +222,7 @@ export function ExcelDownload({ comparisonResults, formCode, disabled }: ExcelDo
window.URL.revokeObjectURL(url);
document.body.removeChild(a);
- toast.success("차이점 Excel 다운로드 완료");
+ toast.success("Excel 다운로드 완료");
} catch (error) {
console.error("Error exporting to Excel:", error);
toast.error("Excel 다운로드 실패");
@@ -145,11 +231,16 @@ export function ExcelDownload({ comparisonResults, formCode, disabled }: ExcelDo
}
};
+ // Determine if there are any differences or missing tags
+ const hasDifferences = comparisonResults.some(item => !item.isMatching);
+ const hasMissingTags = missingTags && (missingTags.localOnly.length > 0 || missingTags.sedpOnly.length > 0);
+ const hasExportableContent = hasDifferences || hasMissingTags;
+
return (
<Button
variant="secondary"
onClick={handleExportDifferences}
- disabled={disabled || isExporting}
+ disabled={disabled || isExporting || !hasExportableContent}
className="flex items-center gap-2"
>
{isExporting ? (