Skip to content

Commit

Permalink
fix(server): widget padding fixes (#382)
Browse files Browse the repository at this point in the history
  • Loading branch information
mimoham24 authored Feb 6, 2023
1 parent bed3f25 commit a019c54
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 7 deletions.
20 changes: 18 additions & 2 deletions server/internal/adapter/gql/gqlmodel/convert_scene_align.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,31 @@ func ToWidgetSection(s *scene.WidgetSection) *WidgetSection {
Bottom: ToWidgetArea(s.Area(scene.WidgetAreaBottom)),
}
}
func ToWidgetAreaPadding(p *scene.WidgetAreaPadding) *WidgetAreaPadding {
if p == nil {
return &WidgetAreaPadding{}
}

return &WidgetAreaPadding{
Top: p.Top(),
Bottom: p.Bottom(),
Left: p.Left(),
Right: p.Right(),
}
}

func ToWidgetArea(a *scene.WidgetArea) *WidgetArea {
if a == nil {
return nil
}

return &WidgetArea{
WidgetIds: util.Map(a.WidgetIDs(), IDFrom[id.Widget]),
Align: ToWidgetAlignType(a.Alignment()),
WidgetIds: util.Map(a.WidgetIDs(), IDFrom[id.Widget]),
Align: ToWidgetAlignType(a.Alignment()),
Padding: ToWidgetAreaPadding(a.Padding()),
Gap: a.Gap(),
Centered: a.Centered(),
Background: a.Background(),
}
}

Expand Down
4 changes: 3 additions & 1 deletion server/internal/usecase/interactor/scene.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,9 @@ func (i *Scene) UpdateWidgetAlignSystem(ctx context.Context, param interfaces.Up
if param.Centered != nil {
area.SetCentered(*param.Centered)
}
area.SetBackground(param.Background)
if param.Background != nil {
area.SetBackground(param.Background)
}

if err = i.sceneRepo.Save(ctx, s); err != nil {
return nil, err
Expand Down
15 changes: 13 additions & 2 deletions server/pkg/scene/builder/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,19 @@ type widgetSectionJSON struct {
}

type widgetAreaJSON struct {
WidgetIDs []string `json:"widgetIds"`
Align string `json:"align"`
WidgetIDs []string `json:"widgetIds"`
Align string `json:"align"`
Padding *widgetAreaPaddingJSON `json:"padding"`
Gap int `json:"gap"`
Centered bool `json:"centered"`
Background *string `json:"background"`
}

type widgetAreaPaddingJSON struct {
Top int `json:"top"`
Bottom int `json:"bottom"`
Left int `json:"left"`
Right int `json:"right"`
}

type widgetJSON struct {
Expand Down
19 changes: 17 additions & 2 deletions server/pkg/scene/builder/scene.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,22 @@ func buildWidgetArea(a *scene.WidgetArea) *widgetAreaJSON {
return nil
}
return &widgetAreaJSON{
WidgetIDs: toString(a.WidgetIDs()),
Align: string(a.Alignment()),
WidgetIDs: toString(a.WidgetIDs()),
Align: string(a.Alignment()),
Padding: buildWidgetAreaPadding(a.Padding()),
Gap: a.Gap(),
Centered: a.Centered(),
Background: a.Background(),
}
}
func buildWidgetAreaPadding(p *scene.WidgetAreaPadding) *widgetAreaPaddingJSON {
if p == nil {
return &widgetAreaPaddingJSON{}
}
return &widgetAreaPaddingJSON{
Top: p.Top(),
Bottom: p.Bottom(),
Left: p.Left(),
Right: p.Right(),
}
}
9 changes: 9 additions & 0 deletions server/pkg/scene/builder/scene_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ func TestBuildWidgetAlignSystem(t *testing.T) {
Top: &widgetAreaJSON{
WidgetIDs: []string{wid.String()},
Align: "start",
Padding: &widgetAreaPaddingJSON{
Top: 0,
Bottom: 0,
Left: 0,
Right: 0,
},
Gap: 0,
Centered: false,
Background: nil,
},
},
},
Expand Down

0 comments on commit a019c54

Please sign in to comment.