Skip to content

Commit

Permalink
fix: console displaying Unit request types (#997)
Browse files Browse the repository at this point in the history
  • Loading branch information
wesbillman authored Feb 27, 2024
1 parent d377577 commit f640d12
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
24 changes: 12 additions & 12 deletions backend/controller/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,22 @@ func (c *ConsoleService) GetModules(ctx context.Context, req *connect.Request[pb
//nolint:forcetypeassert
v := decl.ToProto().(*schemapb.Verb)
verbSchema := schema.VerbToSchema(v) // TODO: include all of the types that the verb references
requestData, ok := verbSchema.Request.(*schema.DataRef)
if !ok {
return nil, fmt.Errorf("expected request to be a data ref, got %T", verbSchema.Request)
}
jsonRequestSchema, err := schema.DataToJSONSchema(sch, *requestData)
if err != nil {
return nil, err
}
jsonData, err := json.MarshalIndent(jsonRequestSchema, "", " ")
if err != nil {
return nil, err
var jsonRequestSchema string
if requestData, ok := verbSchema.Request.(*schema.DataRef); ok {
jsonSchema, err := schema.DataToJSONSchema(sch, *requestData)
if err != nil {
return nil, err
}
jsonData, err := json.MarshalIndent(jsonSchema, "", " ")
if err != nil {
return nil, err
}
jsonRequestSchema = string(jsonData)
}
verbs = append(verbs, &pbconsole.Verb{
Verb: v,
Schema: verbSchema.String(),
JsonRequestSchema: string(jsonData),
JsonRequestSchema: jsonRequestSchema,
})

case *schema.Data:
Expand Down
19 changes: 16 additions & 3 deletions frontend/src/features/graph/create-layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ const groupWidth = 200
const calculateModuleDepths = (modules: Module[]): Record<string, number> => {
const depths: Record<string, number> = {}
const adjList: Record<string, string[]> = {}
const visitedInCurrentPath: Set<string> = new Set() // For cycle detection

// Initialize adjacency list
modules.forEach((module) => {
adjList[module.name ?? ''] = []
;(module.verbs ?? []).forEach((verb) => {
Expand All @@ -26,12 +26,25 @@ const calculateModuleDepths = (modules: Module[]): Record<string, number> => {

// Depth-first search to calculate depths
const dfs = (node: string, depth: number) => {
if (visitedInCurrentPath.has(node)) {
// Detected a cycle
return
}
visitedInCurrentPath.add(node)

depths[node] = Math.max(depths[node] ?? 0, depth)
adjList[node].forEach((neighbor) => dfs(neighbor, depth + 1))
adjList[node].forEach((neighbor) => {
dfs(neighbor, depth + 1)
})

visitedInCurrentPath.delete(node) // Remove the node from the current path after exploring all neighbors
}

// Initialize DFS from each node
Object.keys(adjList).forEach((node) => dfs(node, 0))
Object.keys(adjList).forEach((node) => {
visitedInCurrentPath.clear() // Clear the path before starting a new DFS
dfs(node, 0)
})

return depths
}
Expand Down

0 comments on commit f640d12

Please sign in to comment.