From 7c840cae5f1e44dc46afd790464a520ed2693085 Mon Sep 17 00:00:00 2001 From: Jorge Rojas Date: Mon, 13 Jan 2025 11:39:27 -0400 Subject: [PATCH 1/5] fix: undo mark to delete row --- components/results_table.go | 1 + 1 file changed, 1 insertion(+) diff --git a/components/results_table.go b/components/results_table.go index 8e9f7f7..1fae64d 100644 --- a/components/results_table.go +++ b/components/results_table.go @@ -439,6 +439,7 @@ func (table *ResultsTable) tableInputCapture(event *tcell.EventKey) *tcell.Event } } else { table.AppendNewChange(models.DMLDeleteType, selectedRowIndex, -1, models.CellValue{}) + table.AppendNewChange(models.DMLDeleteType, selectedRowIndex, -1, models.CellValue{TableColumnIndex: -1, TableRowIndex: selectedRowIndex}) } } From eb408f2fbb13c161fc4b8a1aa2900ad5d631e19d Mon Sep 17 00:00:00 2001 From: Jorge Rojas Date: Mon, 13 Jan 2025 12:10:02 -0400 Subject: [PATCH 2/5] fix: delete appended rows --- components/results_table.go | 40 +++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/components/results_table.go b/components/results_table.go index 1fae64d..f934b68 100644 --- a/components/results_table.go +++ b/components/results_table.go @@ -301,6 +301,10 @@ func (table *ResultsTable) AppendNewRow(cells []models.CellValue, index int, UUI for i, cell := range cells { tableCell := tview.NewTableCell(cell.Value.(string)) tableCell.SetExpansion(1) + // Appended rows have a reference to the row UUID so we can identify them later + // Also, rows that have columns marked to be UPDATED will have a reference to the type of the new value (NULL, EMPTY, DEFAULT) + // So, the cell reference will be used to determine if the row/column is an inserted row or if it's an UPDATED row + // I'm sure there is a better way to do this, but it works for now tableCell.SetReference(UUID) tableCell.SetTextColor(app.Styles.PrimaryTextColor) tableCell.SetBackgroundColor(tcell.ColorDarkGreen) @@ -415,17 +419,8 @@ func (table *ResultsTable) tableInputCapture(event *tcell.EventKey) *tcell.Event } } else if command == commands.Delete { if table.Menu.GetSelectedOption() == 1 { - isAnInsertedRow := false - indexOfInsertedRow := -1 - for i, insertedRow := range *table.state.listOfDBChanges { - cellReference := table.GetCell(selectedRowIndex, 0).GetReference() - - if cellReference != nil && insertedRow.PrimaryKeyInfo[0].Value == cellReference { - isAnInsertedRow = true - indexOfInsertedRow = i - } - } + isAnInsertedRow, indexOfInsertedRow := table.isAnInsertedRow(selectedRowIndex) if isAnInsertedRow { *table.state.listOfDBChanges = append((*table.state.listOfDBChanges)[:indexOfInsertedRow], (*table.state.listOfDBChanges)[indexOfInsertedRow+1:]...) @@ -438,7 +433,6 @@ func (table *ResultsTable) tableInputCapture(event *tcell.EventKey) *tcell.Event } } } else { - table.AppendNewChange(models.DMLDeleteType, selectedRowIndex, -1, models.CellValue{}) table.AppendNewChange(models.DMLDeleteType, selectedRowIndex, -1, models.CellValue{TableColumnIndex: -1, TableRowIndex: selectedRowIndex}) } @@ -1049,11 +1043,11 @@ func (table *ResultsTable) AppendNewChange(changeType models.DMLType, rowIndex i dmlChangeAlreadyExists := false // If the column has a reference, it means it's an inserted rowIndex - // These is maybe a better way to detect it is an inserted row + // There is maybe a better way to detect it is an inserted row tableCell := table.GetCell(rowIndex, colIndex) tableCellReference := tableCell.GetReference() - isAnInsertedRow := tableCellReference != nil && tableCellReference.(string) != "NULL&" && tableCellReference.(string) != "EMPTY&" && tableCellReference.(string) != "DEFAULT&" + isAnInsertedRow, _ := table.isAnInsertedRow(rowIndex) if isAnInsertedRow { table.MutateInsertedRowCell(tableCellReference.(string), value) @@ -1376,3 +1370,23 @@ func (table *ResultsTable) UpdateSidebar() { } } + +func (table *ResultsTable) isAnInsertedRow(rowIndex int) (isAnInsertedRow bool, DBChangeIndex int) { + for i, dmlChange := range *table.state.listOfDBChanges { + values := dmlChange.Values + + for _, value := range values { + if value.TableRowIndex == rowIndex { + cellReference := table.GetCell(rowIndex, 0).GetReference() + + isAnInsertedRow := cellReference != nil && cellReference.(string) != "NULL&" && cellReference.(string) != "EMPTY&" && cellReference.(string) != "DEFAULT&" + + if isAnInsertedRow { + return true, i + } + } + } + + } + return false, -1 +} From 1c592d839189784bcb3ea629b18ac44be041bd61 Mon Sep 17 00:00:00 2001 From: Jorge Rojas Date: Mon, 13 Jan 2025 12:50:47 -0400 Subject: [PATCH 3/5] fix: keep changed cell color state --- components/results_table.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/components/results_table.go b/components/results_table.go index f934b68..0f7ece7 100644 --- a/components/results_table.go +++ b/components/results_table.go @@ -346,6 +346,7 @@ func (table *ResultsTable) tableInputCapture(event *tcell.EventKey) *tcell.Event case commands.RecordsMenu: table.Menu.SetSelectedOption(1) table.UpdateRows(table.GetRecords()) + table.colorChangedCells() table.AddInsertedRows() case commands.ColumnsMenu: table.Menu.SetSelectedOption(2) @@ -744,6 +745,7 @@ func (table *ResultsTable) GetPrimaryKeyColumnNames() []string { func (table *ResultsTable) SetRecords(rows [][]string) { table.state.records = rows table.UpdateRows(rows) + table.colorChangedCells() } func (table *ResultsTable) SetColumns(columns [][]string) { @@ -1390,3 +1392,16 @@ func (table *ResultsTable) isAnInsertedRow(rowIndex int) (isAnInsertedRow bool, } return false, -1 } + +func (table *ResultsTable) colorChangedCells() { + for _, dmlChange := range *table.state.listOfDBChanges { + switch dmlChange.Type { + case models.DMLDeleteType: + table.SetRowColor(dmlChange.Values[0].TableRowIndex, colorTableDelete) + case models.DMLUpdateType: + for _, value := range dmlChange.Values { + table.SetCellColor(value.TableRowIndex, value.TableColumnIndex, colorTableChange) + } + } + } +} From b19278be52e0e3f4efbfe3dc09c6ce44bc4c225b Mon Sep 17 00:00:00 2001 From: Jorge Rojas Date: Tue, 21 Jan 2025 20:22:28 -0400 Subject: [PATCH 4/5] chore: update comment Co-authored-by: ccoVeille <3875889+ccoVeille@users.noreply.github.com> --- components/results_table.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/results_table.go b/components/results_table.go index 0f7ece7..a27a738 100644 --- a/components/results_table.go +++ b/components/results_table.go @@ -304,7 +304,7 @@ func (table *ResultsTable) AppendNewRow(cells []models.CellValue, index int, UUI // Appended rows have a reference to the row UUID so we can identify them later // Also, rows that have columns marked to be UPDATED will have a reference to the type of the new value (NULL, EMPTY, DEFAULT) // So, the cell reference will be used to determine if the row/column is an inserted row or if it's an UPDATED row - // I'm sure there is a better way to do this, but it works for now + // there might be a better way to do this, but it works for now tableCell.SetReference(UUID) tableCell.SetTextColor(app.Styles.PrimaryTextColor) tableCell.SetBackgroundColor(tcell.ColorDarkGreen) From f63c5f8468461269e7267e13a5d196a0a10b72a6 Mon Sep 17 00:00:00 2001 From: Jorge Rojas Date: Tue, 21 Jan 2025 20:26:32 -0400 Subject: [PATCH 5/5] refactor: check for inserted rows logic --- components/results_table.go | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/components/results_table.go b/components/results_table.go index a27a738..53468c1 100644 --- a/components/results_table.go +++ b/components/results_table.go @@ -1375,20 +1375,21 @@ func (table *ResultsTable) UpdateSidebar() { func (table *ResultsTable) isAnInsertedRow(rowIndex int) (isAnInsertedRow bool, DBChangeIndex int) { for i, dmlChange := range *table.state.listOfDBChanges { - values := dmlChange.Values - - for _, value := range values { - if value.TableRowIndex == rowIndex { - cellReference := table.GetCell(rowIndex, 0).GetReference() - - isAnInsertedRow := cellReference != nil && cellReference.(string) != "NULL&" && cellReference.(string) != "EMPTY&" && cellReference.(string) != "DEFAULT&" - - if isAnInsertedRow { - return true, i - } + for _, value := range dmlChange.Values { + if value.TableRowIndex != rowIndex { + continue } + cellReference := table.GetCell(rowIndex, 0).GetReference() + if cellReference == nil { + break + } + switch cellReference.(string) { + case "NULL&", "EMPTY&", "DEFAULT&": + default: + return true, i + } + break } - } return false, -1 }