-
Notifications
You must be signed in to change notification settings - Fork 428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/define sorting #176
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks solid! A few nitpicks, but otherwise 👍
|
||
const OVERRIDABLE_FIELDS = ['jsonType', 'type', 'name', 'title', 'description', 'options', 'inputComponent'] | ||
const OVERRIDABLE_FIELDS = ['jsonType', 'sorting', 'type', 'name', 'title', 'description', 'options', 'inputComponent'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for derailing, but should I have added hidden
to this list, too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah! Looks like readOnly
is missing there too.
const DEFAULT_SORT_OPTIONS = [ | ||
{ | ||
title: 'Last edited', | ||
name: '__updatedAt', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not clear to me why these are double-underscored - is this intentional? If so, maybe add a comment explaining why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right - The double underscores were there to prevent conflicts with possible user-defined sort options with the same name. But on second thought; being able to override the semantics of updatedAt
is actually a nice feature that we could document.
: DEFAULT_SORT_OPTIONS).map(option => { | ||
return { | ||
...option, | ||
icon: SortIcon, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we should allow icon
to be specified in sort options? It would make sense to allow say a clock/calendar icon for date sorting and a Aa↓
icon for sorting by title, for instance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally! Will fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a solid implementation of a sorely needed feature. Thumbs up!
After a few IRL discussions we'd like to do a few minor changes to the proposed format:
Updated format: {
type: 'object',
name: 'myType',
// ...
orderings: [
{
title: 'Title',
name: 'title',
by: [
{field: 'title', direction: 'asc'},
{field: 'publicationYear', direction: 'desc'}
]
}
]
//...
} |
* [test-studio] Setup test cases * [schema] Support 'sorting' on object types + guess default sort config * [base] Pass view options to preview.prepare * [base] Expose sort icon * [desk-tool] Support custom sorting of documents list * [desk-tool] Remove unused state key * [desk-tool] Code nits * [desk-tool] Remove prefixed default sort options and make customizable * [desk-tool] Make icon configurable * [schema] Add missing overridable fields * [chore] More consistent usage of 'ordering'
This adds support for defining a set of sort options on schema types:
Example:
These will be options for sorting the list of documents, together with
_createdAt
and_updatedAt
This also introduces a second argument to
preview.prepare
calledviewOptions
. If the document to be previewed is subject to a certain sort order, the sorting will be passed in onviewOptions.sorting
. This allows for returning another preview title if the list of documents should be sorted by a field that is not normally visible, e.g. a localized field.