added SchemaField.Presentable field
This commit is contained in:
@@ -132,6 +132,10 @@ type SchemaField struct {
|
||||
Type string `form:"type" json:"type"`
|
||||
Required bool `form:"required" json:"required"`
|
||||
|
||||
// Presentable indicates whether the field is suitable for
|
||||
// visualization purposes (eg. in the Admin UI relation views).
|
||||
Presentable bool `form:"presentable" json:"presentable"`
|
||||
|
||||
// Deprecated: This field is no-op and will be removed in future versions.
|
||||
// Please use the collection.Indexes field to define a unique constraint.
|
||||
Unique bool `form:"unique" json:"unique"`
|
||||
@@ -645,7 +649,8 @@ type RelationOptions struct {
|
||||
// If nil no limits are applied.
|
||||
MaxSelect *int `form:"maxSelect" json:"maxSelect"`
|
||||
|
||||
// DisplayFields is optional slice of collection field names used for UI purposes.
|
||||
// Deprecated: This field is no-op and will be removed in future versions.
|
||||
// Instead use the individula SchemaField.Presentable option for each field in the relation collection.
|
||||
DisplayFields []string `form:"displayFields" json:"displayFields"`
|
||||
}
|
||||
|
||||
|
||||
@@ -129,19 +129,19 @@ func TestSchemaFieldColDefinition(t *testing.T) {
|
||||
|
||||
func TestSchemaFieldString(t *testing.T) {
|
||||
f := schema.SchemaField{
|
||||
Id: "abc",
|
||||
Name: "test",
|
||||
Type: schema.FieldTypeText,
|
||||
Required: true,
|
||||
Unique: false,
|
||||
System: true,
|
||||
Id: "abc",
|
||||
Name: "test",
|
||||
Type: schema.FieldTypeText,
|
||||
Required: true,
|
||||
Presentable: true,
|
||||
System: true,
|
||||
Options: &schema.TextOptions{
|
||||
Pattern: "test",
|
||||
},
|
||||
}
|
||||
|
||||
result := f.String()
|
||||
expected := `{"system":true,"id":"abc","name":"test","type":"text","required":true,"unique":false,"options":{"min":null,"max":null,"pattern":"test"}}`
|
||||
expected := `{"system":true,"id":"abc","name":"test","type":"text","required":true,"presentable":true,"unique":false,"options":{"min":null,"max":null,"pattern":"test"}}`
|
||||
|
||||
if result != expected {
|
||||
t.Errorf("Expected \n%v, got \n%v", expected, result)
|
||||
@@ -156,19 +156,19 @@ func TestSchemaFieldMarshalJSON(t *testing.T) {
|
||||
// empty
|
||||
{
|
||||
schema.SchemaField{},
|
||||
`{"system":false,"id":"","name":"","type":"","required":false,"unique":false,"options":null}`,
|
||||
`{"system":false,"id":"","name":"","type":"","required":false,"presentable":false,"unique":false,"options":null}`,
|
||||
},
|
||||
// without defined options
|
||||
{
|
||||
schema.SchemaField{
|
||||
Id: "abc",
|
||||
Name: "test",
|
||||
Type: schema.FieldTypeText,
|
||||
Required: true,
|
||||
Unique: false,
|
||||
System: true,
|
||||
Id: "abc",
|
||||
Name: "test",
|
||||
Type: schema.FieldTypeText,
|
||||
Required: true,
|
||||
Presentable: true,
|
||||
System: true,
|
||||
},
|
||||
`{"system":true,"id":"abc","name":"test","type":"text","required":true,"unique":false,"options":{"min":null,"max":null,"pattern":""}}`,
|
||||
`{"system":true,"id":"abc","name":"test","type":"text","required":true,"presentable":true,"unique":false,"options":{"min":null,"max":null,"pattern":""}}`,
|
||||
},
|
||||
// with defined options
|
||||
{
|
||||
@@ -182,7 +182,7 @@ func TestSchemaFieldMarshalJSON(t *testing.T) {
|
||||
Pattern: "test",
|
||||
},
|
||||
},
|
||||
`{"system":true,"id":"","name":"test","type":"text","required":true,"unique":false,"options":{"min":null,"max":null,"pattern":"test"}}`,
|
||||
`{"system":true,"id":"","name":"test","type":"text","required":true,"presentable":false,"unique":false,"options":{"min":null,"max":null,"pattern":"test"}}`,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -207,32 +207,32 @@ func TestSchemaFieldUnmarshalJSON(t *testing.T) {
|
||||
{
|
||||
nil,
|
||||
true,
|
||||
`{"system":false,"id":"","name":"","type":"","required":false,"unique":false,"options":null}`,
|
||||
`{"system":false,"id":"","name":"","type":"","required":false,"presentable":false,"unique":false,"options":null}`,
|
||||
},
|
||||
{
|
||||
[]byte{},
|
||||
true,
|
||||
`{"system":false,"id":"","name":"","type":"","required":false,"unique":false,"options":null}`,
|
||||
`{"system":false,"id":"","name":"","type":"","required":false,"presentable":false,"unique":false,"options":null}`,
|
||||
},
|
||||
{
|
||||
[]byte(`{"system": true}`),
|
||||
true,
|
||||
`{"system":true,"id":"","name":"","type":"","required":false,"unique":false,"options":null}`,
|
||||
`{"system":true,"id":"","name":"","type":"","required":false,"presentable":false,"unique":false,"options":null}`,
|
||||
},
|
||||
{
|
||||
[]byte(`{"invalid"`),
|
||||
true,
|
||||
`{"system":false,"id":"","name":"","type":"","required":false,"unique":false,"options":null}`,
|
||||
`{"system":false,"id":"","name":"","type":"","required":false,"presentable":false,"unique":false,"options":null}`,
|
||||
},
|
||||
{
|
||||
[]byte(`{"type":"text","system":true}`),
|
||||
false,
|
||||
`{"system":true,"id":"","name":"","type":"text","required":false,"unique":false,"options":{"min":null,"max":null,"pattern":""}}`,
|
||||
`{"system":true,"id":"","name":"","type":"text","required":false,"presentable":false,"unique":false,"options":{"min":null,"max":null,"pattern":""}}`,
|
||||
},
|
||||
{
|
||||
[]byte(`{"type":"text","options":{"pattern":"test"}}`),
|
||||
false,
|
||||
`{"system":false,"id":"","name":"","type":"text","required":false,"unique":false,"options":{"min":null,"max":null,"pattern":"test"}}`,
|
||||
`{"system":false,"id":"","name":"","type":"text","required":false,"presentable":false,"unique":false,"options":{"min":null,"max":null,"pattern":"test"}}`,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -470,72 +470,72 @@ func TestSchemaFieldInitOptions(t *testing.T) {
|
||||
{
|
||||
schema.SchemaField{},
|
||||
true,
|
||||
`{"system":false,"id":"","name":"","type":"","required":false,"unique":false,"options":null}`,
|
||||
`{"system":false,"id":"","name":"","type":"","required":false,"presentable":false,"unique":false,"options":null}`,
|
||||
},
|
||||
{
|
||||
schema.SchemaField{Type: "unknown"},
|
||||
true,
|
||||
`{"system":false,"id":"","name":"","type":"unknown","required":false,"unique":false,"options":null}`,
|
||||
`{"system":false,"id":"","name":"","type":"unknown","required":false,"presentable":false,"unique":false,"options":null}`,
|
||||
},
|
||||
{
|
||||
schema.SchemaField{Type: schema.FieldTypeText},
|
||||
false,
|
||||
`{"system":false,"id":"","name":"","type":"text","required":false,"unique":false,"options":{"min":null,"max":null,"pattern":""}}`,
|
||||
`{"system":false,"id":"","name":"","type":"text","required":false,"presentable":false,"unique":false,"options":{"min":null,"max":null,"pattern":""}}`,
|
||||
},
|
||||
{
|
||||
schema.SchemaField{Type: schema.FieldTypeNumber},
|
||||
false,
|
||||
`{"system":false,"id":"","name":"","type":"number","required":false,"unique":false,"options":{"min":null,"max":null}}`,
|
||||
`{"system":false,"id":"","name":"","type":"number","required":false,"presentable":false,"unique":false,"options":{"min":null,"max":null}}`,
|
||||
},
|
||||
{
|
||||
schema.SchemaField{Type: schema.FieldTypeBool},
|
||||
false,
|
||||
`{"system":false,"id":"","name":"","type":"bool","required":false,"unique":false,"options":{}}`,
|
||||
`{"system":false,"id":"","name":"","type":"bool","required":false,"presentable":false,"unique":false,"options":{}}`,
|
||||
},
|
||||
{
|
||||
schema.SchemaField{Type: schema.FieldTypeEmail},
|
||||
false,
|
||||
`{"system":false,"id":"","name":"","type":"email","required":false,"unique":false,"options":{"exceptDomains":null,"onlyDomains":null}}`,
|
||||
`{"system":false,"id":"","name":"","type":"email","required":false,"presentable":false,"unique":false,"options":{"exceptDomains":null,"onlyDomains":null}}`,
|
||||
},
|
||||
{
|
||||
schema.SchemaField{Type: schema.FieldTypeUrl},
|
||||
false,
|
||||
`{"system":false,"id":"","name":"","type":"url","required":false,"unique":false,"options":{"exceptDomains":null,"onlyDomains":null}}`,
|
||||
`{"system":false,"id":"","name":"","type":"url","required":false,"presentable":false,"unique":false,"options":{"exceptDomains":null,"onlyDomains":null}}`,
|
||||
},
|
||||
{
|
||||
schema.SchemaField{Type: schema.FieldTypeEditor},
|
||||
false,
|
||||
`{"system":false,"id":"","name":"","type":"editor","required":false,"unique":false,"options":{}}`,
|
||||
`{"system":false,"id":"","name":"","type":"editor","required":false,"presentable":false,"unique":false,"options":{}}`,
|
||||
},
|
||||
{
|
||||
schema.SchemaField{Type: schema.FieldTypeDate},
|
||||
false,
|
||||
`{"system":false,"id":"","name":"","type":"date","required":false,"unique":false,"options":{"min":"","max":""}}`,
|
||||
`{"system":false,"id":"","name":"","type":"date","required":false,"presentable":false,"unique":false,"options":{"min":"","max":""}}`,
|
||||
},
|
||||
{
|
||||
schema.SchemaField{Type: schema.FieldTypeSelect},
|
||||
false,
|
||||
`{"system":false,"id":"","name":"","type":"select","required":false,"unique":false,"options":{"maxSelect":0,"values":null}}`,
|
||||
`{"system":false,"id":"","name":"","type":"select","required":false,"presentable":false,"unique":false,"options":{"maxSelect":0,"values":null}}`,
|
||||
},
|
||||
{
|
||||
schema.SchemaField{Type: schema.FieldTypeJson},
|
||||
false,
|
||||
`{"system":false,"id":"","name":"","type":"json","required":false,"unique":false,"options":{}}`,
|
||||
`{"system":false,"id":"","name":"","type":"json","required":false,"presentable":false,"unique":false,"options":{}}`,
|
||||
},
|
||||
{
|
||||
schema.SchemaField{Type: schema.FieldTypeFile},
|
||||
false,
|
||||
`{"system":false,"id":"","name":"","type":"file","required":false,"unique":false,"options":{"maxSelect":0,"maxSize":0,"mimeTypes":null,"thumbs":null,"protected":false}}`,
|
||||
`{"system":false,"id":"","name":"","type":"file","required":false,"presentable":false,"unique":false,"options":{"maxSelect":0,"maxSize":0,"mimeTypes":null,"thumbs":null,"protected":false}}`,
|
||||
},
|
||||
{
|
||||
schema.SchemaField{Type: schema.FieldTypeRelation},
|
||||
false,
|
||||
`{"system":false,"id":"","name":"","type":"relation","required":false,"unique":false,"options":{"collectionId":"","cascadeDelete":false,"minSelect":null,"maxSelect":null,"displayFields":null}}`,
|
||||
`{"system":false,"id":"","name":"","type":"relation","required":false,"presentable":false,"unique":false,"options":{"collectionId":"","cascadeDelete":false,"minSelect":null,"maxSelect":null,"displayFields":null}}`,
|
||||
},
|
||||
{
|
||||
schema.SchemaField{Type: schema.FieldTypeUser},
|
||||
false,
|
||||
`{"system":false,"id":"","name":"","type":"user","required":false,"unique":false,"options":{"maxSelect":0,"cascadeDelete":false}}`,
|
||||
`{"system":false,"id":"","name":"","type":"user","required":false,"presentable":false,"unique":false,"options":{"maxSelect":0,"cascadeDelete":false}}`,
|
||||
},
|
||||
{
|
||||
schema.SchemaField{
|
||||
@@ -543,7 +543,7 @@ func TestSchemaFieldInitOptions(t *testing.T) {
|
||||
Options: &schema.TextOptions{Pattern: "test"},
|
||||
},
|
||||
false,
|
||||
`{"system":false,"id":"","name":"","type":"text","required":false,"unique":false,"options":{"min":null,"max":null,"pattern":"test"}}`,
|
||||
`{"system":false,"id":"","name":"","type":"text","required":false,"presentable":false,"unique":false,"options":{"min":null,"max":null,"pattern":"test"}}`,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -286,7 +286,7 @@ func TestSchemaMarshalJSON(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
expected := `[{"system":false,"id":"f1id","name":"test1","type":"text","required":false,"unique":false,"options":{"min":null,"max":null,"pattern":""}},{"system":false,"id":"f2id","name":"test2","type":"text","required":false,"unique":false,"options":{"min":null,"max":null,"pattern":"test"}}]`
|
||||
expected := `[{"system":false,"id":"f1id","name":"test1","type":"text","required":false,"presentable":false,"unique":false,"options":{"min":null,"max":null,"pattern":""}},{"system":false,"id":"f2id","name":"test2","type":"text","required":false,"presentable":false,"unique":false,"options":{"min":null,"max":null,"pattern":"test"}}]`
|
||||
|
||||
if string(result) != expected {
|
||||
t.Fatalf("Expected %s, got %s", expected, string(result))
|
||||
@@ -354,7 +354,7 @@ func TestSchemaValue(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
expected := `[{"system":false,"id":"f1id","name":"test1","type":"text","required":false,"unique":false,"options":{"min":null,"max":null,"pattern":""}}]`
|
||||
expected := `[{"system":false,"id":"f1id","name":"test1","type":"text","required":false,"presentable":false,"unique":false,"options":{"min":null,"max":null,"pattern":""}}]`
|
||||
|
||||
if v2 != expected {
|
||||
t.Fatalf("Expected %v, got %v", expected, v2)
|
||||
@@ -377,21 +377,21 @@ func TestSchemaScan(t *testing.T) {
|
||||
{`[{}]`, true, `[]`},
|
||||
// unknown field type
|
||||
{
|
||||
`[{"system":false,"id":"123","name":"test1","type":"unknown","required":false,"unique":false}]`,
|
||||
`[{"system":false,"id":"123","name":"test1","type":"unknown","required":false,"presentable":false,"unique":false}]`,
|
||||
true,
|
||||
`[]`,
|
||||
},
|
||||
// without options
|
||||
{
|
||||
`[{"system":false,"id":"123","name":"test1","type":"text","required":false,"unique":false}]`,
|
||||
`[{"system":false,"id":"123","name":"test1","type":"text","required":false,"presentable":false,"unique":false}]`,
|
||||
false,
|
||||
`[{"system":false,"id":"123","name":"test1","type":"text","required":false,"unique":false,"options":{"min":null,"max":null,"pattern":""}}]`,
|
||||
`[{"system":false,"id":"123","name":"test1","type":"text","required":false,"presentable":false,"unique":false,"options":{"min":null,"max":null,"pattern":""}}]`,
|
||||
},
|
||||
// with options
|
||||
{
|
||||
`[{"system":false,"id":"123","name":"test1","type":"text","required":false,"unique":false,"options":{"min":null,"max":null,"pattern":"test"}}]`,
|
||||
`[{"system":false,"id":"123","name":"test1","type":"text","required":false,"presentable":false,"unique":false,"options":{"min":null,"max":null,"pattern":"test"}}]`,
|
||||
false,
|
||||
`[{"system":false,"id":"123","name":"test1","type":"text","required":false,"unique":false,"options":{"min":null,"max":null,"pattern":"test"}}]`,
|
||||
`[{"system":false,"id":"123","name":"test1","type":"text","required":false,"presentable":false,"unique":false,"options":{"min":null,"max":null,"pattern":"test"}}]`,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user