Skip to content
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

Fix: Changing sorting direction on patterns does nothing. #64508

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading