Skip to content

Commit

Permalink
Fix: Changing sorting direction on patterns does nothing. (#64508)
Browse files Browse the repository at this point in the history
Co-authored-by: jorgefilipecosta <jorgefilipecosta@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
  • Loading branch information
3 people authored Aug 15, 2024
1 parent cdbd582 commit f4fe8d7
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ function SortFieldControl() {
}

function SortDirectionControl() {
const { view, onChangeView } = useContext( DataViewsContext );
const { view, fields, onChangeView } = useContext( DataViewsContext );
return (
<ToggleGroupControl
className="dataviews-view-config__sort-direction"
Expand All @@ -149,17 +149,19 @@ function SortDirectionControl() {
isBlock
label={ __( 'Order' ) }
value={ view.sort?.direction || 'desc' }
disabled={ ! view?.sort?.field }
onChange={ ( newDirection ) => {
if ( ! view?.sort?.field ) {
return;
}
if ( newDirection === 'asc' || newDirection === 'desc' ) {
onChangeView( {
...view,
sort: {
direction: newDirection,
field: view.sort.field,
field:
view.sort?.field ||
// If there is no field assigned as the sorting field assign the first sortable field.
fields.find(
( field ) => field.enableSorting !== false
)?.id ||
'',
},
} );
return;
Expand Down

0 comments on commit f4fe8d7

Please sign in to comment.