Skip to content

Commit

Permalink
[base] More asset schema tweaks (#282)
Browse files Browse the repository at this point in the history
  • Loading branch information
bjoerge committed Oct 19, 2017
1 parent 9fa5ca6 commit 192e4a8
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 34 deletions.
28 changes: 20 additions & 8 deletions packages/@sanity/base/src/schema/types/fileAsset.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default {
{
name: 'system',
title: 'System fields',
description: 'These are read only'
description: 'These fields are managed by the system and not editable'
}
],
fields: [
Expand All @@ -16,19 +16,23 @@ export default {
title: 'Original file name'
},
{
name: 'extension',
name: 'label',
type: 'string',
title: 'File extension'
title: 'Label'
},
{
name: 'mimeType',
name: 'extension',
type: 'string',
title: 'Mime type'
title: 'File extension',
readOnly: true,
fieldset: 'system'
},
{
name: 'label',
name: 'mimeType',
type: 'string',
title: 'Label'
title: 'Mime type',
readOnly: true,
fieldset: 'system'
},
{
name: 'size',
Expand Down Expand Up @@ -61,7 +65,15 @@ export default {
],
preview: {
select: {
title: 'originalFilename'
title: 'originalFilename',
path: 'path',
mimeType: 'mimeType',
},
prepare(doc) {
return {
title: doc.title || doc.path.split('/').slice(-1)[0],
subtitle: doc.mimeType
}
}
}
}
68 changes: 42 additions & 26 deletions packages/@sanity/base/src/schema/types/imageAsset.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
const PALETTE_FIELDS = [
{name: 'background', type: 'string', title: 'Background'},
{name: 'foreground', type: 'string', title: 'Foreground'},
{name: 'population', type: 'number', title: 'Population'},
{name: 'title', type: 'string', title: 'String'},
{name: 'background', type: 'string', title: 'Background', readOnly: true},
{name: 'foreground', type: 'string', title: 'Foreground', readOnly: true},
{name: 'population', type: 'number', title: 'Population', readOnly: true},
{name: 'title', type: 'string', title: 'String', readOnly: true},
]

export default {
name: 'sanity.imageAsset',
title: 'Image',
Expand All @@ -12,14 +13,7 @@ export default {
{
name: 'system',
title: 'System fields',
description: 'These are read only'
},
{
name: 'metadata',
title: 'Extra metadata…',
options: {
collapsable: true
}
description: 'These fields are managed by the system and not editable'
}
],
fields: [
Expand All @@ -29,19 +23,23 @@ export default {
title: 'Original file name'
},
{
name: 'extension',
name: 'label',
type: 'string',
title: 'File extension'
title: 'Label'
},
{
name: 'mimeType',
name: 'extension',
type: 'string',
title: 'Mime type'
readOnly: true,
title: 'File extension',
fieldset: 'system'
},
{
name: 'label',
name: 'mimeType',
type: 'string',
title: 'Label'
readOnly: true,
title: 'Mime type',
fieldset: 'system'
},
{
name: 'size',
Expand Down Expand Up @@ -75,8 +73,15 @@ export default {
name: 'metadata',
type: 'object',
title: 'Metadata',
readOnly: true,
fieldset: 'metadata',
fieldsets: [
{
name: 'extra',
title: 'Extra metadata…',
options: {
collapsable: true
}
}
],
fields: [
{
name: 'location',
Expand All @@ -87,10 +92,11 @@ export default {
type: 'object',
title: 'Dimensions',
fields: [
{name: 'height', type: 'number', title: 'Height'},
{name: 'width', type: 'number', title: 'Width'},
{name: 'aspectRatio', type: 'number', title: 'Aspect ratio'}
]
{name: 'height', type: 'number', title: 'Height', readOnly: true},
{name: 'width', type: 'number', title: 'Width', readOnly: true},
{name: 'aspectRatio', type: 'number', title: 'Aspect ratio', readOnly: true}
],
fieldset: 'extra'
},
{
name: 'palette',
Expand All @@ -104,15 +110,25 @@ export default {
{name: 'dominant', type: 'object', title: 'Dominant', fields: PALETTE_FIELDS},
{name: 'lightMuted', type: 'object', title: 'Light Muted', fields: PALETTE_FIELDS},
{name: 'muted', type: 'object', title: 'Muted', fields: PALETTE_FIELDS}
]
],
fieldset: 'extra'
}
]
}
],
preview: {
select: {
title: 'originalFilename',
imageUrl: 'url'
imageUrl: 'url',
path: 'path',
mimeType: 'mimeType',
},
prepare(doc) {
return {
title: doc.title || doc.path.split('/').slice(-1)[0],
imageUrl: `${doc.imageUrl}?w=150`,
subtitle: doc.mimeType
}
}
}
}

0 comments on commit 192e4a8

Please sign in to comment.