-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
DataViews: sort author by name + allow custom sort function #64064
Changes from all commits
f469303
7f4ecf1
6e9b21c
b1ce0e1
4460490
344ca6d
bcf814a
eaa0b63
621ac69
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { default as integer } from './integer'; | ||
import type { FieldType } from '../types'; | ||
|
||
/** | ||
* | ||
* @param {FieldType} type The field type definition to get. | ||
* | ||
* @return A field type definition. | ||
*/ | ||
export default function getFieldTypeDefinition( type?: FieldType ) { | ||
if ( 'integer' === type ) { | ||
return integer; | ||
} | ||
|
||
// If no type found, the sort function doesn't do anything. | ||
return { | ||
sort: () => 0, | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice file :) Should we move the "control" to the field types definition? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes! And validation, etc. I'll do that in a follow-up. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Validation moved to the type definition at #64164 |
||
* Internal dependencies | ||
*/ | ||
import type { SortDirection } from '../types'; | ||
|
||
function sort( a: any, b: any, direction: SortDirection ) { | ||
return direction === 'asc' ? a - b : b - a; | ||
} | ||
|
||
export default { | ||
sort, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,6 +143,15 @@ export function filterSortAndPaginate< Item >( | |
const valueA = fieldToSort.getValue( { item: a } ) ?? ''; | ||
const valueB = fieldToSort.getValue( { item: b } ) ?? ''; | ||
|
||
if ( fieldToSort.type === 'integer' ) { | ||
return fieldToSort.sort( | ||
oandregal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
a, | ||
b, | ||
view.sort?.direction ?? 'desc' | ||
); | ||
} | ||
|
||
// When/if types become required, we can remove the following logic. | ||
if ( | ||
typeof valueA === 'number' && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that I've left the existing logic here because |
||
typeof valueB === 'number' | ||
|
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.
What do we think of this? What do we do if the type is not found?