Added a confirmation before querying or rescanning when dirty items
This is to avoid clobbering any dirty items.
This commit is contained in:
parent
7b194d0a19
commit
2df0fc7e27
|
@ -92,7 +92,7 @@ func (c *TableReadController) PromptForQuery() tea.Cmd {
|
||||||
return events.SetError(err)
|
return events.SetError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return func() tea.Msg {
|
return c.doIfNoneDirty(func() tea.Msg {
|
||||||
resultSet := c.state.ResultSet()
|
resultSet := c.state.ResultSet()
|
||||||
newResultSet, err := c.tableService.ScanOrQuery(context.Background(), resultSet.TableInfo, expr)
|
newResultSet, err := c.tableService.ScanOrQuery(context.Background(), resultSet.TableInfo, expr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -100,17 +100,42 @@ func (c *TableReadController) PromptForQuery() tea.Cmd {
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.setResultSetAndFilter(newResultSet, "")
|
return c.setResultSetAndFilter(newResultSet, "")
|
||||||
}
|
})
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *TableReadController) Rescan() tea.Cmd {
|
func (c *TableReadController) doIfNoneDirty(cmd tea.Cmd) tea.Cmd {
|
||||||
|
var anyDirty = false
|
||||||
|
for i := 0; i < len(c.state.ResultSet().Items()); i++ {
|
||||||
|
anyDirty = anyDirty || c.state.ResultSet().IsDirty(i)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !anyDirty {
|
||||||
|
return cmd
|
||||||
|
}
|
||||||
|
|
||||||
return func() tea.Msg {
|
return func() tea.Msg {
|
||||||
|
return events.PromptForInputMsg{
|
||||||
|
Prompt: "reset modified items? ",
|
||||||
|
OnDone: func(value string) tea.Cmd {
|
||||||
|
if value != "y" {
|
||||||
|
return events.SetStatus("operation aborted")
|
||||||
|
}
|
||||||
|
|
||||||
|
return cmd
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *TableReadController) Rescan() tea.Cmd {
|
||||||
|
return c.doIfNoneDirty(func() tea.Msg {
|
||||||
resultSet := c.state.ResultSet()
|
resultSet := c.state.ResultSet()
|
||||||
return c.doScan(context.Background(), resultSet, resultSet.Query)
|
return c.doScan(context.Background(), resultSet, resultSet.Query)
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *TableReadController) ExportCSV(filename string) tea.Cmd {
|
func (c *TableReadController) ExportCSV(filename string) tea.Cmd {
|
||||||
|
|
|
@ -62,6 +62,40 @@ func TestTableReadController_ListTables(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestTableReadController_Rescan(t *testing.T) {
|
||||||
|
client := testdynamo.SetupTestTable(t, testData)
|
||||||
|
|
||||||
|
provider := dynamo.NewProvider(client)
|
||||||
|
service := tables.NewService(provider)
|
||||||
|
state := controllers.NewState()
|
||||||
|
readController := controllers.NewTableReadController(state, service, "bravo-table")
|
||||||
|
|
||||||
|
t.Run("should perform a rescan", func(t *testing.T) {
|
||||||
|
invokeCommand(t, readController.Init())
|
||||||
|
invokeCommand(t, readController.Rescan())
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("should prompt to rescan if any dirty rows", func(t *testing.T) {
|
||||||
|
invokeCommand(t, readController.Init())
|
||||||
|
|
||||||
|
state.ResultSet().SetDirty(0, true)
|
||||||
|
|
||||||
|
invokeCommandWithPrompt(t, readController.Rescan(), "y")
|
||||||
|
|
||||||
|
assert.False(t, state.ResultSet().IsDirty(0))
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("should not rescan if any dirty rows", func(t *testing.T) {
|
||||||
|
invokeCommand(t, readController.Init())
|
||||||
|
|
||||||
|
state.ResultSet().SetDirty(0, true)
|
||||||
|
|
||||||
|
invokeCommandWithPrompt(t, readController.Rescan(), "n")
|
||||||
|
|
||||||
|
assert.True(t, state.ResultSet().IsDirty(0))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func TestTableReadController_ExportCSV(t *testing.T) {
|
func TestTableReadController_ExportCSV(t *testing.T) {
|
||||||
client := testdynamo.SetupTestTable(t, testData)
|
client := testdynamo.SetupTestTable(t, testData)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue