1
0
Fork 0
mirror of https://github.com/anyproto/anytype-heart.git synced 2025-06-09 17:44:59 +09:00

Merge pull request #209 from anyproto/go-1136-columns-with-the-same-names-disappear-csv-import

GO-1136: remove spaces from CSV relations
This commit is contained in:
Anastasia Shemyakinskaya 2023-07-21 12:24:00 +02:00 committed by GitHub
commit 36a1043646
Signed by: github
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 1 deletions

View file

@ -8,6 +8,7 @@ import (
"github.com/globalsign/mgo/bson"
"github.com/gogo/protobuf/types"
"github.com/google/uuid"
"github.com/samber/lo"
"github.com/anyproto/anytype-heart/core/block/collection"
"github.com/anyproto/anytype-heart/core/block/editor/state"
@ -77,7 +78,7 @@ func getDetailsFromCSVTable(csvTable [][]string, useFirstRowForRelations bool) (
Key: bundle.RelationKeyName.String(),
})
relationsSnapshots := make([]*converter.Snapshot, 0, len(csvTable[0]))
allRelations := csvTable[0]
allRelations := lo.Map(csvTable[0], func(item string, index int) string { return strings.TrimSpace(item) })
var err error
numberOfRelationsLimit := len(allRelations)
if numberOfRelationsLimit > limitForColumns {

View file

@ -562,3 +562,45 @@ func Test_findUniqueRelationAndAddNumber(t *testing.T) {
assert.Equal(t, []string{"relation1", "1", "2", "relation", "3", "relation 1"}, result)
})
}
func Test_findUniqueRelationWithSpaces(t *testing.T) {
csv := CSV{}
p := process.NewProgress(pb.ModelProcess_Import)
sn, err := csv.GetSnapshots(&pb.RpcObjectImportRequest{
Params: &pb.RpcObjectImportRequestParamsOfCsvParams{
CsvParams: &pb.RpcObjectImportRequestCsvParams{
Path: []string{"testdata/relationswithspaces.csv"},
Delimiter: ";",
UseFirstRowForRelations: true,
},
},
Type: pb.RpcObjectImportRequest_Csv,
Mode: pb.RpcObjectImportRequest_IGNORE_ERRORS,
}, p)
assert.Nil(t, err)
assert.NotNil(t, sn)
var subObjects []*converter.Snapshot
for _, snapshot := range sn.Snapshots {
if snapshot.SbType == sb.SmartBlockTypeSubObject {
subObjects = append(subObjects, snapshot)
}
}
assert.Len(t, subObjects, 5)
name := pbtypes.GetString(subObjects[0].Snapshot.Data.Details, bundle.RelationKeyName.String())
assert.True(t, name == "Text")
name = pbtypes.GetString(subObjects[1].Snapshot.Data.Details, bundle.RelationKeyName.String())
assert.True(t, name == "Text 1")
name = pbtypes.GetString(subObjects[2].Snapshot.Data.Details, bundle.RelationKeyName.String())
assert.True(t, name == "Text 3")
name = pbtypes.GetString(subObjects[3].Snapshot.Data.Details, bundle.RelationKeyName.String())
assert.True(t, name == "Text 2")
name = pbtypes.GetString(subObjects[4].Snapshot.Data.Details, bundle.RelationKeyName.String())
assert.True(t, name == "Text 4")
}

View file

@ -0,0 +1,4 @@
Name;Text;Text ;Text ;Text 2;Text
Text;aaa;bbb;ccc;ddd;eee
Text;1;2;3;4;5
;;;;;
1 Name Text Text Text Text 2 Text
2 Text aaa bbb ccc ddd eee
3 Text 1 2 3 4 5
4