Skip to content

Commit

Permalink
fix(server): cannot unset a schema field's title (#1073)
Browse files Browse the repository at this point in the history
* fix title unsetting bug

* Update server/pkg/schema/schema.go

Co-authored-by: yk-eukarya <[email protected]>

---------

Co-authored-by: yk-eukarya <[email protected]>
  • Loading branch information
mimoham24 and yk-eukarya authored Feb 22, 2024
1 parent 06ad138 commit 55d7d6c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 3 additions & 1 deletion server/e2e/gql_field_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ func TestCreateField(t *testing.T) {
tags := res.Path("$.data.node.schema.fields[0].typeProperty.tags").Raw().([]any)

_, _ = updateField(e, mId, fId, "test", "test", "test",
true, true, true, true, nil, "Tag",
true, true, false, true, nil, "Tag",
map[string]any{
"tag": map[string]any{
"defaultValue": []string{"s1", "s3"},
Expand All @@ -385,6 +385,8 @@ func TestCreateField(t *testing.T) {
Value("node").Object().
HasValue("id", mId)

title := res.Path("$.data.node.schema.fields[0].isTitle").Raw().(bool)
assert.False(t, title)
_, _ = createField(e, mId, "test2", "test2", "test2",
false, false, false, false, "Tag",
map[string]any{
Expand Down
7 changes: 6 additions & 1 deletion server/pkg/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,13 @@ func (s *Schema) TitleField() *FieldID {
}

func (s *Schema) SetTitleField(tf *FieldID) error {
if !s.HasField(*tf) || s.Fields() == nil || len(s.Fields()) == 0 {
// unsetting title
if tf == nil {
s.titleField = nil
return nil
}

if !s.HasField(*tf) || s.Fields() == nil || len(s.Fields()) == 0 {
return ErrInvalidTitleField
}
s.titleField = tf.CloneRef()
Expand Down

0 comments on commit 55d7d6c

Please sign in to comment.