Skip to content

Commit

Permalink
fix substreams gui not showing the selected output_module if it has n…
Browse files Browse the repository at this point in the history
…o data early enough
  • Loading branch information
sduchesneau committed Nov 5, 2024
1 parent badd816 commit 3040ccc
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
3 changes: 3 additions & 0 deletions cmd/substreams/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions docs/release-notes/change-log.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
29 changes: 17 additions & 12 deletions tui2/pages/output/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand All @@ -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) })
Expand All @@ -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])
Expand All @@ -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:
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
}
Expand Down
5 changes: 5 additions & 0 deletions tui2/pages/request/newinstance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 3040ccc

Please sign in to comment.