Skip to content

Commit 54df60a

Browse files
committed
fix: allows appending a new row to an empty table
1 parent d68a380 commit 54df60a

File tree

1 file changed

+50
-47
lines changed

1 file changed

+50
-47
lines changed

Diff for: components/ResultsTable.go

+50-47
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,60 @@ func (table *ResultsTable) tableInputCapture(event *tcell.EventKey) *tcell.Event
256256
table.UpdateRows(table.GetIndexes())
257257
}
258258
}
259+
260+
command := app.Keymaps.Group("table").Resolve(event)
261+
262+
if command == commands.AppendNewRow {
263+
if table.Menu.GetSelectedOption() == 1 {
264+
265+
newRow := make([]string, table.GetColumnCount())
266+
newRowIndex := table.GetRowCount()
267+
newRowUuid := uuid.New()
268+
269+
for i := 0; i < table.GetColumnCount(); i++ {
270+
newRow[i] = "Default"
271+
}
272+
273+
table.InsertRow(newRow, newRowIndex, newRowUuid)
274+
275+
for i := 0; i < table.GetColumnCount(); i++ {
276+
table.GetCell(newRowIndex, i).SetBackgroundColor(tcell.ColorDarkGreen)
277+
}
278+
279+
newInsert := models.DbInsert{
280+
Table: table.GetDBReference(),
281+
Columns: table.GetRecords()[0],
282+
Values: newRow,
283+
PrimaryKeyValue: newRowUuid,
284+
Option: 1,
285+
}
286+
287+
*table.state.listOfDbInserts = append(*table.state.listOfDbInserts, newInsert)
288+
289+
if table.Tree.GetCurrentNode().GetColor() == tview.Styles.InverseTextColor || table.Tree.GetCurrentNode().GetColor() == tview.Styles.PrimaryTextColor {
290+
table.Tree.GetCurrentNode().SetColor(InsertColor)
291+
} else if table.Tree.GetCurrentNode().GetColor() == DeleteColor {
292+
table.Tree.GetCurrentNode().SetColor(ChangeColor)
293+
}
294+
295+
table.Select(newRowIndex, 0)
296+
297+
App.ForceDraw()
298+
table.StartEditingCell(newRowIndex, 0, func(newValue string, row, col int) {
299+
cellReference := table.GetCell(row, 0).GetReference()
300+
301+
if cellReference != nil {
302+
table.MutateInsertedRowCell(cellReference.(uuid.UUID), col, newValue)
303+
}
304+
})
305+
306+
}
307+
}
308+
259309
if rowCount == 1 || colCount == 0 {
260310
return nil
261311
}
262312

263-
command := app.Keymaps.Group("table").Resolve(event)
264-
265313
if command == commands.Search {
266314
if table.Editor != nil {
267315
App.SetFocus(table.Editor)
@@ -432,51 +480,6 @@ func (table *ResultsTable) tableInputCapture(event *tcell.EventKey) *tcell.Event
432480
table.AppendNewChange("DELETE", table.GetDBReference(), selectedRowIndex, -1, "")
433481
}
434482

435-
}
436-
} else if command == commands.AppendNewRow {
437-
if table.Menu.GetSelectedOption() == 1 {
438-
439-
newRow := make([]string, table.GetColumnCount())
440-
newRowIndex := table.GetRowCount()
441-
newRowUuid := uuid.New()
442-
443-
for i := 0; i < table.GetColumnCount(); i++ {
444-
newRow[i] = "Default"
445-
}
446-
447-
table.InsertRow(newRow, newRowIndex, newRowUuid)
448-
449-
for i := 0; i < table.GetColumnCount(); i++ {
450-
table.GetCell(newRowIndex, i).SetBackgroundColor(tcell.ColorDarkGreen)
451-
}
452-
453-
newInsert := models.DbInsert{
454-
Table: table.GetDBReference(),
455-
Columns: table.GetRecords()[0],
456-
Values: newRow,
457-
PrimaryKeyValue: newRowUuid,
458-
Option: 1,
459-
}
460-
461-
*table.state.listOfDbInserts = append(*table.state.listOfDbInserts, newInsert)
462-
463-
if table.Tree.GetCurrentNode().GetColor() == tview.Styles.InverseTextColor || table.Tree.GetCurrentNode().GetColor() == tview.Styles.PrimaryTextColor {
464-
table.Tree.GetCurrentNode().SetColor(InsertColor)
465-
} else if table.Tree.GetCurrentNode().GetColor() == DeleteColor {
466-
table.Tree.GetCurrentNode().SetColor(ChangeColor)
467-
}
468-
469-
table.Select(newRowIndex, 1)
470-
471-
App.ForceDraw()
472-
table.StartEditingCell(newRowIndex, 1, func(newValue string, row, col int) {
473-
cellReference := table.GetCell(row, 0).GetReference()
474-
475-
if cellReference != nil {
476-
table.MutateInsertedRowCell(cellReference.(uuid.UUID), col, newValue)
477-
}
478-
})
479-
480483
}
481484
}
482485

0 commit comments

Comments
 (0)