Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions cue/dashboard/layout_go_gen.cue
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,28 @@ import "github.com/perses/spec/cue/common"
#KindGridLayout: #LayoutKind & "Grid"
#KindTabLayout: #LayoutKind & "Tabs"

#RepeatVariableAlignment: _ // #enumRepeatVariableAlignment

#enumRepeatVariableAlignment:
#RepeatVariableAlignmentHorizontal |
#RepeatVariableAlignmentVertical

#RepeatVariableAlignmentHorizontal: #RepeatVariableAlignment & "horizontal"
#RepeatVariableAlignmentVertical: #RepeatVariableAlignment & "vertical"

#RepeatVariable: {
value: string @go(Value)
maxPer?: null | int @go(MaxPer,*int)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More link to implem than spec, but what happen if there is two panels next to each other without repeat variable. And you enable it on one with maxPer: 2. Will it do 2 rows?

  • 1 panel (without repeat), empty
  • panel repeat, panel repeat

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maxPer refers to rows inside grid item. By default the grid item will extend it's width to full grid width when setting repeat panel on given item (inspired by grafana) but after that you can change its width and the panels will be fit into rows based on maxPer variable.

demo.mov

alignment?: #RepeatVariableAlignment @go(Alignment)
}

#GridItem: {
x: int @go(X)
y: int @go(Y)
width: int @go(Width)
height: int @go(Height)
content?: null | common.#JSONRef @go(Content,*common.JSONRef)
x: int @go(X)
y: int @go(Y)
width: int @go(Width)
height: int @go(Height)
content?: null | common.#JSONRef @go(Content,*common.JSONRef)
repeatVariable?: null | #RepeatVariable @go(RepeatVariable,*RepeatVariable)
}

#GridLayoutCollapse: {
Expand Down
62 changes: 57 additions & 5 deletions go/dashboard/layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,64 @@ func (k *LayoutKind) validate() error {
return nil
}

type RepeatVariableAlignment string

const (
RepeatVariableAlignmentHorizontal RepeatVariableAlignment = "horizontal"
RepeatVariableAlignmentVertical RepeatVariableAlignment = "vertical"
)

var repeatVariableAlignmentMap = map[RepeatVariableAlignment]bool{
RepeatVariableAlignmentHorizontal: true,
RepeatVariableAlignmentVertical: true,
}

func (a *RepeatVariableAlignment) UnmarshalJSON(data []byte) error {
var tmp RepeatVariableAlignment
type plain RepeatVariableAlignment
if err := json.Unmarshal(data, (*plain)(&tmp)); err != nil {
return err
}
if err := (&tmp).validate(); err != nil {
return err
}
*a = tmp
return nil
}

func (a *RepeatVariableAlignment) UnmarshalYAML(unmarshal func(any) error) error {
var tmp RepeatVariableAlignment
type plain RepeatVariableAlignment
if err := unmarshal((*plain)(&tmp)); err != nil {
return err
}
if err := (&tmp).validate(); err != nil {
return err
}
*a = tmp
return nil
}

func (a *RepeatVariableAlignment) validate() error {
if _, ok := repeatVariableAlignmentMap[*a]; !ok {
return fmt.Errorf("unknown repeatVariable.alignment %q used", *a)
}
return nil
}

type RepeatVariable struct {
Value string `json:"value" yaml:"value"`
MaxPer *int `json:"maxPer,omitempty" yaml:"maxPer,omitempty"`
Alignment RepeatVariableAlignment `json:"alignment,omitempty" yaml:"alignment,omitempty"`
}
Comment thread
adrianSepiol marked this conversation as resolved.

type GridItem struct {
X int `json:"x" yaml:"x"`
Y int `json:"y" yaml:"y"`
Width int `json:"width" yaml:"width"`
Height int `json:"height" yaml:"height"`
Content *common.JSONRef `json:"content" yaml:"content"`
X int `json:"x" yaml:"x"`
Y int `json:"y" yaml:"y"`
Width int `json:"width" yaml:"width"`
Height int `json:"height" yaml:"height"`
Content *common.JSONRef `json:"content" yaml:"content"`
RepeatVariable *RepeatVariable `json:"repeatVariable,omitempty" yaml:"repeatVariable,omitempty"`
}

type GridLayoutCollapse struct {
Expand Down
Loading
Loading