Skip to content

Commit

Permalink
fix: better layout of modules and right panel (#1137)
Browse files Browse the repository at this point in the history
Fixes #1136 

![Screenshot 2024-03-25 at 1 58
11 PM](https://github.com/TBD54566975/ftl/assets/51647/c2de8d27-c734-4a95-b2fd-6c2b2d64a025)
![Screenshot 2024-03-25 at 1 58
17 PM](https://github.com/TBD54566975/ftl/assets/51647/9d2eaf33-24d1-4067-971a-a92e3983caaa)
![Screenshot 2024-03-25 at 1 58
20 PM](https://github.com/TBD54566975/ftl/assets/51647/0fd722cf-d31d-4b6b-83f1-7576f7837652)

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
wesbillman and github-actions[bot] authored Mar 25, 2024
1 parent 16588c5 commit 6bd60f1
Show file tree
Hide file tree
Showing 19 changed files with 910 additions and 566 deletions.
42 changes: 40 additions & 2 deletions backend/controller/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/TBD54566975/ftl/backend/protos/xyz/block/ftl/v1/console/pbconsoleconnect"
schemapb "github.com/TBD54566975/ftl/backend/protos/xyz/block/ftl/v1/schema"
"github.com/TBD54566975/ftl/backend/schema"
"github.com/TBD54566975/ftl/buildengine"
"github.com/TBD54566975/ftl/internal/log"
"github.com/TBD54566975/ftl/internal/model"
"github.com/TBD54566975/ftl/internal/slices"
Expand Down Expand Up @@ -64,7 +65,7 @@ func (c *ConsoleService) GetModules(ctx context.Context, req *connect.Request[pb
case *schema.Verb:
//nolint:forcetypeassert
v := decl.ToProto().(*schemapb.Verb)
verbSchema := schema.VerbFromProto(v) // TODO: include all of the types that the verb references
verbSchema := schema.VerbFromProto(v) // TODO: include all of the types that the verb references
var jsonRequestSchema string
if requestData, ok := verbSchema.Request.(*schema.Ref); ok {
jsonSchema, err := schema.DataToJSONSchema(sch, *requestData)
Expand Down Expand Up @@ -121,8 +122,20 @@ func (c *ConsoleService) GetModules(ctx context.Context, req *connect.Request[pb
})
}

sorted := buildengine.TopologicalSort(graph(sch))
topology := &pbconsole.Topology{
Levels: make([]*pbconsole.TopologyGroup, len(sorted)),
}
for i, level := range sorted {
group := &pbconsole.TopologyGroup{
Modules: level,
}
topology.Levels[i] = group
}

return connect.NewResponse(&pbconsole.GetModulesResponse{
Modules: modules,
Modules: modules,
Topology: topology,
}), nil
}

Expand Down Expand Up @@ -392,3 +405,28 @@ func eventDALToProto(event dal.Event) *pbconsole.Event {
panic(fmt.Errorf("unknown event type %T", event))
}
}

func graph(sch *schema.Schema) map[string][]string {
out := make(map[string][]string)
for _, module := range sch.Modules {
buildGraph(sch, module, out)
}
return out
}

// buildGraph recursively builds the dependency graph
func buildGraph(sch *schema.Schema, module *schema.Module, out map[string][]string) {
out[module.Name] = module.Imports()
for _, dep := range module.Imports() {
var depModule *schema.Module
for _, m := range sch.Modules {
if m.String() == dep {
depModule = m
break
}
}
if depModule != nil {
buildGraph(sch, module, out)
}
}
}
Loading

0 comments on commit 6bd60f1

Please sign in to comment.