From 7ae99b009bd41ba059906d87d4dda76d04828e20 Mon Sep 17 00:00:00 2001 From: Leon Mika Date: Fri, 23 May 2025 22:04:41 +1000 Subject: [PATCH] ucl: added rs:set --- cmd/dynamo-browse/main.go | 20 +- .../common/ui/commandctrl/cmdpacks/modrs.go | 78 ++++++- .../common/ui/commandctrl/cmdpacks/modui.go | 195 ++++++++++++++++++ .../common/ui/commandctrl/cmdpacks/stdcmds.go | 25 +++ .../ui/commandctrl/cmdpacks/stdcmds_test.go | 13 +- internal/common/ui/commandctrl/commandctrl.go | 23 ++- internal/common/ui/commandctrl/ctx.go | 39 +++- internal/common/ui/events/resultset.go | 5 + internal/dynamo-browse/controllers/events.go | 8 - .../dynamo-browse/controllers/keybinding.go | 4 + .../dynamo-browse/controllers/tableread.go | 30 ++- .../dynamo-browse/controllers/tablewrite.go | 20 +- internal/dynamo-browse/ui/model.go | 6 +- 13 files changed, 400 insertions(+), 66 deletions(-) create mode 100644 internal/common/ui/commandctrl/cmdpacks/modui.go create mode 100644 internal/common/ui/events/resultset.go diff --git a/cmd/dynamo-browse/main.go b/cmd/dynamo-browse/main.go index aeaf4eb..862941d 100644 --- a/cmd/dynamo-browse/main.go +++ b/cmd/dynamo-browse/main.go @@ -158,18 +158,18 @@ func main() { } keyBindingService := keybindings_service.NewService(keyBindings) - keyBindingController := controllers.NewKeyBindingController(keyBindingService, scriptController) + keyBindingController := controllers.NewKeyBindingController(keyBindingService, nil) - commandController := commandctrl.NewCommandController(inputHistoryService, - cmdpacks.StandardCommands{ - TableService: tableService, - State: state, - ReadController: tableReadController, - WriteController: tableWriteController, - ExportController: exportController, - KeyBindingController: keyBindingController, - }, + stdCommands := cmdpacks.NewStandardCommands( + tableService, + state, + tableReadController, + tableWriteController, + exportController, + keyBindingController, ) + + commandController := commandctrl.NewCommandController(inputHistoryService, stdCommands) commandController.AddCommandLookupExtension(scriptController) commandController.SetCommandCompletionProvider(columnsController) diff --git a/internal/common/ui/commandctrl/cmdpacks/modrs.go b/internal/common/ui/commandctrl/cmdpacks/modrs.go index eea66b4..407120c 100644 --- a/internal/common/ui/commandctrl/cmdpacks/modrs.go +++ b/internal/common/ui/commandctrl/cmdpacks/modrs.go @@ -3,6 +3,7 @@ package cmdpacks import ( "context" "github.com/aws/aws-sdk-go-v2/service/dynamodb/types" + "github.com/lmika/dynamo-browse/internal/common/ui/commandctrl" "github.com/lmika/dynamo-browse/internal/dynamo-browse/controllers" "github.com/lmika/dynamo-browse/internal/dynamo-browse/models" "github.com/lmika/dynamo-browse/internal/dynamo-browse/models/queryexpr" @@ -65,21 +66,26 @@ var rsQueryDoc = repl.Doc{ `, } -func (rs *rsModule) rsQuery(ctx context.Context, args ucl.CallArgs) (any, error) { +func parseQuery( + ctx context.Context, + args ucl.CallArgs, + currentRS *models.ResultSet, + tablesService *tables.Service, +) (*queryexpr.QueryExpr, *models.TableInfo, error) { var expr string if err := args.Bind(&expr); err != nil { - return nil, err + return nil, nil, err } q, err := queryexpr.Parse(expr) if err != nil { - return nil, err + return nil, nil, err } if args.NArgs() > 0 { var queryArgs ucl.Hashable if err := args.Bind(&queryArgs); err != nil { - return nil, err + return nil, nil, err } queryNames := map[string]string{} @@ -108,17 +114,26 @@ func (rs *rsModule) rsQuery(ctx context.Context, args ucl.CallArgs) (any, error) if args.HasSwitch("table") { var tblName string if err := args.BindSwitch("table", &tblName); err != nil { - return nil, err + return nil, nil, err } - tableInfo, err = rs.tableService.Describe(ctx, tblName) + tableInfo, err = tablesService.Describe(ctx, tblName) if err != nil { - return nil, err + return nil, nil, err } - } else if currRs := rs.state.ResultSet(); currRs != nil && currRs.TableInfo != nil { - tableInfo = currRs.TableInfo + } else if currentRS != nil && currentRS.TableInfo != nil { + tableInfo = currentRS.TableInfo } else { - return nil, errors.New("no table specified") + return nil, nil, errors.New("no table specified") + } + + return q, tableInfo, nil +} + +func (rs *rsModule) rsQuery(ctx context.Context, args ucl.CallArgs) (any, error) { + q, tableInfo, err := parseQuery(ctx, args, rs.state.ResultSet(), rs.tableService) + if err != nil { + return nil, err } newResultSet, err := rs.tableService.ScanOrQuery(context.Background(), tableInfo, q, nil) @@ -167,6 +182,20 @@ func (rs *rsModule) rsScan(ctx context.Context, args ucl.CallArgs) (_ any, err e return newResultSetProxy(newResultSet), nil } +func (rs *rsModule) rsFilter(ctx context.Context, args ucl.CallArgs) (any, error) { + var ( + rsProxy SimpleProxy[*models.ResultSet] + filter string + ) + + if err := args.Bind(&rsProxy, &filter); err != nil { + return nil, err + } + + newResultSet := rs.tableService.Filter(rsProxy.ProxyValue(), filter) + return newResultSetProxy(newResultSet), nil +} + var rsNextPageDoc = repl.Doc{ Brief: "Returns the next page of the passed in result-set", Usage: "RESULT_SET", @@ -207,6 +236,33 @@ func (rs *rsModule) rsUnion(ctx context.Context, args ucl.CallArgs) (_ any, err return newResultSetProxy(rsProxy1.ProxyValue().MergeWith(rsProxy2.ProxyValue())), nil } +func (rs *rsModule) rsSet(ctx context.Context, args ucl.CallArgs) (_ any, err error) { + var ( + item itemProxy + expr string + val ucl.Object + ) + + if err := args.Bind(&item, &expr, &val); err != nil { + return nil, err + } + + q, err := queryexpr.Parse(expr) + if err != nil { + return nil, err + } + + // TEMP + if err := q.SetEvalItem(item.item, &types.AttributeValueMemberS{Value: val.String()}); err != nil { + return nil, err + } + item.resultSet.SetDirty(item.idx, true) + commandctrl.QueueRefresh(ctx) + // END TEMP + + return item, nil +} + func moduleRS(tableService *tables.Service, state *controllers.State) ucl.Module { m := &rsModule{ tableService: tableService, @@ -219,8 +275,10 @@ func moduleRS(tableService *tables.Service, state *controllers.State) ucl.Module "new": m.rsNew, "query": m.rsQuery, "scan": m.rsScan, + "filter": m.rsFilter, "next-page": m.rsNextPage, "union": m.rsUnion, + "set": m.rsSet, }, } } diff --git a/internal/common/ui/commandctrl/cmdpacks/modui.go b/internal/common/ui/commandctrl/cmdpacks/modui.go new file mode 100644 index 0000000..6bcd6ce --- /dev/null +++ b/internal/common/ui/commandctrl/cmdpacks/modui.go @@ -0,0 +1,195 @@ +package cmdpacks + +import ( + "context" + tea "github.com/charmbracelet/bubbletea" + "github.com/lmika/dynamo-browse/internal/common/ui/commandctrl" + "github.com/lmika/dynamo-browse/internal/common/ui/events" + "github.com/lmika/dynamo-browse/internal/dynamo-browse/controllers" + "github.com/lmika/dynamo-browse/internal/dynamo-browse/services/tables" + "ucl.lmika.dev/ucl" +) + +type uiModule struct { + tableService *tables.Service + state *controllers.State + ckb *customKeyBinding + readController *controllers.TableReadController +} + +func (m *uiModule) uiPrompt(ctx context.Context, args ucl.CallArgs) (any, error) { + var prompt string + if err := args.Bind(&prompt); err != nil { + return nil, err + } + + resChan := make(chan string) + go func() { + commandctrl.PostMsg(ctx, events.PromptForInput(prompt, nil, func(value string) tea.Msg { + resChan <- value + return nil + })) + }() + + select { + case value := <-resChan: + return value, nil + case <-ctx.Done(): + return nil, ctx.Err() + } +} + +func (m *uiModule) uiConfirm(ctx context.Context, args ucl.CallArgs) (any, error) { + var prompt string + if err := args.Bind(&prompt); err != nil { + return nil, err + } + + resChan := make(chan bool) + go func() { + commandctrl.PostMsg(ctx, events.Confirm(prompt, func(value bool) tea.Msg { + resChan <- value + return nil + })) + }() + + select { + case value := <-resChan: + return value, nil + case <-ctx.Done(): + return nil, ctx.Err() + } +} + +func (m *uiModule) uiPromptTable(ctx context.Context, args ucl.CallArgs) (any, error) { + tables, err := m.tableService.ListTables(context.Background()) + if err != nil { + return nil, err + } + + resChan := make(chan string) + go func() { + commandctrl.PostMsg(ctx, controllers.PromptForTableMsg{ + Tables: tables, + OnSelected: func(tableName string) tea.Msg { + resChan <- tableName + return nil + }, + }) + }() + + select { + case value := <-resChan: + return value, nil + case <-ctx.Done(): + return nil, ctx.Err() + } +} + +func (m *uiModule) uiBind(ctx context.Context, args ucl.CallArgs) (any, error) { + var ( + bindName string + key string + inv ucl.Invokable + ) + + if args.NArgs() == 2 { + if err := args.Bind(&key, &inv); err != nil { + return nil, err + } + bindName = "custom." + key + } else { + if err := args.Bind(&bindName, &key, &inv); err != nil { + return nil, err + } + } + + invoker := commandctrl.GetInvoker(ctx) + + m.ckb.bindings[bindName] = func() tea.Msg { + return invoker.Invoke(inv, nil) + } + m.ckb.keyBindings[key] = bindName + return nil, nil +} + +func (m *uiModule) uiQuery(ctx context.Context, args ucl.CallArgs) (any, error) { + q, tableInfo, err := parseQuery(ctx, args, m.state.ResultSet(), m.tableService) + if err != nil { + return nil, err + } + + commandctrl.PostMsg(ctx, m.readController.RunQuery(q, tableInfo)) + return nil, nil +} + +func (m *uiModule) uiFilter(ctx context.Context, args ucl.CallArgs) (any, error) { + var filter string + + if err := args.Bind(&filter); err != nil { + return nil, err + } + + commandctrl.PostMsg(ctx, m.readController.Filter(filter)) + return nil, nil +} + +func moduleUI( + tableService *tables.Service, + state *controllers.State, + readController *controllers.TableReadController, +) (ucl.Module, controllers.CustomKeyBindingSource) { + m := &uiModule{ + tableService: tableService, + state: state, + readController: readController, + ckb: &customKeyBinding{ + bindings: map[string]tea.Cmd{}, + keyBindings: map[string]string{}, + }, + } + + return ucl.Module{ + Name: "ui", + Builtins: map[string]ucl.BuiltinHandler{ + "prompt": m.uiPrompt, + "prompt-table": m.uiPromptTable, + "confirm": m.uiConfirm, + "query": m.uiQuery, + "filter": m.uiFilter, + "bind": m.uiBind, + }, + }, m.ckb +} + +type customKeyBinding struct { + bindings map[string]tea.Cmd + keyBindings map[string]string +} + +func (c *customKeyBinding) LookupBinding(theKey string) string { + return c.keyBindings[theKey] +} + +func (c *customKeyBinding) CustomKeyCommand(key string) tea.Cmd { + bindingName, ok := c.keyBindings[key] + if !ok { + return nil + } + + binding, ok := c.bindings[bindingName] + if !ok { + return nil + } + + return binding +} + +func (c *customKeyBinding) UnbindKey(key string) { + delete(c.keyBindings, key) +} + +func (c *customKeyBinding) Rebind(bindingName string, newKey string) error { + c.keyBindings[newKey] = bindingName + return nil +} diff --git a/internal/common/ui/commandctrl/cmdpacks/stdcmds.go b/internal/common/ui/commandctrl/cmdpacks/stdcmds.go index e5c1aab..73d2c9c 100644 --- a/internal/common/ui/commandctrl/cmdpacks/stdcmds.go +++ b/internal/common/ui/commandctrl/cmdpacks/stdcmds.go @@ -19,6 +19,30 @@ type StandardCommands struct { WriteController *controllers.TableWriteController ExportController *controllers.ExportController KeyBindingController *controllers.KeyBindingController + + modUI ucl.Module +} + +func NewStandardCommands( + tableService *tables.Service, + state *controllers.State, + readController *controllers.TableReadController, + writeController *controllers.TableWriteController, + exportController *controllers.ExportController, + keyBindingController *controllers.KeyBindingController, +) StandardCommands { + modUI, ckbs := moduleUI(tableService, state, readController) + keyBindingController.SetCustomKeyBindingSource(ckbs) + + return StandardCommands{ + TableService: tableService, + State: state, + ReadController: readController, + WriteController: writeController, + ExportController: exportController, + KeyBindingController: keyBindingController, + modUI: modUI, + } } var cmdQuitDoc = repl.Doc{ @@ -364,6 +388,7 @@ func (sc StandardCommands) cmdRebind(ctx context.Context, args ucl.CallArgs) (an func (sc StandardCommands) InstOptions() []ucl.InstOption { return []ucl.InstOption{ ucl.WithModule(moduleRS(sc.TableService, sc.State)), + ucl.WithModule(sc.modUI), } } diff --git a/internal/common/ui/commandctrl/cmdpacks/stdcmds_test.go b/internal/common/ui/commandctrl/cmdpacks/stdcmds_test.go index 44aff3e..228c6be 100644 --- a/internal/common/ui/commandctrl/cmdpacks/stdcmds_test.go +++ b/internal/common/ui/commandctrl/cmdpacks/stdcmds_test.go @@ -14,8 +14,10 @@ import ( "github.com/lmika/dynamo-browse/internal/dynamo-browse/services/inputhistory" "github.com/lmika/dynamo-browse/internal/dynamo-browse/services/itemrenderer" "github.com/lmika/dynamo-browse/internal/dynamo-browse/services/jobs" + keybindings_service "github.com/lmika/dynamo-browse/internal/dynamo-browse/services/keybindings" "github.com/lmika/dynamo-browse/internal/dynamo-browse/services/tables" "github.com/lmika/dynamo-browse/internal/dynamo-browse/services/viewsnapshot" + "github.com/lmika/dynamo-browse/internal/dynamo-browse/ui/keybindings" "github.com/lmika/dynamo-browse/test/testdynamo" "github.com/lmika/dynamo-browse/test/testworkspace" bus "github.com/lmika/events" @@ -132,15 +134,12 @@ func newService(t *testing.T, opts ...serviceOpt) *services { columnsController := controllers.NewColumnsController(readController, eventBus) exportController := controllers.NewExportController(state, service, jobsController, columnsController, pasteboardprovider.NilProvider{}) + keyBindingService := keybindings_service.NewService(keybindings.Default()) + keyBindingController := controllers.NewKeyBindingController(keyBindingService, nil) + _ = settingsController commandController := commandctrl.NewCommandController(inputHistoryService, - cmdpacks.StandardCommands{ - State: state, - TableService: service, - ReadController: readController, - WriteController: writeController, - ExportController: exportController, - }, + cmdpacks.NewStandardCommands(service, state, readController, writeController, exportController, keyBindingController), ) s.State = state diff --git a/internal/common/ui/commandctrl/commandctrl.go b/internal/common/ui/commandctrl/commandctrl.go index 79847f0..d4de9be 100644 --- a/internal/common/ui/commandctrl/commandctrl.go +++ b/internal/common/ui/commandctrl/commandctrl.go @@ -139,8 +139,26 @@ func (c *CommandController) ExecuteAndWait(ctx context.Context, commandInput str return c.uclInst.Eval(ctx, commandInput) } +func (c *CommandController) Invoke(invokable ucl.Invokable, args []any) (msg tea.Msg) { + execCtx := execContext{ctrl: c} + ctx := context.WithValue(context.Background(), commandCtlKey, &execCtx) + + res, err := invokable.Invoke(ctx, args) + if err != nil { + msg = events.Error(err) + } else if res != nil { + msg = events.StatusMsg(fmt.Sprint(res)) + } + if execCtx.requestRefresh { + c.postMessage(events.ResultSetUpdated{}) + } + + return msg +} + func (c *CommandController) cmdLooper() { - ctx := context.WithValue(context.Background(), commandCtlKey, c) + execCtx := execContext{ctrl: c} + ctx := context.WithValue(context.Background(), commandCtlKey, &execCtx) for { select { @@ -151,6 +169,9 @@ func (c *CommandController) cmdLooper() { } else if res != nil { c.postMessage(events.StatusMsg(fmt.Sprint(res))) } + if execCtx.requestRefresh { + c.postMessage(events.ResultSetUpdated{}) + } } } } diff --git a/internal/common/ui/commandctrl/ctx.go b/internal/common/ui/commandctrl/ctx.go index 7fc70ea..fef635b 100644 --- a/internal/common/ui/commandctrl/ctx.go +++ b/internal/common/ui/commandctrl/ctx.go @@ -3,33 +3,60 @@ package commandctrl import ( "context" tea "github.com/charmbracelet/bubbletea" + "ucl.lmika.dev/ucl" ) type commandCtlKeyType struct{} var commandCtlKey = commandCtlKeyType{} +type execContext struct { + ctrl *CommandController + requestRefresh bool +} + func PostMsg(ctx context.Context, msg tea.Msg) { - cmdCtl, ok := ctx.Value(commandCtlKey).(*CommandController) + cmdCtl, ok := ctx.Value(commandCtlKey).(*execContext) if ok { - cmdCtl.postMessage(msg) + cmdCtl.ctrl.postMessage(msg) } } func SelectedItemIndex(ctx context.Context) (int, bool) { - cmdCtl, ok := ctx.Value(commandCtlKey).(*CommandController) + cmdCtl, ok := ctx.Value(commandCtlKey).(*execContext) if !ok { return 0, false } - return cmdCtl.uiStateProvider.SelectedItemIndex(), true + return cmdCtl.ctrl.uiStateProvider.SelectedItemIndex(), true } func SetSelectedItemIndex(ctx context.Context, newIdx int) tea.Msg { - cmdCtl, ok := ctx.Value(commandCtlKey).(*CommandController) + cmdCtl, ok := ctx.Value(commandCtlKey).(*execContext) if !ok { return nil } - return cmdCtl.uiStateProvider.SetSelectedItemIndex(newIdx) + return cmdCtl.ctrl.uiStateProvider.SetSelectedItemIndex(newIdx) +} + +func GetInvoker(ctx context.Context) Invoker { + cmdCtl, ok := ctx.Value(commandCtlKey).(*execContext) + if !ok { + return nil + } + + return cmdCtl.ctrl +} + +func QueueRefresh(ctx context.Context) { + cmdCtl, ok := ctx.Value(commandCtlKey).(*execContext) + if !ok { + return + } + cmdCtl.requestRefresh = true +} + +type Invoker interface { + Invoke(invokable ucl.Invokable, args []any) tea.Msg } diff --git a/internal/common/ui/events/resultset.go b/internal/common/ui/events/resultset.go new file mode 100644 index 0000000..cce739a --- /dev/null +++ b/internal/common/ui/events/resultset.go @@ -0,0 +1,5 @@ +package events + +type ResultSetUpdated struct { + StatusMessage string +} diff --git a/internal/dynamo-browse/controllers/events.go b/internal/dynamo-browse/controllers/events.go index 7af1c41..ac0e74a 100644 --- a/internal/dynamo-browse/controllers/events.go +++ b/internal/dynamo-browse/controllers/events.go @@ -81,14 +81,6 @@ type PromptForTableMsg struct { OnSelected func(tableName string) tea.Msg } -type ResultSetUpdated struct { - statusMessage string -} - -func (rs ResultSetUpdated) StatusMessage() string { - return rs.statusMessage -} - type ShowColumnOverlay struct{} type HideColumnOverlay struct{} diff --git a/internal/dynamo-browse/controllers/keybinding.go b/internal/dynamo-browse/controllers/keybinding.go index 043248f..3b9dc76 100644 --- a/internal/dynamo-browse/controllers/keybinding.go +++ b/internal/dynamo-browse/controllers/keybinding.go @@ -20,6 +20,10 @@ func NewKeyBindingController(service *keybindings.Service, customBindingSource C } } +func (kb *KeyBindingController) SetCustomKeyBindingSource(customBindingSource CustomKeyBindingSource) { + kb.customBindingSource = customBindingSource +} + func (kb *KeyBindingController) Rebind(bindingName string, newKey string, force bool) tea.Msg { existingBinding := kb.findExistingBinding(newKey) if existingBinding == "" { diff --git a/internal/dynamo-browse/controllers/tableread.go b/internal/dynamo-browse/controllers/tableread.go index e7034a5..38946f3 100644 --- a/internal/dynamo-browse/controllers/tableread.go +++ b/internal/dynamo-browse/controllers/tableread.go @@ -182,6 +182,10 @@ func (c *TableReadController) PromptForQuery() tea.Msg { } } +func (c *TableReadController) RunQuery(q *queryexpr.QueryExpr, table *models.TableInfo) tea.Msg { + return c.runQuery(table, q, "", true, nil) +} + func (c *TableReadController) runQuery( tableInfo *models.TableInfo, query *queryexpr.QueryExpr, @@ -339,27 +343,31 @@ func (c *TableReadController) Mark(op MarkOp, where string) tea.Msg { }); err != nil { return events.Error(err) } - return ResultSetUpdated{} + return events.ResultSetUpdated{} } -func (c *TableReadController) Filter() tea.Msg { +func (c *TableReadController) PromptForFilter() tea.Msg { return events.PromptForInputMsg{ Prompt: "filter: ", History: c.inputHistoryService.Iter(context.Background(), filterInputHistoryCategory), OnDone: func(value string) tea.Msg { - resultSet := c.state.ResultSet() - if resultSet == nil { - return events.StatusMsg("Result-set is nil") - } - - return NewJob(c.jobController, "Applying Filter…", func(ctx context.Context) (*models.ResultSet, error) { - newResultSet := c.tableService.Filter(resultSet, value) - return newResultSet, nil - }).OnEither(c.handleResultSetFromJobResult(value, true, false, resultSetUpdateFilter)).Submit() + return c.Filter(value) }, } } +func (c *TableReadController) Filter(value string) tea.Msg { + resultSet := c.state.ResultSet() + if resultSet == nil { + return events.StatusMsg("Result-set is nil") + } + + return NewJob(c.jobController, "Applying Filter…", func(ctx context.Context) (*models.ResultSet, error) { + newResultSet := c.tableService.Filter(resultSet, value) + return newResultSet, nil + }).OnEither(c.handleResultSetFromJobResult(value, true, false, resultSetUpdateFilter)).Submit() +} + func (c *TableReadController) handleResultSetFromJobResult( filter string, pushbackStack, errIfEmpty bool, diff --git a/internal/dynamo-browse/controllers/tablewrite.go b/internal/dynamo-browse/controllers/tablewrite.go index 033a0cb..8f248c5 100644 --- a/internal/dynamo-browse/controllers/tablewrite.go +++ b/internal/dynamo-browse/controllers/tablewrite.go @@ -44,7 +44,7 @@ func (twc *TableWriteController) ToggleMark(idx int) tea.Msg { resultSet.SetMark(idx, !resultSet.Marked(idx)) }) - return ResultSetUpdated{} + return events.ResultSetUpdated{} } func (twc *TableWriteController) NewItem() tea.Msg { @@ -148,7 +148,7 @@ func (twc *TableWriteController) setStringValue(idx int, attr *queryexpr.QueryEx }); err != nil { return events.Error(err) } - return ResultSetUpdated{} + return events.ResultSetUpdated{} }, } } @@ -181,7 +181,7 @@ func (twc *TableWriteController) setToExpressionValue(idx int, attr *queryexpr.Q }); err != nil { return events.Error(err) } - return ResultSetUpdated{} + return events.ResultSetUpdated{} }, } } @@ -205,7 +205,7 @@ func (twc *TableWriteController) setNumberValue(idx int, attr *queryexpr.QueryEx }); err != nil { return events.Error(err) } - return ResultSetUpdated{} + return events.ResultSetUpdated{} }, } } @@ -234,7 +234,7 @@ func (twc *TableWriteController) setBoolValue(idx int, attr *queryexpr.QueryExpr }); err != nil { return events.Error(err) } - return ResultSetUpdated{} + return events.ResultSetUpdated{} }, } } @@ -255,7 +255,7 @@ func (twc *TableWriteController) setNullValue(idx int, attr *queryexpr.QueryExpr }); err != nil { return events.Error(err) } - return ResultSetUpdated{} + return events.ResultSetUpdated{} } func (twc *TableWriteController) DeleteAttribute(idx int, key string) tea.Msg { @@ -291,7 +291,7 @@ func (twc *TableWriteController) DeleteAttribute(idx int, key string) tea.Msg { return events.Error(err) } - return ResultSetUpdated{} + return events.ResultSetUpdated{} } func (twc *TableWriteController) PutItems() tea.Msg { @@ -351,8 +351,8 @@ func (twc *TableWriteController) PutItems() tea.Msg { } return rs, nil }).OnDone(func(rs *models.ResultSet) tea.Msg { - return ResultSetUpdated{ - statusMessage: applyToN("", len(itemsToPut), "item", "item", " put to table"), + return events.ResultSetUpdated{ + StatusMessage: applyToN("", len(itemsToPut), "item", "item", " put to table"), } }).Submit() }, @@ -379,7 +379,7 @@ func (twc *TableWriteController) TouchItem(idx int) tea.Msg { if err := twc.tableService.PutItemAt(context.Background(), resultSet, idx); err != nil { return events.Error(err) } - return ResultSetUpdated{} + return events.ResultSetUpdated{} }, } } diff --git a/internal/dynamo-browse/ui/model.go b/internal/dynamo-browse/ui/model.go index 9acb70e..81f6926 100644 --- a/internal/dynamo-browse/ui/model.go +++ b/internal/dynamo-browse/ui/model.go @@ -276,10 +276,10 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { case controllers.SetTableItemView: cmd := m.setMainViewIndex(msg.ViewIndex) return m, cmd - case controllers.ResultSetUpdated: + case events.ResultSetUpdated: return m, tea.Batch( m.tableView.Refresh(), - events.SetStatus(msg.StatusMessage()), + events.SetStatus(msg.StatusMessage), ) case tea.KeyMsg: // TODO: use modes here @@ -302,7 +302,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { case key.Matches(msg, m.keyMap.PromptForQuery): return m, m.tableReadController.PromptForQuery case key.Matches(msg, m.keyMap.PromptForFilter): - return m, m.tableReadController.Filter + return m, m.tableReadController.PromptForFilter case key.Matches(msg, m.keyMap.FetchNextPage): return m, m.tableReadController.NextPage case key.Matches(msg, m.keyMap.ViewBack):