Skip to content

Commit

Permalink
Merge pull request #721 from anyproto/go-2300-clean-import-to-existin…
Browse files Browse the repository at this point in the history
…g-space

GO-2300: make widget collection not favorite for gallery
  • Loading branch information
AnastasiaShemyakinskaya authored Dec 15, 2023
2 parents 291c913 + 51163a1 commit f5a3f82
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 12 deletions.
8 changes: 4 additions & 4 deletions core/block/import/common/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ func (r *RootCollection) MakeRootCollection(collectionName string,
targetObjects []string,
icon string,
fileKeys []*pb.ChangeFileKeys,
needToAddDate bool,
needToAddDate, shouldBeFavorite bool,
) (*Snapshot, error) {
if needToAddDate {
importDate := time.Now().Format(time.RFC3339)
collectionName = fmt.Sprintf("%s %s", collectionName, importDate)
}
detailsStruct := r.getCreateCollectionRequest(collectionName, icon)
detailsStruct := r.getCreateCollectionRequest(collectionName, icon, shouldBeFavorite)
_, _, st, err := r.service.CreateCollection(detailsStruct, []*model.InternalFlag{{
Value: model.InternalFlag_collectionDontIndexLinks,
}})
Expand Down Expand Up @@ -102,11 +102,11 @@ func (r *RootCollection) addRelations(st *state.State) error {
return nil
}

func (r *RootCollection) getCreateCollectionRequest(collectionName string, icon string) *types.Struct {
func (r *RootCollection) getCreateCollectionRequest(collectionName string, icon string, shouldBeFavorite bool) *types.Struct {
details := make(map[string]*types.Value, 0)
details[bundle.RelationKeySourceFilePath.String()] = pbtypes.String(collectionName)
details[bundle.RelationKeyName.String()] = pbtypes.String(collectionName)
details[bundle.RelationKeyIsFavorite.String()] = pbtypes.Bool(true)
details[bundle.RelationKeyIsFavorite.String()] = pbtypes.Bool(shouldBeFavorite)
details[bundle.RelationKeyLayout.String()] = pbtypes.Float64(float64(model.ObjectType_collection))
details[bundle.RelationKeyIconImage.String()] = pbtypes.String(icon)

Expand Down
2 changes: 1 addition & 1 deletion core/block/import/csv/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (c *CSV) GetSnapshots(ctx context.Context, req *pb.RpcObjectImportRequest,
return nil, allErrors
}
rootCollection := common.NewRootCollection(c.collectionService)
rootCol, err := rootCollection.MakeRootCollection(rootCollectionName, result.objectIDs, "", nil, true)
rootCol, err := rootCollection.MakeRootCollection(rootCollectionName, result.objectIDs, "", nil, true, true)
if err != nil {
allErrors.Add(err)
if req.Mode == pb.RpcObjectImportRequest_ALL_OR_NOTHING {
Expand Down
2 changes: 1 addition & 1 deletion core/block/import/html/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (h *HTML) GetSnapshots(ctx context.Context, req *pb.RpcObjectImportRequest,
return nil, allErrors
}
rootCollection := common.NewRootCollection(h.collectionService)
rootCollectionSnapshot, err := rootCollection.MakeRootCollection(rootCollectionName, targetObjects, "", nil, true)
rootCollectionSnapshot, err := rootCollection.MakeRootCollection(rootCollectionName, targetObjects, "", nil, true, true)
if err != nil {
allErrors.Add(err)
if allErrors.ShouldAbortImport(len(path), req.Type) {
Expand Down
2 changes: 1 addition & 1 deletion core/block/import/markdown/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (m *Markdown) processFiles(req *pb.RpcObjectImportRequest, progress process
func (m *Markdown) createRootCollection(allSnapshots []*common.Snapshot) ([]*common.Snapshot, string, error) {
targetObjects := m.getObjectIDs(allSnapshots)
rootCollection := common.NewRootCollection(m.service)
rootCol, err := rootCollection.MakeRootCollection(rootCollectionName, targetObjects, "", nil, true)
rootCol, err := rootCollection.MakeRootCollection(rootCollectionName, targetObjects, "", nil, true, true)
if err != nil {
return nil, "", err
}
Expand Down
2 changes: 1 addition & 1 deletion core/block/import/notion/api/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ func (ds *Service) AddObjectsToNotionCollection(notionContext *api.NotionImportC
allObjects := ds.filterObjects(notionContext, notionDB, notionPages)

rootCollection := common.NewRootCollection(ds.collectionService)
rootCol, err := rootCollection.MakeRootCollection(rootCollectionName, allObjects, "", nil, true)
rootCol, err := rootCollection.MakeRootCollection(rootCollectionName, allObjects, "", nil, true, true)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions core/block/import/pb/gallery.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (g *GalleryImport) ProvideCollection(snapshots []*common.Snapshot,
}
}
objectsIDs := g.getObjectsIDs(snapshots)
objectsCollection, err := rootCollection.MakeRootCollection(collectionName, objectsIDs, icon, fileKeys, false)
objectsCollection, err := rootCollection.MakeRootCollection(collectionName, objectsIDs, icon, fileKeys, false, true)
if err != nil {
return nil, err
}
Expand All @@ -77,7 +77,7 @@ func (g *GalleryImport) getWidgetsCollection(collectionName string,
collectionsSnapshots []*common.Snapshot,
) ([]*common.Snapshot, error) {
widgetCollectionName := collectionName + widgetCollectionPattern
widgetsCollectionSnapshot, err := rootCollection.MakeRootCollection(widgetCollectionName, widgetObjects, icon, fileKeys, false)
widgetsCollectionSnapshot, err := rootCollection.MakeRootCollection(widgetCollectionName, widgetObjects, icon, fileKeys, false, false)
if err != nil {
return nil, err
}
Expand Down
1 change: 1 addition & 0 deletions core/block/import/pb/gallery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ func TestGalleryImport_ProvideCollection(t *testing.T) {
objectsInCollection := rootCollectionState.GetStoreSlice(template.CollectionStoreKey)
assert.Len(t, objectsInCollection, 1)
assert.Equal(t, objectsInCollection[0], "oldObjectInWidget")
assert.False(t, pbtypes.GetBool(rootCollectionState.Details(), bundle.RelationKeyIsFavorite.String()))

rootCollectionState = state.NewDocFromSnapshot("", collection[1].Snapshot).(*state.State)
objectsInCollection = rootCollectionState.GetStoreSlice(template.CollectionStoreKey)
Expand Down
2 changes: 1 addition & 1 deletion core/block/import/pb/space.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (s *SpaceImport) ProvideCollection(snapshots []*common.Snapshot,
})
}
rootCollection := common.NewRootCollection(s.service)
rootCollectionSnapshot, err := rootCollection.MakeRootCollection(rootCollectionName, rootObjects, "", nil, true)
rootCollectionSnapshot, err := rootCollection.MakeRootCollection(rootCollectionName, rootObjects, "", nil, true, true)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion core/block/import/txt/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (t *TXT) GetSnapshots(ctx context.Context, req *pb.RpcObjectImportRequest,
return nil, allErrors
}
rootCollection := common.NewRootCollection(t.service)
rootCol, err := rootCollection.MakeRootCollection(rootCollectionName, targetObjects, "", nil, true)
rootCol, err := rootCollection.MakeRootCollection(rootCollectionName, targetObjects, "", nil, true, true)
if err != nil {
allErrors.Add(err)
if allErrors.ShouldAbortImport(len(paths), req.Type) {
Expand Down

0 comments on commit f5a3f82

Please sign in to comment.