Skip to content

Commit

Permalink
chore(server): add position, bgColor & title to story & page json res…
Browse files Browse the repository at this point in the history
…pectively for published story (#787)
  • Loading branch information
pyshx committed Nov 6, 2023
1 parent c158b69 commit cea0d7b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion server/e2e/gql_storytelling_test.go
Expand Up @@ -1037,7 +1037,7 @@ func TestStoryPublishing(t *testing.T) {
_, err = buf.ReadFrom(rc)
assert.NoError(t, err)

pub := regexp.MustCompile(fmt.Sprintf(`{"schemaVersion":1,"id":"%s","publishedAt":".*","property":{"tiles":\[{"id":".*"}]},"plugins":{},"layers":null,"widgets":\[],"widgetAlignSystem":null,"tags":\[],"clusters":\[],"story":{"id":"%s","property":{},"pages":\[{"id":"%s","property":{},"blocks":\[{"id":"%s","property":{"default":{"text":"test value"},"panel":{"padding":{"top":2,"bottom":3,"left":0,"right":1}}},"plugins":null,"extensionId":"%s","pluginId":"%s"}],"swipeable":true,"swipeableLayers":\[],"layers":\[]}]},"nlsLayers":null,"layerStyles":null,"coreSupport":true}`, sID, storyID, pageID, blockID, extensionId, pluginId))
pub := regexp.MustCompile(fmt.Sprintf(`{"schemaVersion":1,"id":"%s","publishedAt":".*","property":{"tiles":\[{"id":".*"}]},"plugins":{},"layers":null,"widgets":\[],"widgetAlignSystem":null,"tags":\[],"clusters":\[],"story":{"id":"%s","property":{},"pages":\[{"id":"%s","property":{},"title":"test","blocks":\[{"id":"%s","property":{"default":{"text":"test value"},"panel":{"padding":{"top":2,"bottom":3,"left":0,"right":1}}},"plugins":null,"extensionId":"%s","pluginId":"%s"}],"swipeable":true,"swipeableLayers":\[],"layers":\[]}],"position":"left","bgColor":""},"nlsLayers":null,"layerStyles":null,"coreSupport":true}`, sID, storyID, pageID, blockID, extensionId, pluginId))
assert.Regexp(t, pub, buf.String())

resString := e.GET("/p/test-alias/data.json").
Expand Down
12 changes: 9 additions & 3 deletions server/pkg/scene/builder/story.go
Expand Up @@ -9,14 +9,17 @@ import (
)

type storyJSON struct {
ID string `json:"id"`
Property propertyJSON `json:"property"`
Pages []pageJSON `json:"pages"`
ID string `json:"id"`
Property propertyJSON `json:"property"`
Pages []pageJSON `json:"pages"`
PanelPosition string `json:"position"`
BgColor string `json:"bgColor"`
}

type pageJSON struct {
ID string `json:"id"`
Property propertyJSON `json:"property"`
Title string `json:"title"`
Blocks []blockJSON `json:"blocks"`
Swipeable bool `json:"swipeable"`
SwipeableLayers []string `json:"swipeableLayers"`
Expand Down Expand Up @@ -45,13 +48,16 @@ func (b *Builder) storyJSON(ctx context.Context, p []*property.Property) (*story
}
return b.pageJSON(ctx, *page, p), true
}),
PanelPosition: string(b.story.PanelPosition()),
BgColor: b.story.BgColor(),
}, nil
}

func (b *Builder) pageJSON(ctx context.Context, page storytelling.Page, p []*property.Property) pageJSON {
return pageJSON{
ID: page.Id().String(),
Property: b.property(ctx, findProperty(p, page.Property())),
Title: page.Title(),
Blocks: lo.FilterMap(page.Blocks(), func(block *storytelling.Block, _ int) (blockJSON, bool) {
if block == nil {
return blockJSON{}, false
Expand Down
4 changes: 4 additions & 0 deletions server/pkg/storytelling/story.go
Expand Up @@ -165,6 +165,10 @@ func (s *Story) PanelPosition() Position {
return s.panelPosition
}

func (s *Story) BgColor() string {
return s.bgColor
}

func (s *Story) ValidateProperties(pm property.Map) error {
if pm == nil {
return nil
Expand Down

0 comments on commit cea0d7b

Please sign in to comment.