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-4785: Fix subscription deps #1973

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion core/block/editor/basic/details.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func (bs *basic) validateDetailFormat(spaceID string, key domain.RelationKey, v

return nil
case model.RelationFormat_file, model.RelationFormat_object:
vals, ok := v.TryStringList()
vals, ok := v.TryWrapToStringList()
if !ok {
return fmt.Errorf("incorrect type: %v instead of string list", v)
}
Expand Down
6 changes: 5 additions & 1 deletion core/block/editor/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package file

import (
"context"
"errors"
"fmt"
"os"
"path/filepath"
Expand Down Expand Up @@ -306,11 +307,14 @@ func (sf *sfile) dropFilesCreateStructure(groupId, targetId string, pos model.Bl
}

func (sf *sfile) dropFilesSetInfo(info dropFileInfo) (err error) {
if info.err == context.Canceled {
if errors.Is(info.err, context.Canceled) {
s := sf.NewState().SetGroupId(info.groupId)
s.Unlink(info.blockId)
return sf.Apply(s)
}
if info.err != nil {
return fmt.Errorf("drop file: %w", info.err)
}
if isCollection(sf) {
s := sf.NewState()
if !s.HasInStore([]string{info.file.TargetObjectId}) {
Expand Down
3 changes: 1 addition & 2 deletions core/block/editor/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -1129,8 +1129,7 @@
}

func (s *State) modifyIdsInDetail(details *domain.Details, key domain.RelationKey, modifier func(id string) string) {
// TODO TryStringList in pbtypes return []string{singleValue} for string values
if ids := details.GetStringList(key); len(ids) > 0 {
if ids := details.WrapToStringList(key); len(ids) > 0 {

Check failure on line 1132 in core/block/editor/state/state.go

View workflow job for this annotation

GitHub Actions / lint

`if len(ids) > 0` has complex nested blocks (complexity: 6) (nestif)
var anyChanges bool
for i, oldId := range ids {
if oldId == "" {
Expand Down
4 changes: 4 additions & 0 deletions core/domain/genericmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ func (d *GenericMap[K]) GetStringList(key K) []string {
return d.Get(key).StringList()
}

func (d *GenericMap[K]) WrapToStringList(key K) []string {
return d.Get(key).WrapToStringList()
}

func (d *GenericMap[K]) TryFloat64List(key K) ([]float64, bool) {
return d.Get(key).TryFloat64List()
}
Expand Down
20 changes: 20 additions & 0 deletions core/domain/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,26 @@ func (v Value) StringList() []string {
return res
}

func (v Value) TryWrapToStringList() ([]string, bool) {
res, ok := v.TryStringList()
if ok {
return res, true
}
s, ok := v.TryString()
if ok {
return []string{s}, true
}
return nil, false
}

func (v Value) WrapToStringList() []string {
res, ok := v.TryWrapToStringList()
if ok {
return res
}
return nil
}

func (v Value) IsInt64List() bool {
return v.IsFloat64List()
}
Expand Down
2 changes: 1 addition & 1 deletion core/subscription/dep.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (ds *dependencyService) depIdsByEntries(entries []*entry, depKeys []domain.
depIds = forceIds
for _, e := range entries {
for _, k := range depKeys {
for _, depId := range e.data.GetStringList(k) {
for _, depId := range e.data.WrapToStringList(k) {
if depId != "" && slice.FindPos(depIds, depId) == -1 && depId != e.id {
depIds = append(depIds, depId)
}
Expand Down
27 changes: 0 additions & 27 deletions util/pbtypes/pbtypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,33 +517,6 @@ func BundledRelationIdToKey(id string) (string, error) {
return "", fmt.Errorf("incorrect id format")
}

func Map(s *types.Struct, keys ...string) *types.Struct {
if len(keys) == 0 {
return s
}
if s == nil {
return nil
}
ns := new(types.Struct)
if s.Fields == nil {
return ns
}
ns.Fields = make(map[string]*types.Value)
for _, key := range keys {
if value, ok := s.Fields[key]; ok {
ns.Fields[key] = value
}
}
return ns
}

func MapN(structs []*types.Struct, keys ...string) []*types.Struct {
for i, s := range structs {
structs[i] = Map(s, keys...)
}
return structs
}

func StructIterate(st *types.Struct, f func(path []string, v *types.Value)) {
var iterate func(s *types.Struct, f func(path []string, v *types.Value), path []string)
iterate = func(s *types.Struct, f func(path []string, v *types.Value), path []string) {
Expand Down
33 changes: 0 additions & 33 deletions util/pbtypes/pbtypes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (

"github.com/gogo/protobuf/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/exp/maps"
)

func TestGet(t *testing.T) {
Expand Down Expand Up @@ -179,34 +177,3 @@ func TestIsEmptyValueOrAbsent(t *testing.T) {
})
}
}

func TestMapN(t *testing.T) {
// given
structs := []*types.Struct{
{Fields: map[string]*types.Value{
"name": String("obj1"),
"id": String("obj1"),
"key": String("obj1"),
}},
{Fields: map[string]*types.Value{
"name": String("obj2"),
"id": String("obj2"),
"links": StringList([]string{"obj1", "obj3"}),
}},
{Fields: map[string]*types.Value{
"name": String("obj3"),
"id": String("obj3"),
"number": Int64(42),
}},
}
keys := []string{"name", "id"}

// when
mapped := MapN(structs, keys...)

// then
require.Len(t, mapped, 3)
assert.Len(t, maps.Keys(mapped[0].Fields), 2)
assert.Len(t, maps.Keys(mapped[1].Fields), 2)
assert.Len(t, maps.Keys(mapped[2].Fields), 2)
}
Loading