Skip to content

Commit f5791c3

Browse files
authored
fix: copy first row due to failed falsey check (supabase#40909)
* updated because of zero falsey value not copying * test: add E2E test for copying first and second row values Adds regression test to verify that users can copy cell values from the first row (index 0) and second row. This prevents the bug where falsy index checks would prevent copying from row 0. Addresses FE-2178
1 parent 4ee5050 commit f5791c3

File tree

2 files changed

+66
-4
lines changed

2 files changed

+66
-4
lines changed

apps/studio/components/grid/components/menu/RowContextMenu.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ export const RowContextMenu = ({ rows }: RowContextMenuProps) => {
2222

2323
function onDeleteRow(p: RowContextMenuItemProps) {
2424
const rowIdx = p.props?.rowIdx
25-
if (!rowIdx) return
25+
if (rowIdx === undefined || rowIdx === null) return
2626

2727
const row = rows[rowIdx]
2828
if (row) tableEditorSnap.onDeleteRows([row])
2929
}
3030

3131
function onEditRowClick(p: RowContextMenuItemProps) {
3232
const rowIdx = p.props?.rowIdx
33-
if (!rowIdx) return
33+
if (rowIdx === undefined || rowIdx === null) return
3434

3535
const row = rows[rowIdx]
3636
tableEditorSnap.onEditRow(row)
@@ -39,7 +39,7 @@ export const RowContextMenu = ({ rows }: RowContextMenuProps) => {
3939
const onCopyCellContent = useCallback(
4040
(p: RowContextMenuItemProps) => {
4141
const rowIdx = p.props?.rowIdx
42-
if (!snap.selectedCellPosition || !rowIdx) return
42+
if (!snap.selectedCellPosition || rowIdx === undefined || rowIdx === null) return
4343

4444
const row = rows[rowIdx]
4545
const columnKey = snap.gridColumns[snap.selectedCellPosition.idx as number].key
@@ -56,7 +56,7 @@ export const RowContextMenu = ({ rows }: RowContextMenuProps) => {
5656
const onCopyRowContent = useCallback(
5757
(p: RowContextMenuItemProps) => {
5858
const rowIdx = p.props?.rowIdx
59-
if (!rowIdx) return
59+
if (rowIdx === undefined || rowIdx === null) return
6060

6161
const row = rows[rowIdx]
6262
copyToClipboard(JSON.stringify(row))

e2e/studio/features/table-editor.spec.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,4 +717,66 @@ test.describe('table editor', () => {
717717

718718
await deleteTable(page, ref, tableNameDataActions)
719719
})
720+
721+
test('copying cell values from first and second row works', async ({ page, ref }) => {
722+
const tableName = 'pw_table_copy_rows'
723+
const colName = 'pw_column'
724+
725+
// Ensure we're on editor
726+
if (!page.url().includes('/editor')) {
727+
await page.goto(toUrl(`/project/${ref}/editor?schema=public`))
728+
await waitForTableToLoad(page, ref)
729+
}
730+
731+
// Create table and add two rows
732+
await createTable(page, ref, tableName)
733+
await page.getByRole('button', { name: `View ${tableName}`, exact: true }).click()
734+
await page.waitForURL(/\/editor\/\d+\?schema=public$/)
735+
736+
// Insert first row with value 'first_row_value'
737+
await page.getByTestId('table-editor-insert-new-row').click()
738+
await page.getByRole('menuitem', { name: 'Insert row Insert a new row' }).click()
739+
await page.getByTestId(`${colName}-input`).fill('first_row_value')
740+
await page.getByTestId('action-bar-save-row').click()
741+
await waitForApiResponse(page, 'pg-meta', ref, 'query?key=', { method: 'POST' })
742+
743+
// Insert second row with value 'second_row_value'
744+
await page.getByTestId('table-editor-insert-new-row').click()
745+
await page.getByRole('menuitem', { name: 'Insert row Insert a new row' }).click()
746+
await page.getByTestId(`${colName}-input`).fill('second_row_value')
747+
await page.getByTestId('action-bar-save-row').click()
748+
await waitForApiResponse(page, 'pg-meta', ref, 'query?key=', { method: 'POST' })
749+
750+
// Wait for grid to be visible
751+
await expect(page.getByRole('grid')).toBeVisible()
752+
753+
// Right-click on the first row's cell to open context menu
754+
const firstRowCell = page.getByRole('gridcell', { name: 'first_row_value' })
755+
await expect(firstRowCell).toBeVisible()
756+
await firstRowCell.click({ button: 'right' })
757+
758+
// Click "Copy cell" from context menu
759+
await page.getByRole('menuitem', { name: 'Copy cell' }).click()
760+
await page.waitForTimeout(500)
761+
762+
// Verify first row value was copied
763+
const firstCopiedValue = await page.evaluate(() => navigator.clipboard.readText())
764+
expect(firstCopiedValue).toBe('first_row_value')
765+
766+
// Right-click on the second row's cell to open context menu
767+
const secondRowCell = page.getByRole('gridcell', { name: 'second_row_value' })
768+
await expect(secondRowCell).toBeVisible()
769+
await secondRowCell.click({ button: 'right' })
770+
771+
// Click "Copy cell" from context menu
772+
await page.getByRole('menuitem', { name: 'Copy cell' }).click()
773+
await page.waitForTimeout(500)
774+
775+
// Verify second row value was copied
776+
const secondCopiedValue = await page.evaluate(() => navigator.clipboard.readText())
777+
expect(secondCopiedValue).toBe('second_row_value')
778+
779+
// Cleanup
780+
await deleteTable(page, ref, tableName)
781+
})
720782
})

0 commit comments

Comments
 (0)