diff --git a/cmd/substreams/gui.go b/cmd/substreams/gui.go index 722017a1..11a9e250 100644 --- a/cmd/substreams/gui.go +++ b/cmd/substreams/gui.go @@ -197,6 +197,9 @@ func runGui(cmd *cobra.Command, args []string) (err error) { DefaultParams: strings.Join(defaultParams, "\n"), // ReaderOptions: readerOptions, } + if err := requestConfig.Normalize(); err != nil { + return err + } ui, err := tui2.New(requestConfig) if err != nil { diff --git a/docs/release-notes/change-log.md b/docs/release-notes/change-log.md index 3e1f71f7..1cfd4ba5 100644 --- a/docs/release-notes/change-log.md +++ b/docs/release-notes/change-log.md @@ -11,6 +11,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ## Unreleased +* Fix `substreams gui` selecting the wrong module in the 'outputs' view if there is no output the selected output_module. + ## v1.10.9 * Add Mantra Mainnet and Testnet to the HardcodedEndpoints map. diff --git a/tui2/pages/output/output.go b/tui2/pages/output/output.go index cfd9d04c..4e956462 100644 --- a/tui2/pages/output/output.go +++ b/tui2/pages/output/output.go @@ -34,9 +34,8 @@ type Output struct { lastDisplayContext *displayContext lastOutputContent string - lowBlock *uint64 - highBlock uint64 - firstBlockSeen bool + lowBlock *uint64 + highBlock uint64 blocksPerModule map[string][]uint64 payloads map[request.BlockContext]*pbsubstreamsrpc.AnyModuleOutput @@ -92,7 +91,6 @@ func New(c common.Common, config *request.Config) (*Output, error) { outputModule: config.OutputModule, logsEnabled: true, //moduleNavigator: nav, - firstBlockSeen: true, } output.statusBar.SetShowLogs(output.logsEnabled) return output, nil @@ -163,6 +161,14 @@ func (o *Output) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } o.blockSelector.StretchBounds(*o.lowBlock, o.highBlock) + // this will run on first received data (whatever module) + // we always add the "output module" as soon as we get data + if o.moduleSelector.AddModule(o.outputModule) { + cmds = append(cmds, func() tea.Msg { return common.UpdateSeenModulesMsg(o.moduleSelector.Modules) }) + o.active.Module = o.outputModule + o.active.BlockNum = blockNum + } + o.blockIDs[msg.Clock.Number] = msg.Clock.Id for _, output := range msg.AllModuleOutputs() { if output.IsEmpty() { @@ -175,6 +181,7 @@ func (o *Output) Update(msg tea.Msg) (tea.Model, tea.Cmd) { BlockNum: blockNum, } + forceRedraw := false if _, found := o.payloads[blockCtx]; !found { if o.moduleSelector.AddModule(modName) { cmds = append(cmds, func() tea.Msg { return common.UpdateSeenModulesMsg(o.moduleSelector.Modules) }) @@ -183,6 +190,10 @@ func (o *Output) Update(msg tea.Msg) (tea.Model, tea.Cmd) { o.active.Module = modName o.active.BlockNum = blockNum } + if o.active.Module == modName && len(o.blocksPerModule[modName]) == 0 { + forceRedraw = true + o.active.BlockNum = blockNum + } o.blocksPerModule[modName] = append(o.blocksPerModule[modName], blockNum) if modName == o.active.Module { o.blockSelector.SetAvailableBlocks(o.blocksPerModule[modName]) @@ -197,10 +208,7 @@ func (o *Output) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } } o.payloads[blockCtx] = output - if o.firstBlockSeen { - o.active = blockCtx - } - o.setOutputViewContent(false) + o.setOutputViewContent(forceRedraw) } case search.ApplySearchQueryMsg: @@ -319,7 +327,7 @@ func (o *Output) setOutputViewContent(forcedRender bool) { errReceived: o.errReceived, } - if o.firstBlockSeen || forcedRender { + if forcedRender { vals := o.renderedOutput(displayCtx.payload, true) content := o.renderPayload(vals) if displayCtx.searchViewEnabled { @@ -339,9 +347,6 @@ func (o *Output) setOutputViewContent(forcedRender bool) { o.outputView.SetContent(content) o.lastOutputContent = content - if content != "" { - o.firstBlockSeen = false - } } else { o.outputView.SetContent(o.lastOutputContent) } diff --git a/tui2/pages/request/newinstance.go b/tui2/pages/request/newinstance.go index 7ebe03f2..b63e740d 100644 --- a/tui2/pages/request/newinstance.go +++ b/tui2/pages/request/newinstance.go @@ -63,6 +63,11 @@ type Instance struct { Graph *manifest.ModuleGraph } +func (c *Config) Normalize() error { + _, err := c.NewInstance() + return err +} + func (c *Config) NewInstance() (out *Instance, err error) { // WARN: this is run in a goroutine, so there are risks of races when we mutate // this *Config pointer, although it should be fairly low risk.