Skip to content

Commit

Permalink
chore(server): add extensionId and pluginId in block json of publishe…
Browse files Browse the repository at this point in the history
…d story (#693)
  • Loading branch information
pyshx committed Sep 19, 2023
1 parent eb82a83 commit b2992da
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
7 changes: 5 additions & 2 deletions server/e2e/gql_storytelling_test.go
Expand Up @@ -1015,7 +1015,10 @@ func TestStoryPublishing(t *testing.T) {

_, _, pageID := createPage(e, sID, storyID, "test", true)

_, _, blockID := createBlock(e, sID, storyID, pageID, "reearth", "textStoryBlock", nil)
extensionId := "textStoryBlock"
pluginId := "reearth"

_, _, blockID := createBlock(e, sID, storyID, pageID, pluginId, extensionId, nil)

_, res := fetchSceneForStories(e, sID)
blockPropID := res.Object().Path("$.data.node.stories[0].pages[0].blocks[0].propertyId").Raw().(string)
Expand All @@ -1034,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}]}]}}`, sID, storyID, pageID, blockID))
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"}]}]}}`, sID, storyID, pageID, blockID, extensionId, pluginId))
assert.Regexp(t, pub, buf.String())

resString := e.GET("/p/test-alias/data.json").
Expand Down
16 changes: 10 additions & 6 deletions server/pkg/scene/builder/story.go
Expand Up @@ -21,9 +21,11 @@ type pageJSON struct {
}

type blockJSON struct {
ID string `json:"id"`
Property propertyJSON `json:"property"`
Plugins map[string]propertyJSON `json:"plugins"`
ID string `json:"id"`
Property propertyJSON `json:"property"`
Plugins map[string]propertyJSON `json:"plugins"`
ExtensionId string `json:"extensionId"`
PluginId string `json:"pluginId"`
}

func (b *Builder) storyJSON(ctx context.Context, p []*property.Property) (*storyJSON, error) {
Expand Down Expand Up @@ -58,8 +60,10 @@ func (b *Builder) pageJSON(ctx context.Context, page storytelling.Page, p []*pro

func (b *Builder) blockJSON(ctx context.Context, block storytelling.Block, p []*property.Property) blockJSON {
return blockJSON{
ID: block.ID().String(),
Property: b.property(ctx, findProperty(p, block.Property())),
Plugins: nil,
ID: block.ID().String(),
Property: b.property(ctx, findProperty(p, block.Property())),
Plugins: nil,
ExtensionId: block.Extension().String(),
PluginId: block.Plugin().String(),
}
}

0 comments on commit b2992da

Please sign in to comment.