Skip to content

Commit

Permalink
[base] Provide size ordering + size subtitles for assets
Browse files Browse the repository at this point in the history
  • Loading branch information
rexxars committed Feb 22, 2018
1 parent e167b3e commit ad772ce
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
17 changes: 13 additions & 4 deletions packages/@sanity/base/src/schema/types/fileAsset.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export default {
{
name: 'originalFilename',
type: 'string',
title: 'Original file name'
title: 'Original file name',
readOnly: true
},
{
name: 'label',
Expand All @@ -39,7 +40,7 @@ export default {
type: 'number',
title: 'File size in bytes',
readOnly: true,
fieldset: 'system',
fieldset: 'system'
},
{
name: 'assetId',
Expand Down Expand Up @@ -68,12 +69,20 @@ export default {
title: 'originalFilename',
path: 'path',
mimeType: 'mimeType',
size: 'size'
},
prepare(doc) {
return {
title: doc.title || doc.path.split('/').slice(-1)[0],
subtitle: doc.mimeType
subtitle: `${doc.mimeType} (${(doc.size / 1024 / 1024).toFixed(2)} MB)`
}
}
}
},
orderings: [
{
title: 'File size',
name: 'fileSizeDesc',
by: [{field: 'size', direction: 'desc'}]
}
]
}
24 changes: 16 additions & 8 deletions packages/@sanity/base/src/schema/types/imageAsset.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const PALETTE_FIELDS = [
{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},
{name: 'title', type: 'string', title: 'String', readOnly: true}
]

export default {
Expand All @@ -20,7 +20,8 @@ export default {
{
name: 'originalFilename',
type: 'string',
title: 'Original file name'
title: 'Original file name',
readOnly: true
},
{
name: 'label',
Expand All @@ -46,7 +47,7 @@ export default {
type: 'number',
title: 'File size in bytes',
readOnly: true,
fieldset: 'system',
fieldset: 'system'
},
{
name: 'assetId',
Expand Down Expand Up @@ -118,17 +119,24 @@ export default {
],
preview: {
select: {
id: '_id',
title: 'originalFilename',
imageUrl: 'url',
path: 'path',
mimeType: 'mimeType',
size: 'size'
},
prepare(doc) {
return {
title: doc.title || doc.path.split('/').slice(-1)[0],
imageUrl: `${doc.imageUrl}?w=150`,
subtitle: doc.mimeType
media: {asset: {_ref: doc.id}},
subtitle: `${doc.mimeType} (${(doc.size / 1024 / 1024).toFixed(2)} MB)`
}
}
}
},
orderings: [
{
title: 'File size',
name: 'fileSizeDesc',
by: [{field: 'size', direction: 'desc'}]
}
]
}

0 comments on commit ad772ce

Please sign in to comment.