From 2469012008d4dd3cb9b1bec0b0f4abbeccd0d1a1 Mon Sep 17 00:00:00 2001 From: WithoutPants <53250216+WithoutPants@users.noreply.github.com> Date: Fri, 4 Jun 2021 09:49:10 +1000 Subject: [PATCH] Fix empty sort by causing UI crash (#1480) --- ui/v2.5/src/components/List/ListFilter.tsx | 4 +++- ui/v2.5/src/hooks/ListHook.tsx | 9 ++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/ui/v2.5/src/components/List/ListFilter.tsx b/ui/v2.5/src/components/List/ListFilter.tsx index 2ef6d07ec..fb74171a2 100644 --- a/ui/v2.5/src/components/List/ListFilter.tsx +++ b/ui/v2.5/src/components/List/ListFilter.tsx @@ -499,7 +499,9 @@ export const ListFilter: React.FC = ( - {intl.formatMessage({ id: currentSortBy?.messageID })} + {currentSortBy + ? intl.formatMessage({ id: currentSortBy.messageID }) + : ""} {renderSortByOptions()} diff --git a/ui/v2.5/src/hooks/ListHook.tsx b/ui/v2.5/src/hooks/ListHook.tsx index 73c62d43c..18141336c 100644 --- a/ui/v2.5/src/hooks/ListHook.tsx +++ b/ui/v2.5/src/hooks/ListHook.tsx @@ -450,11 +450,9 @@ const useList = ( const originalPathName = useRef(location.pathname); const persistanceKey = options.persistanceKey ?? options.filterMode; + const defaultSort = options.defaultSort ?? filterOptions.defaultSortBy; const [filter, setFilter] = useState( - new ListFilterModel( - queryString.parse(location.search), - options.defaultSort ?? filterOptions.defaultSortBy - ) + new ListFilterModel(queryString.parse(location.search), defaultSort) ); const updateInterfaceConfig = useCallback( @@ -515,7 +513,7 @@ const useList = ( } : activeFilter; - const newFilter = new ListFilterModel(query); + const newFilter = new ListFilterModel(query, defaultSort); // Compare constructed filter with current filter. // If different it's the result of navigation, and we update the filter. @@ -531,6 +529,7 @@ const useList = ( history.replace(newLocation); } }, [ + defaultSort, filter, interfaceState.data, interfaceState.loading,