Skip to content

Commit 35cdc0b

Browse files
Copilothotlong
andcommitted
Fix code review feedback: simplify startEdit and fix test selector
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 86220c0 commit 35cdc0b

2 files changed

Lines changed: 9 additions & 10 deletions

File tree

packages/components/src/renderers/complex/__tests__/data-table-batch-editing.test.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,10 @@ describe('Data Table - Batch Editing', () => {
7171
expect(modifiedIndicator).toBeInTheDocument();
7272
});
7373

74-
// Edit second cell in same row - now the name shows as 'John Smith'
75-
const emailCell = container.querySelector('td:has-text("john@example.com")') ||
76-
Array.from(container.querySelectorAll('td')).find(el =>
77-
el.textContent?.includes('john@example.com')
78-
);
74+
// Edit second cell in same row - find by searching through all cells
75+
const emailCell = Array.from(container.querySelectorAll('td')).find(el =>
76+
el.textContent?.includes('john@example.com')
77+
);
7978

8079
expect(emailCell).toBeInTheDocument();
8180
if (emailCell) {

packages/components/src/renderers/complex/data-table.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -350,16 +350,17 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => {
350350
};
351351

352352
// Cell editing handlers
353-
const startEdit = (rowIndex: number, columnKey: string, currentValue: any) => {
353+
const startEdit = (rowIndex: number, columnKey: string) => {
354354
if (!editable) return;
355355

356356
const column = columns.find(col => col.accessorKey === columnKey);
357357
if (column?.editable === false) return;
358358

359359
setEditingCell({ rowIndex, columnKey });
360360

361-
// Check if there's a pending change for this cell
361+
// Check if there's a pending change for this cell, otherwise use current data value
362362
const rowChanges = pendingChanges.get(rowIndex);
363+
const currentValue = paginatedData[rowIndex][columnKey];
363364
const valueToEdit = rowChanges?.[columnKey] ?? currentValue ?? '';
364365
setEditValue(valueToEdit);
365366
};
@@ -461,8 +462,7 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => {
461462

462463
if (e.key === 'Enter' && !editingCell) {
463464
e.preventDefault();
464-
const value = paginatedData[rowIndex][columnKey];
465-
startEdit(rowIndex, columnKey, value);
465+
startEdit(rowIndex, columnKey);
466466
}
467467
};
468468

@@ -707,7 +707,7 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => {
707707
minWidth: columnWidth,
708708
maxWidth: columnWidth
709709
}}
710-
onDoubleClick={() => isEditable && startEdit(rowIndex, col.accessorKey, originalValue)}
710+
onDoubleClick={() => isEditable && startEdit(rowIndex, col.accessorKey)}
711711
onKeyDown={(e) => handleCellKeyDown(e, rowIndex, col.accessorKey)}
712712
tabIndex={0}
713713
>

0 commit comments

Comments
 (0)