Skip to content

Commit

Permalink
Add support for untyped layout: in the canvas YAML
Browse files Browse the repository at this point in the history
  • Loading branch information
begelundmuller committed Feb 4, 2025
1 parent 9e0f00d commit 27881f2
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 30 deletions.
73 changes: 43 additions & 30 deletions proto/gen/rill/runtime/v1/resources.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions proto/gen/rill/runtime/v1/resources.pb.validate.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions proto/gen/rill/runtime/v1/runtime.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3635,6 +3635,8 @@ definitions:
type: object
$ref: '#/definitions/v1CanvasItem'
title: Items to render on the canvas
layout:
description: Layout is an untyped object pending a formal definition.
securityRules:
type: array
items:
Expand Down
2 changes: 2 additions & 0 deletions proto/rill/runtime/v1/resources.proto
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,8 @@ message CanvasSpec {
repeated ComponentVariable variables = 5;
// Items to render on the canvas
repeated CanvasItem items = 4;
// Layout is an untyped object pending a formal definition.
google.protobuf.Value layout = 16;
// Security rules to apply for access to the canvas.
repeated SecurityRule security_rules = 6;
}
Expand Down
12 changes: 12 additions & 0 deletions runtime/compilers/rillv1/parse_canvas.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
runtimev1 "github.com/rilldata/rill/proto/gen/rill/runtime/v1"
"github.com/rilldata/rill/runtime/pkg/rilltime"
"golang.org/x/exp/maps"
"google.golang.org/protobuf/types/known/structpb"
"gopkg.in/yaml.v3"
)

Expand Down Expand Up @@ -39,6 +40,7 @@ type CanvasYAML struct {
Width *uint32 `yaml:"width"`
Height *uint32 `yaml:"height"`
} `yaml:"items"`
Layout any `yaml:"layout"` // Untyped pending a formal definition
Security *SecurityPolicyYAML `yaml:"security"`
}

Expand Down Expand Up @@ -144,6 +146,15 @@ func (p *Parser) parseCanvas(node *Node) error {
node.Refs = append(node.Refs, ResourceName{Kind: ResourceKindComponent, Name: component})
}

// Parse layout (currently untyped pending a formal definition)
var layout *structpb.Value
if tmp.Layout != nil {
layout, err = structpb.NewValue(tmp.Layout)
if err != nil {
return fmt.Errorf("invalid layout: %w", err)
}
}

// Build and validate presets
var defaultPreset *runtimev1.CanvasPreset
if tmp.Defaults != nil {
Expand Down Expand Up @@ -208,6 +219,7 @@ func (p *Parser) parseCanvas(node *Node) error {
r.CanvasSpec.EmbeddedTheme = themeSpec
r.CanvasSpec.Variables = variables
r.CanvasSpec.Items = items
r.CanvasSpec.Layout = layout
r.CanvasSpec.SecurityRules = rules

// Track inline components
Expand Down
5 changes: 5 additions & 0 deletions runtime/compilers/rillv1/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1715,6 +1715,10 @@ items:
- component:
markdown:
content: "Hello world!"
layout:
- 1, 2, 3
- 4, 5, 6
`,
})

Expand Down Expand Up @@ -1790,6 +1794,7 @@ items:
{Component: "c2", Width: asPtr(uint32(1)), Height: asPtr(uint32(2))},
{Component: "d1--component-2", DefinedInCanvas: true},
},
Layout: must(structpb.NewValue([]any{"1, 2, 3", "4, 5, 6"})),
},
},
}
Expand Down
8 changes: 8 additions & 0 deletions web-common/src/proto/gen/rill/runtime/v1/resources_pb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4563,6 +4563,13 @@ export class CanvasSpec extends Message<CanvasSpec> {
*/
items: CanvasItem[] = [];

/**
* Layout is an untyped object pending a formal definition.
*
* @generated from field: google.protobuf.Value layout = 16;
*/
layout?: Value;

/**
* Security rules to apply for access to the canvas.
*
Expand Down Expand Up @@ -4590,6 +4597,7 @@ export class CanvasSpec extends Message<CanvasSpec> {
{ no: 15, name: "default_preset", kind: "message", T: CanvasPreset },
{ no: 5, name: "variables", kind: "message", T: ComponentVariable, repeated: true },
{ no: 4, name: "items", kind: "message", T: CanvasItem, repeated: true },
{ no: 16, name: "layout", kind: "message", T: Value },
{ no: 6, name: "security_rules", kind: "message", T: SecurityRule, repeated: true },
]);

Expand Down
2 changes: 2 additions & 0 deletions web-common/src/runtime-client/gen/index.schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2380,6 +2380,8 @@ The values should be valid IANA location identifiers. */
/** Variables that can be used in the canvas. */
variables?: V1ComponentVariable[];
items?: V1CanvasItem[];
/** Layout is an untyped object pending a formal definition. */
layout?: unknown;
/** Security rules to apply for access to the canvas. */
securityRules?: V1SecurityRule[];
}
Expand Down

0 comments on commit 27881f2

Please sign in to comment.