mirror of
https://github.com/anyproto/anytype-heart.git
synced 2025-06-08 05:47:07 +09:00
Merge pull request #2299 from anyproto/go-5279-new-welcome-page
GO-5279 New welcome page
This commit is contained in:
commit
e5a52131fd
7 changed files with 61 additions and 9 deletions
|
@ -116,6 +116,10 @@ func validateDetails(s *pb.SnapshotWithType, info *useCaseInfo) (err error) {
|
|||
continue
|
||||
}
|
||||
|
||||
if k == bundle.RelationKeyAutoWidgetTargets.String() && val == "bin" {
|
||||
continue
|
||||
}
|
||||
|
||||
_, found := info.objects[val]
|
||||
if !found {
|
||||
if isBrokenTemplate(k, val) {
|
||||
|
|
|
@ -95,7 +95,7 @@ func (ot *ObjectType) Init(ctx *smartblock.InitContext) (err error) {
|
|||
|
||||
func (ot *ObjectType) CreationStateMigration(ctx *smartblock.InitContext) migration.Migration {
|
||||
return migration.Migration{
|
||||
Version: 2,
|
||||
Version: 4,
|
||||
Proc: func(s *state.State) {
|
||||
if len(ctx.ObjectTypeKeys) > 0 && len(ctx.State.ObjectTypeKeys()) == 0 {
|
||||
ctx.State.SetObjectTypeKeys(ctx.ObjectTypeKeys)
|
||||
|
@ -417,7 +417,7 @@ func (ot *ObjectType) dataviewTemplates() []template.StateTransformer {
|
|||
|
||||
dvContent.Dataview.TargetObjectId = ot.Id()
|
||||
return []template.StateTransformer{
|
||||
template.WithDataviewID(state.DataviewBlockID, dvContent, false),
|
||||
template.WithDataviewIDIfNotExists(state.DataviewBlockID, dvContent, false),
|
||||
template.WithForcedDetail(bundle.RelationKeySetOf, domain.StringList([]string{ot.Id()})),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -405,6 +405,22 @@ var WithAllBlocksEditsRestricted = StateTransformer(func(s *state.State) {
|
|||
})
|
||||
})
|
||||
|
||||
var WithDataviewIDIfNotExists = func(id string, dataview *model.BlockContentOfDataview, forceViews bool) StateTransformer {
|
||||
return func(s *state.State) {
|
||||
WithEmpty(s)
|
||||
if !s.Exists(id) {
|
||||
s.Set(simple.New(&model.Block{Content: dataview, Id: id}))
|
||||
if !s.IsParentOf(s.RootId(), id) {
|
||||
err := s.InsertTo(s.RootId(), model.Block_Inner, id)
|
||||
if err != nil {
|
||||
log.Errorf("template WithDataview failed to insert: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
var WithDataviewID = func(id string, dataview *model.BlockContentOfDataview, forceViews bool) StateTransformer {
|
||||
return func(s *state.State) {
|
||||
WithEmpty(s)
|
||||
|
@ -414,10 +430,8 @@ var WithDataviewID = func(id string, dataview *model.BlockContentOfDataview, for
|
|||
if dvBlock, ok := b.(simpleDataview.Block); !ok {
|
||||
return true
|
||||
} else {
|
||||
if len(dvBlock.Model().GetDataview().Relations) == 0 ||
|
||||
!slice.UnsortedEqual(dvBlock.Model().GetDataview().Source, dataview.Dataview.Source) ||
|
||||
if !slice.UnsortedEqual(dvBlock.Model().GetDataview().Source, dataview.Dataview.Source) ||
|
||||
len(dvBlock.Model().GetDataview().Views) == 0 ||
|
||||
forceViews && len(dvBlock.Model().GetDataview().Relations) != len(dataview.Dataview.Relations) ||
|
||||
forceViews && !pbtypes.DataviewViewsEqualSorted(dvBlock.Model().GetDataview().Views, dataview.Dataview.Views) {
|
||||
|
||||
/* log.With("object" s.RootId()).With("name", pbtypes.GetString(s.Details(), "name")).Warnf("dataview needs to be migrated: %v, %v, %v, %v",
|
||||
|
|
|
@ -166,7 +166,6 @@ func (oc *ObjectCreator) Create(dataObject *DataObject, sn *common.Snapshot) (*d
|
|||
|
||||
func canUpdateObject(sbType coresb.SmartBlockType) bool {
|
||||
return sbType != coresb.SmartBlockTypeRelation &&
|
||||
sbType != coresb.SmartBlockTypeObjectType &&
|
||||
sbType != coresb.SmartBlockTypeRelationOption &&
|
||||
sbType != coresb.SmartBlockTypeFileObject &&
|
||||
sbType != coresb.SmartBlockTypeParticipant
|
||||
|
|
|
@ -42,6 +42,7 @@ import (
|
|||
"github.com/anyproto/anytype-heart/pb"
|
||||
"github.com/anyproto/anytype-heart/pkg/lib/bundle"
|
||||
"github.com/anyproto/anytype-heart/pkg/lib/core"
|
||||
"github.com/anyproto/anytype-heart/pkg/lib/core/smartblock"
|
||||
"github.com/anyproto/anytype-heart/pkg/lib/localstore/addr"
|
||||
"github.com/anyproto/anytype-heart/pkg/lib/localstore/filestore"
|
||||
"github.com/anyproto/anytype-heart/pkg/lib/localstore/objectstore"
|
||||
|
@ -494,7 +495,15 @@ func (i *Import) getObjectID(
|
|||
return err
|
||||
}
|
||||
oldIDToNew[snapshot.Id] = id
|
||||
if payload.RootRawChange != nil {
|
||||
var isBundled bool
|
||||
switch snapshot.Snapshot.SbType {
|
||||
case smartblock.SmartBlockTypeObjectType:
|
||||
isBundled = bundle.HasObjectTypeByKey(domain.TypeKey(snapshot.Snapshot.Data.Key))
|
||||
case smartblock.SmartBlockTypeRelation:
|
||||
isBundled = bundle.HasRelation(domain.RelationKey(snapshot.Snapshot.Data.Key))
|
||||
}
|
||||
// bundled types will be created and then updated, cause they can be installed asynchronously
|
||||
if payload.RootRawChange != nil && !isBundled {
|
||||
createPayloads[id] = payload
|
||||
}
|
||||
return i.extractInternalKey(snapshot, oldIDToNew)
|
||||
|
|
|
@ -259,7 +259,7 @@ func (b *builtinObjects) importArchive(
|
|||
importRequest := &importer.ImportRequest{
|
||||
RpcObjectImportRequest: &pb.RpcObjectImportRequest{
|
||||
SpaceId: spaceID,
|
||||
UpdateExistingObjects: false,
|
||||
UpdateExistingObjects: true,
|
||||
Type: model.Import_Pb,
|
||||
Mode: pb.RpcObjectImportRequest_ALL_OR_NOTHING,
|
||||
NoProgress: progress == nil,
|
||||
|
@ -392,7 +392,7 @@ func (b *builtinObjects) createWidgets(ctx session.Context, spaceId string, useC
|
|||
log.Errorf("failed to get type id: %w", err)
|
||||
return
|
||||
}
|
||||
for _, typeId := range []string{pageTypeId, taskTypeId} {
|
||||
for _, typeId := range []string{taskTypeId, pageTypeId} {
|
||||
if has, err := b.typeHasObjects(spaceId, typeId); err != nil {
|
||||
log.Warnf("failed to check if type '%s' has objects: %v", pageTypeId, err)
|
||||
} else if has {
|
||||
|
@ -400,10 +400,36 @@ func (b *builtinObjects) createWidgets(ctx session.Context, spaceId string, useC
|
|||
}
|
||||
}
|
||||
|
||||
var welcomePageId string
|
||||
if useCase == pb.RpcObjectImportUseCaseRequest_GET_STARTED {
|
||||
welcomePageId, err = b.getNewObjectID(spaceId, "bafyreidbxbw522cupdbxgzdpqayqb33ttvhyhlquprnbcgvpfp2p7pd4tq")
|
||||
if err != nil {
|
||||
log.Errorf("failed to get welcome page: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
if len(widgetTargetsToCreate) == 0 {
|
||||
return
|
||||
}
|
||||
if err = cache.DoStateCtx(b.objectGetter, ctx, widgetObjectID, func(s *state.State, w widget.Widget) error {
|
||||
|
||||
if useCase == pb.RpcObjectImportUseCaseRequest_GET_STARTED && welcomePageId != "" {
|
||||
if _, err = w.CreateBlock(s, &pb.RpcBlockCreateWidgetRequest{
|
||||
ContextId: s.RootId(),
|
||||
WidgetLayout: model.BlockContentWidget_Link,
|
||||
Position: model.Block_InnerFirst,
|
||||
TargetId: s.RootId(),
|
||||
Block: &model.Block{
|
||||
Id: "welcome",
|
||||
Content: &model.BlockContentOfLink{Link: &model.BlockContentLink{
|
||||
TargetBlockId: welcomePageId,
|
||||
}},
|
||||
},
|
||||
}); err != nil {
|
||||
log.Errorf("failed to add welcome page widget: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
for _, targetId := range widgetTargetsToCreate {
|
||||
if err := w.AddAutoWidget(s, targetId, "", addr.ObjectTypeAllViewId, model.BlockContentWidget_View, ""); err != nil {
|
||||
log.Errorf("failed to create widget block for type '%s': %v", targetId, err)
|
||||
|
|
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue