Skip to content

Commit

Permalink
Merge pull request #118 from anyproto/go-1561-usecase-design-fixes
Browse files Browse the repository at this point in the history
GO-1561 Usecases | Design fixes
  • Loading branch information
KirillSto authored Jun 30, 2023
2 parents e9ba62f + 0bde4dc commit 1d707fc
Show file tree
Hide file tree
Showing 12 changed files with 118 additions and 16 deletions.
75 changes: 75 additions & 0 deletions cmd/archiveprocessor/excluded.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package main

import (
_ "embed"
"encoding/json"
"fmt"
"strings"

"github.com/anyproto/anytype-heart/pkg/lib/pb/model"
)

//go:embed excluded.json
var excludedJson []byte

const (
objectTypeIdPattern = "ot-"
relationIdPattern = "rel-"
)

var (
objectsToExcludeSlice []string
objectsToExclude map[string]struct{}

shouldObjectTypesBeExcluded = false
shouldRelationsBeExcluded = false

sbTypesToBeExcluded = map[model.SmartBlockType]struct{}{
model.SmartBlockType_Workspace: {},
model.SmartBlockType_Widget: {},
model.SmartBlockType_ProfilePage: {},
model.SmartBlockType_Template: {},
}
)

func init() {
err := json.Unmarshal(excludedJson, &objectsToExcludeSlice)
if err != nil {
panic(fmt.Errorf("failed to unmarshal excluded.json: %v", err))
}
objectsToExclude = make(map[string]struct{})
for _, id := range objectsToExcludeSlice {
switch id {
case objectTypeIdPattern:
shouldObjectTypesBeExcluded = true
case relationIdPattern:
shouldRelationsBeExcluded = true
default:
objectsToExclude[id] = struct{}{}
}
}
}

func shouldBeExcluded(id string, sbType model.SmartBlockType) bool {
if _, found := sbTypesToBeExcluded[sbType]; found {
fmt.Printf("Smartblock '%s' is excluded as has type %s\n", id, sbType.String())
return true
}

if shouldObjectTypesBeExcluded && strings.HasPrefix(id, objectTypeIdPattern) {
fmt.Printf("Smartblock '%s' is excluded as it is object type\n", id)
return true
}

if shouldRelationsBeExcluded && strings.HasPrefix(id, relationIdPattern) {
fmt.Printf("Smartblock '%s' is excluded as it is relation\n", id)
return true
}

if _, found := objectsToExclude[id]; found {
fmt.Printf("Smartblock '%s' is excluded as it is listed in 'excluded.json'\n", id)
return true
}

return false
}
2 changes: 2 additions & 0 deletions cmd/archiveprocessor/excluded.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[
]
27 changes: 15 additions & 12 deletions cmd/archiveprocessor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,7 @@ type useCaseInfo struct {

const anytypeProfileFilename = addr.AnytypeProfileId + ".pb"

var (
errIncorrectFileFound = fmt.Errorf("incorrect protobuf file was found")

sbTypesToBeExcluded = map[model.SmartBlockType]struct{}{
model.SmartBlockType_Workspace: {},
model.SmartBlockType_Widget: {},
model.SmartBlockType_ProfilePage: {},
model.SmartBlockType_Template: {},
}
)
var errIncorrectFileFound = fmt.Errorf("incorrect protobuf file was found")

func main() {
if err := run(); err != nil {
Expand Down Expand Up @@ -174,8 +165,7 @@ func processFile(r io.ReadCloser, name string, info *useCaseInfo) ([]byte, error
return nil, err
}

if _, found := sbTypesToBeExcluded[sbType]; found {
fmt.Printf("Smartblock '%s' is excluded as has type %s\n", id, sbType.String())
if shouldBeExcluded(id, sbType) {
return nil, nil
}
fmt.Println(id, "\t", snapshot.Data.Details.Fields[bundle.RelationKeyName.String()].GetStringValue())
Expand Down Expand Up @@ -228,6 +218,19 @@ func processAndValidate(snapshot *pb.ChangeSnapshot, info *useCaseInfo) error {
processAccountRelatedDetails(snapshot)
processRules(snapshot)

if id == "bafyreibop22didlfnzyoplncnhd5cqrevjw5nwud3maqrzeq6h7jzedhmi" {
snapshot.Data.Blocks[15].Content.(*model.BlockContentOfBookmark).Bookmark = &model.BlockContentBookmark{
TargetObjectId: "bafyreidj2g3i6lc3udtlrr5ytcsgusywcyecepcirk5cans6aoxw2nnmhy",
Type: model.LinkPreview_Page,
State: model.BlockContentBookmark_Done,
Url: "https://community.anytype.io/",
Title: "Anytype Community",
Description: "Place to share feedback, write bug reports, and connect with Anytype users from all over the globe!",
ImageHash: "bafybeib4mags3wtdcpnlwcysqby6kdhvy2hbk3s54owcqmpvjwlv4xe7ky",
FaviconHash: "bafybeiasl27gslws4hpvzufm467zjhxb3klodj53rt6dpola67bmvep3x4",
}
}

if !strings.HasPrefix(id, addr.RelationKeyToIdPrefix) && !strings.HasPrefix(id, addr.ObjectTypeKeyToIdPrefix) {
isValid := true
for _, v := range validators {
Expand Down
2 changes: 1 addition & 1 deletion cmd/archiveprocessor/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func getRelationLinkByKey(links []*model.RelationLink, key string) *model.Relati

func snapshotHasKeyForHash(s *pb.ChangeSnapshot, hash string) bool {
for _, k := range s.FileKeys {
if k.Hash == hash {
if k.Hash == hash && len(k.Keys) > 0 {
return true
}
}
Expand Down
1 change: 0 additions & 1 deletion core/block/editor/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ func (p *Page) CreationStateMigration(ctx *smartblock.InitContext) migration.Mig
case model.ObjectType_todo:
templates = append(templates,
template.WithTitle,
template.WithDescription,
template.WithRelations([]bundle.RelationKey{bundle.RelationKeyDone}),
)
case model.ObjectType_bookmark:
Expand Down
18 changes: 16 additions & 2 deletions pkg/lib/bundle/relation.gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ source: pkg/lib/bundle/relations.json
package bundle

import (
"github.com/anyproto/anytype-heart/pkg/lib/localstore/addr"
addr "github.com/anyproto/anytype-heart/pkg/lib/localstore/addr"
"github.com/anyproto/anytype-heart/pkg/lib/pb/model"
)

const RelationChecksum = "a30a07c4418915a9c1eef7f6fd679e4e494ae0031018c8567973158de94ae207"
const RelationChecksum = "b4fb721c0937e69e97e0d5be67e5fab27a674afdc3a4e9a0c4323b4e7e5414ec"

type RelationKey string

Expand Down Expand Up @@ -163,6 +163,7 @@ const (
RelationKeySourceFilePath RelationKey = "sourceFilePath"
RelationKeyFileSyncStatus RelationKey = "fileSyncStatus"
RelationKeyLastChangeId RelationKey = "lastChangeId"
RelationKeyStarred RelationKey = "starred"
RelationKeyDefaultTemplateId RelationKey = "defaultTemplateId"
)

Expand Down Expand Up @@ -1788,6 +1789,19 @@ var (
ReadOnlyRelation: true,
Scope: model.Relation_type,
},
RelationKeyStarred: {

DataSource: model.Relation_details,
Description: "",
Format: model.RelationFormat_checkbox,
Id: "_brstarred",
Key: "starred",
MaxCount: 1,
Name: "Starred",
ReadOnly: false,
ReadOnlyRelation: true,
Scope: model.Relation_type,
},
RelationKeyStars: {

DataSource: model.Relation_details,
Expand Down
9 changes: 9 additions & 0 deletions pkg/lib/bundle/relations.json
Original file line number Diff line number Diff line change
Expand Up @@ -1381,6 +1381,15 @@
"readonly": true,
"source": "derived"
},
{
"format": "checkbox",
"hidden": false,
"key": "starred",
"maxCount": 1,
"name": "Starred",
"readonly": false,
"source": "details"
},
{
"description": "ID of template chosen as default for particular object type",
"format": "object",
Expand Down
Binary file modified util/builtinobjects/data/knowledge_base.zip
Binary file not shown.
Binary file modified util/builtinobjects/data/notes_diary.zip
Binary file not shown.
Binary file modified util/builtinobjects/data/personal_projects.zip
Binary file not shown.
Binary file modified util/builtinobjects/data/skip.zip
Binary file not shown.
Binary file modified util/builtintemplate/data/bundled_templates.zip
Binary file not shown.

0 comments on commit 1d707fc

Please sign in to comment.