From f4fe8d74d28ed2c0a7429963333d325073be5e27 Mon Sep 17 00:00:00 2001 From: Jorge Costa Date: Thu, 15 Aug 2024 14:01:48 +0200 Subject: [PATCH] Fix: Changing sorting direction on patterns does nothing. (#64508) Co-authored-by: jorgefilipecosta Co-authored-by: t-hamano --- .../src/components/dataviews-view-config/index.tsx | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/dataviews/src/components/dataviews-view-config/index.tsx b/packages/dataviews/src/components/dataviews-view-config/index.tsx index 0aae714c5ce27..69b4cba776326 100644 --- a/packages/dataviews/src/components/dataviews-view-config/index.tsx +++ b/packages/dataviews/src/components/dataviews-view-config/index.tsx @@ -140,7 +140,7 @@ function SortFieldControl() { } function SortDirectionControl() { - const { view, onChangeView } = useContext( DataViewsContext ); + const { view, fields, onChangeView } = useContext( DataViewsContext ); return ( { - 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;