Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GO-4588 layout resolver #1975

Open
wants to merge 24 commits into
base: feature/primitives
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
318fbf6
GO-4588 Add resolved layout injection WIP
KirillSto Dec 6, 2024
decb884
GO-4588 Update subscriptions on type absence
KirillSto Dec 17, 2024
a3178d7
GO-4588 Resolve layout for new objects
KirillSto Dec 19, 2024
17a0891
GO-4588 Add SetRecLayout rpc WIP
KirillSto Dec 19, 2024
f90ecdd
GO-4588 Merge feature branch
KirillSto Dec 20, 2024
00ded0e
GO-4588 Fix after merge
KirillSto Dec 20, 2024
2d1acea
GO-4588 Change resolved layout on type apply
KirillSto Dec 20, 2024
e01a075
GO-4588 Replace layout with resolvedLayout
KirillSto Dec 21, 2024
1fd2b1b
GO-4588 Inject resolved layout
KirillSto Dec 21, 2024
df1b995
GO-4588 Fix lint
KirillSto Jan 7, 2025
838f04d
GO-4588 Allow to update recLayout via SetDetails
KirillSto Jan 7, 2025
a39b82d
GO-4588 Fix lint
KirillSto Jan 7, 2025
5eb4f3e
GO-4588 Take layout from local details
KirillSto Jan 7, 2025
3a629d4
GO-4588 Rm layout inject from creator
KirillSto Jan 7, 2025
ded7941
GO-4588 Add tests on resolvedLayout injection
KirillSto Jan 7, 2025
806151d
GO-4588 Increase force reindex counter
KirillSto Jan 8, 2025
d24c206
GO-4588 Make Task, Note, Page editable
KirillSto Jan 8, 2025
116a576
GO-4588 Use Apply instead of StateAppend
KirillSto Jan 8, 2025
29bd117
GO-4588 Test on changeResolvedLayout
KirillSto Jan 9, 2025
4f45c74
GO-4588 Test on changeResolvedLayout
KirillSto Jan 9, 2025
2e0cf30
GO-4588 Merge feature branch
KirillSto Jan 10, 2025
0770a84
GO-4588 Change layout for templates
KirillSto Jan 10, 2025
0506887
GO-4588 Set layout for not-pages
KirillSto Jan 13, 2025
f768162
GO-4588 Fix integration test
KirillSto Jan 14, 2025
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
5 changes: 5 additions & 0 deletions .mockery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ packages:
dir: "{{.InterfaceDir}}"
outpkg: "{{.PackageName}}"
inpackage: true
Space:
config:
dir: "{{.InterfaceDir}}"
outpkg: "{{.PackageName}}"
inpackage: true
github.com/anyproto/anytype-heart/core/block/editor/lastused:
interfaces:
ObjectUsageUpdater:
Expand Down
2 changes: 1 addition & 1 deletion core/block/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (s *Service) deleteRelationOptions(spaceId string, relationKey string) erro
relationOptions, _, err := s.objectStore.SpaceIndex(spaceId).QueryObjectIds(database.Query{
Filters: []database.FilterRequest{
{
RelationKey: bundle.RelationKeyLayout,
RelationKey: bundle.RelationKeyResolvedLayout,
Condition: model.BlockContentDataviewFilter_Equal,
Value: domain.Int64(model.ObjectType_relationOption),
},
Expand Down
2 changes: 1 addition & 1 deletion core/block/detailservice/relations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func relationObject(key domain.RelationKey, format model.RelationFormat) objects
return objectstore.TestObject{
bundle.RelationKeyId: domain.String(key.URL()),
bundle.RelationKeySpaceId: domain.String(spaceId),
bundle.RelationKeyLayout: domain.Float64(float64(model.ObjectType_relation)),
bundle.RelationKeyResolvedLayout: domain.Float64(float64(model.ObjectType_relation)),
bundle.RelationKeyRelationKey: domain.String(key.String()),
bundle.RelationKeyRelationFormat: domain.Int64(int64(format)),
}
Expand Down
3 changes: 2 additions & 1 deletion core/block/editor/accountobject/accountobject.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ func (a *accountObject) initState(st *state.State) error {
template.InitTemplate(st,
template.WithTitle,
template.WithForcedObjectTypes([]domain.TypeKey{bundle.TypeKeyProfile}),
template.WithForcedDetail(bundle.RelationKeyLayout, domain.Int64(model.ObjectType_profile)),
template.WithResolvedLayout(model.ObjectType_profile),
template.WithLayout(model.ObjectType_profile),
template.WithDetail(bundle.RelationKeyLayoutAlign, domain.Int64(model.Block_AlignCenter)),
)
blockId := "identity"
Expand Down
4 changes: 2 additions & 2 deletions core/block/editor/basic/details.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func (bs *basic) setDetailSpecialCases(st *state.State, detail domain.Detail) er
if detail.Key == bundle.RelationKeyType {
return fmt.Errorf("can't change object type directly: %w", domain.ErrValidationFailed)
}
if detail.Key == bundle.RelationKeyLayout {
if detail.Key == bundle.RelationKeyResolvedLayout {
// special case when client sets the layout detail directly instead of using SetLayoutInState command
return bs.SetLayoutInState(st, model.ObjectTypeLayout(detail.Value.Int64()), false)
}
Expand Down Expand Up @@ -410,7 +410,7 @@ func (bs *basic) SetLayoutInState(s *state.State, toLayout model.ObjectTypeLayou
}

fromLayout, _ := s.Layout()
s.SetDetail(bundle.RelationKeyLayout, domain.Int64(toLayout))
s.SetDetail(bundle.RelationKeyResolvedLayout, domain.Int64(toLayout))
if err = bs.layoutConverter.Convert(s, fromLayout, toLayout); err != nil {
return fmt.Errorf("convert layout: %w", err)
}
Expand Down
8 changes: 4 additions & 4 deletions core/block/editor/basic/details_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,10 @@ func TestBasic_SetObjectTypesInState(t *testing.T) {

f.lastUsed.EXPECT().UpdateLastUsedDate(mock.Anything, bundle.TypeKeyTask, mock.Anything).Return().Once()
f.store.AddObjects(t, []objectstore.TestObject{{
bundle.RelationKeySpaceId: domain.String(spaceId),
bundle.RelationKeyId: domain.String("ot-task"),
bundle.RelationKeyUniqueKey: domain.String("ot-task"),
bundle.RelationKeyLayout: domain.Int64(int64(model.ObjectType_todo)),
bundle.RelationKeySpaceId: domain.String(spaceId),
bundle.RelationKeyId: domain.String("ot-task"),
bundle.RelationKeyUniqueKey: domain.String("ot-task"),
bundle.RelationKeyResolvedLayout: domain.Int64(int64(model.ObjectType_todo)),
}})

s := f.sb.NewState()
Expand Down
5 changes: 3 additions & 2 deletions core/block/editor/basic/extract_objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func removeBlocks(state *state.State, descendants []simple.Block) {

func createTargetObjectDetails(nameText string, layout model.ObjectTypeLayout) *domain.Details {
details := domain.NewDetails()
details.SetInt64(bundle.RelationKeyLayout, int64(layout))
details.SetInt64(bundle.RelationKeyResolvedLayout, int64(layout))
// Without this check title will be duplicated in template.WithNameToFirstBlock
if layout != model.ObjectType_note {
details.SetString(bundle.RelationKeyName, nameText)
Expand Down Expand Up @@ -252,5 +252,6 @@ func copySubtreeOfBlocks(s *state.State, oldRootId string, oldBlocks []simple.Bl
}

func hasNoteLayout(s *state.State) bool {
return model.ObjectTypeLayout(s.Details().GetInt64(bundle.RelationKeyLayout)) == model.ObjectType_note
//nolint:gosec
return model.ObjectTypeLayout(s.LocalDetails().GetInt64(bundle.RelationKeyResolvedLayout)) == model.ObjectType_note
}
4 changes: 3 additions & 1 deletion core/block/editor/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ func (p *Dashboard) CreationStateMigration(ctx *smartblock.InitContext) migratio
Version: 2,
Proc: func(st *state.State) {
template.InitTemplate(st,
template.WithObjectTypesAndLayout([]domain.TypeKey{bundle.TypeKeyDashboard}, model.ObjectType_dashboard),
template.WithObjectTypes([]domain.TypeKey{bundle.TypeKeyDashboard}),
template.WithLayout(model.ObjectType_dashboard),
template.WithResolvedLayout(model.ObjectType_dashboard),
template.WithEmpty,
template.WithDetailName("Home"),
template.WithDetailIconEmoji("🏠"),
Expand Down
3 changes: 2 additions & 1 deletion core/block/editor/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ func (sf *sfile) SetFileTargetObjectId(ctx session.Context, blockId, targetObjec
return err
}
var blockContentFileType model.BlockContentFileType
switch model.ObjectTypeLayout(sb.Details().GetInt64(bundle.RelationKeyLayout)) {
//nolint:gosec
switch model.ObjectTypeLayout(sb.LocalDetails().GetInt64(bundle.RelationKeyResolvedLayout)) {
case model.ObjectType_image:
blockContentFileType = model.BlockContentFile_Image
case model.ObjectType_audio:
Expand Down
10 changes: 5 additions & 5 deletions core/block/editor/file/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func TestFile(t *testing.T) {
fx := newFixture(t)
fileSb := smarttest.New("root")
fileSb.SetDetails(nil, []domain.Detail{{
Key: bundle.RelationKeyLayout,
Key: bundle.RelationKeyResolvedLayout,
Value: domain.Int64(int64(testCase.typeLayout)),
}}, false)

Expand Down Expand Up @@ -160,7 +160,7 @@ func TestDropFiles(t *testing.T) {

fx := newFixture(t)
st := fx.sb.Doc.NewState()
st.SetDetail(bundle.RelationKeyLayout, domain.Int64(int64(model.ObjectType_collection)))
st.SetDetail(bundle.RelationKeyResolvedLayout, domain.Int64(int64(model.ObjectType_collection)))
fx.sb.Doc = st
fx.pickerFx.EXPECT().GetObject(context.Background(), "root").Return(fx, nil).Maybe()
fx.mockSender.EXPECT().Broadcast(mock.Anything).Return().Maybe()
Expand All @@ -185,7 +185,7 @@ func TestDropFiles(t *testing.T) {

fx := newFixture(t)
st := fx.sb.Doc.NewState()
st.SetDetail(bundle.RelationKeyLayout, domain.Int64(int64(model.ObjectType_collection)))
st.SetDetail(bundle.RelationKeyResolvedLayout, domain.Int64(int64(model.ObjectType_collection)))
fx.sb.Doc = st
fx.pickerFx.EXPECT().GetObject(context.Background(), "root").Return(fx, nil).Maybe()
fx.mockSender.EXPECT().Broadcast(mock.Anything).Return().Maybe()
Expand All @@ -210,7 +210,7 @@ func TestDropFiles(t *testing.T) {

fx := newFixture(t)
st := fx.sb.Doc.NewState()
st.SetDetail(bundle.RelationKeyLayout, domain.Int64(int64(model.ObjectType_collection)))
st.SetDetail(bundle.RelationKeyResolvedLayout, domain.Int64(int64(model.ObjectType_collection)))
fx.sb.Doc = st
fx.pickerFx.EXPECT().GetObject(context.Background(), "root").Return(fx, nil)
fx.mockSender.EXPECT().Broadcast(mock.Anything).Return()
Expand Down Expand Up @@ -245,7 +245,7 @@ func TestDropFiles(t *testing.T) {

fx := newFixture(t)
st := fx.sb.Doc.NewState()
st.SetDetail(bundle.RelationKeyLayout, domain.Int64(int64(model.ObjectType_collection)))
st.SetDetail(bundle.RelationKeyResolvedLayout, domain.Int64(int64(model.ObjectType_collection)))
fx.sb.Doc = st
fx.pickerFx.EXPECT().GetObject(context.Background(), "root").Return(fx, nil)
fx.mockSender.EXPECT().Broadcast(mock.Anything).Return()
Expand Down
14 changes: 10 additions & 4 deletions core/block/editor/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (p *Page) deleteRelationOptions(spaceID string, relationKey string) error {
Value: domain.String(relationKey),
},
{
RelationKey: bundle.RelationKeyLayout,
RelationKey: bundle.RelationKeyResolvedLayout,
Condition: model.BlockContentDataviewFilter_Equal,
Value: domain.Int64(model.ObjectType_relationOption),
},
Expand Down Expand Up @@ -172,8 +172,8 @@ func (p *Page) CreationStateMigration(ctx *smartblock.InitContext) migration.Mig

templates := []template.StateTransformer{
template.WithEmpty,
template.WithObjectTypesAndLayout(ctx.State.ObjectTypeKeys(), layout),
template.WithLayout(layout),
template.WithObjectTypes(ctx.State.ObjectTypeKeys()),
template.WithResolvedLayout(layout),
template.WithDefaultFeaturedRelations,
template.WithFeaturedRelations,
template.WithLinkFieldsMigration,
Expand Down Expand Up @@ -204,27 +204,33 @@ func (p *Page) CreationStateMigration(ctx *smartblock.InitContext) migration.Mig
templates = append(templates,
template.WithTitle,
template.WithAddedFeaturedRelation(bundle.RelationKeyType),
template.WithLayout(layout),
)
case model.ObjectType_objectType:
templates = append(templates,
template.WithTitle,
template.WithAddedFeaturedRelation(bundle.RelationKeyType),
template.WithLayout(layout),
)
case model.ObjectType_chat:
templates = append(templates,
template.WithTitle,
template.WithBlockChat,
template.WithLayout(layout),
)
case model.ObjectType_chatDerived:
templates = append(templates,
template.WithTitle,
template.WithBlockChat,
template.WithLayout(layout),
)
// TODO case for relationOption?
case model.ObjectType_tag:
templates = append(templates,
template.WithTitle,
template.WithNoDescription)
template.WithNoDescription,
template.WithLayout(layout),
)
default:
templates = append(templates,
template.WithTitle,
Expand Down
3 changes: 2 additions & 1 deletion core/block/editor/participant.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ func (p *participant) Init(ctx *smartblock.InitContext) (err error) {
ctx.State.SetDetailAndBundledRelation(bundle.RelationKeyIsReadonly, domain.Bool(true))
ctx.State.SetDetailAndBundledRelation(bundle.RelationKeyIsArchived, domain.Bool(false))
ctx.State.SetDetailAndBundledRelation(bundle.RelationKeyIsHidden, domain.Bool(false))
ctx.State.SetDetailAndBundledRelation(bundle.RelationKeyLayout, domain.Int64(model.ObjectType_participant))
ctx.State.SetDetailAndBundledRelation(bundle.RelationKeyLayoutAlign, domain.Int64(model.Block_AlignCenter))

records, err := p.objectStore.QueryByIds([]string{p.Id()})
Expand All @@ -64,6 +63,8 @@ func (p *participant) Init(ctx *smartblock.InitContext) (err error) {
template.WithTitle,
template.WithDescription,
template.WithFeaturedRelations,
template.WithLayout(model.ObjectType_participant),
template.WithResolvedLayout(model.ObjectType_participant),
template.WithAddedFeaturedRelation(bundle.RelationKeyType),
template.WithAddedFeaturedRelation(bundle.RelationKeyBacklinks),
)
Expand Down
2 changes: 1 addition & 1 deletion core/block/editor/participant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func newStoreFixture(t *testing.T) *spaceindex.StoreFixture {
for _, rel := range []domain.RelationKey{
bundle.RelationKeyFeaturedRelations, bundle.RelationKeyIdentity, bundle.RelationKeyName,
bundle.RelationKeyIdentityProfileLink, bundle.RelationKeyIsReadonly, bundle.RelationKeyIsArchived,
bundle.RelationKeyDescription, bundle.RelationKeyIsHidden, bundle.RelationKeyLayout,
bundle.RelationKeyDescription, bundle.RelationKeyIsHidden, bundle.RelationKeyResolvedLayout,
bundle.RelationKeyLayoutAlign, bundle.RelationKeyIconImage, bundle.RelationKeyGlobalName,
bundle.RelationKeyId, bundle.RelationKeyParticipantPermissions, bundle.RelationKeyLastModifiedBy,
bundle.RelationKeySpaceId, bundle.RelationKeyParticipantStatus, bundle.RelationKeyIsHiddenDiscovery,
Expand Down
4 changes: 3 additions & 1 deletion core/block/editor/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ func (p *Profile) CreationStateMigration(ctx *smartblock.InitContext) migration.
Version: 4,
Proc: func(st *state.State) {
template.InitTemplate(st,
template.WithObjectTypesAndLayout([]domain.TypeKey{bundle.TypeKeyProfile}, model.ObjectType_profile),
template.WithObjectTypes([]domain.TypeKey{bundle.TypeKeyProfile}),
template.WithLayout(model.ObjectType_profile),
template.WithResolvedLayout(model.ObjectType_profile),
template.WithDetail(bundle.RelationKeyLayoutAlign, domain.Int64(model.Block_AlignCenter)),
migrationSetHidden,
)
Expand Down
Loading
Loading