From 8d4e651031314907064ebe33e3fcb3f3f90be288 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Thu, 7 Aug 2025 14:43:23 +0000 Subject: [PATCH] Enhance spreadsheet import to support source and target content columns Co-authored-by: ryderwishart --- .../spreadsheet/SpreadsheetImporterForm.tsx | 89 +++++++++++++------ 1 file changed, 63 insertions(+), 26 deletions(-) diff --git a/webviews/codex-webviews/src/NewSourceUploader/importers/spreadsheet/SpreadsheetImporterForm.tsx b/webviews/codex-webviews/src/NewSourceUploader/importers/spreadsheet/SpreadsheetImporterForm.tsx index 5a9721b79..d8f527195 100644 --- a/webviews/codex-webviews/src/NewSourceUploader/importers/spreadsheet/SpreadsheetImporterForm.tsx +++ b/webviews/codex-webviews/src/NewSourceUploader/importers/spreadsheet/SpreadsheetImporterForm.tsx @@ -185,27 +185,53 @@ export const SpreadsheetImporterForm: React.FC = (props) setShowPreview(true); } else { // Source import - create notebook pair - const sourceCells = parsedData.rows - .filter((row) => row[parseInt(sourceColumnIndex!)]?.trim()) - .map((row, index) => { - const id = idColumnIndex - ? row[parseInt(idColumnIndex)]?.trim() || - createCellId(parsedData.filename, index) - : createCellId(parsedData.filename, index); - - return { + // Get all rows that have content in at least one of the selected columns + const relevantRows = parsedData.rows.filter((row, index) => { + const hasSourceContent = sourceColumnIndex && row[parseInt(sourceColumnIndex)]?.trim(); + const hasTargetContent = targetColumnIndex && row[parseInt(targetColumnIndex)]?.trim(); + return hasSourceContent || hasTargetContent; + }); + + const sourceCells = relevantRows.map((row, index) => { + const id = idColumnIndex + ? row[parseInt(idColumnIndex)]?.trim() || + createCellId(parsedData.filename, index) + : createCellId(parsedData.filename, index); + + return { + id, + content: sourceColumnIndex ? (row[parseInt(sourceColumnIndex)] || "") : "", + images: [], + metadata: { id, - content: row[parseInt(sourceColumnIndex!)], - images: [], - metadata: { - id, - data: { - rowIndex: index, - originalRow: row, - }, + data: { + rowIndex: index, + originalRow: row, }, - }; - }); + }, + }; + }); + + // Create target cells - use target column content if available, otherwise empty + const targetCells = relevantRows.map((row, index) => { + const id = idColumnIndex + ? row[parseInt(idColumnIndex)]?.trim() || + createCellId(parsedData.filename, index) + : createCellId(parsedData.filename, index); + + return { + id, + content: targetColumnIndex ? (row[parseInt(targetColumnIndex)] || "") : "", + images: [], + metadata: { + id, + data: { + rowIndex: index, + originalRow: row, + }, + }, + }; + }); const notebookPair: NotebookPair = { source: { @@ -223,10 +249,7 @@ export const SpreadsheetImporterForm: React.FC = (props) }, codex: { name: parsedData.filename, - cells: sourceCells.map((cell) => ({ - ...cell, - content: "", // Empty target cells - })), + cells: targetCells, metadata: { id: parsedData.filename, originalFileName: selectedFile!.name, @@ -275,7 +298,7 @@ export const SpreadsheetImporterForm: React.FC = (props) {isTranslationImport ? `Tell us which column contains the translations for "${selectedSource?.name}"` - : "Tell us which columns contain your content"} + : "Tell us which columns contain your content. You can select both source and target columns to import both at once."} @@ -331,6 +354,20 @@ export const SpreadsheetImporterForm: React.FC = (props) )} + {!isTranslationImport && ( + 0 && + columnMapping[column.index] !== "target" + } + > +
+ + Target Content +
+
+ )} {isTranslationImport && ( = (props) {getColumnTypeCount("target") > 0 && ( - Translation + {isTranslationImport ? "Translation" : "Target Content"} )} @@ -419,7 +456,7 @@ export const SpreadsheetImporterForm: React.FC = (props) {isTranslationImport ? "Choose a CSV or TSV file containing translations that match your source content" - : "Choose a CSV or TSV file to import as source content and create a translation workspace"} + : "Choose a CSV or TSV file to import as source content and create a translation workspace. You can optionally include target content if your spreadsheet has both columns."}