Skip to content

Commit

Permalink
Showcase a ComposableDashboardPanel() veneer selector
Browse files Browse the repository at this point in the history
  • Loading branch information
K-Phoen committed Oct 5, 2023
1 parent 80ae144 commit 42abb83
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 3 deletions.
5 changes: 4 additions & 1 deletion cmd/cli/loaders/openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ func openapiLoader(opts Options) ([]*ast.Schema, error) {
for _, entrypoint := range opts.OpenAPIEntrypoints {
pkg := filepath.Base(filepath.Dir(entrypoint))
schemaAst, err := openapi.GenerateAST(entrypoint, openapi.Config{
Package: pkg,
Package: pkg,
SchemaMetadata: ast.SchemaMeta{
// TODO: extract these from somewhere
},
})
if err != nil {
return nil, err
Expand Down
8 changes: 6 additions & 2 deletions internal/openapi/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ const (
)

type Config struct {
Package string
Package string
SchemaMetadata ast.SchemaMeta
}

type generator struct {
Expand All @@ -42,7 +43,10 @@ func GenerateAST(filePath string, cfg Config) (*ast.Schema, error) {
}

g := &generator{
file: &ast.Schema{Package: cfg.Package},
file: &ast.Schema{
Package: cfg.Package,
Metadata: cfg.SchemaMetadata,
},
}

if oapi.Components == nil {
Expand Down
6 changes: 6 additions & 0 deletions internal/veneers/builder/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,9 @@ func MergeIntoAction(sourceBuilderName string, underPath string, excludeOptions
return newBuilder
}
}

func ComposeDashboardPanelAction(_ /*panelBuilderName*/ string) RewriteAction {
return func(builders ast.Builders, destinationBuilder ast.Builder) ast.Builder {
return destinationBuilder
}
}
7 changes: 7 additions & 0 deletions internal/veneers/builder/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,10 @@ func MergeInto(selector Selector, sourceBuilderName string, underPath string, ex
Action: MergeIntoAction(sourceBuilderName, underPath, excludeOptions),
}
}

func ComposeDashboardPanel(selector Selector, sourceBuilderName string) RewriteRule {
return RewriteRule{
Selector: selector,
Action: ComposeDashboardPanelAction(sourceBuilderName),
}
}
8 changes: 8 additions & 0 deletions internal/veneers/builder/selectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ func StructGeneratedFromDisjunction() Selector {
}
}

func ComposableDashboardPanel() Selector {
return func(builder ast.Builder) bool {
return builder.Schema.Metadata.Kind == ast.SchemaKindComposable &&
builder.Schema.Metadata.Variant == ast.SchemaVariantPanel &&
builder.Schema.Metadata.Identifier != ""
}
}

func EveryBuilder() Selector {
return func(builder ast.Builder) bool {
return true
Expand Down
6 changes: 6 additions & 0 deletions internal/veneers/veneers.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ func Common() *Rewriter {
},
),

// Panels composability
builder.ComposeDashboardPanel(
builder.ComposableDashboardPanel(),
"dashboard.Panel",
),

// remove builders that were previously merged into something else
builder.Omit(builder.ByName("FieldConfig")),
builder.Omit(builder.ByName("FieldConfigSource")),
Expand Down

0 comments on commit 42abb83

Please sign in to comment.