Skip to content

Commit

Permalink
Fix: Allow to set the filter via URL query parameter
Browse files Browse the repository at this point in the history
Drop `usePageFilter` `locationQueryFilterString` because the query param
filter gathered from `useSearchParams` is the only valid value.

Drop `FilterProvider` `locationQuery` prop because a string was passed
instead of the expected query object and because usePageFilter already
handles its use case internally via `useSearchParams`.
  • Loading branch information
bjoernricks committed Jan 13, 2025
1 parent 2da1ff3 commit efc436f
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 17 deletions.
5 changes: 0 additions & 5 deletions src/web/entities/filterprovider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ const FilterProvider = ({
fallbackFilter,
gmpname,
pageName = gmpname,
locationQuery = {},
}) => {
const [returnedFilter, isLoadingFilter] = usePageFilter(pageName, gmpname, {
fallbackFilter,
locationQueryFilterString: locationQuery?.filter,
});
return (
<React.Fragment>
Expand All @@ -29,9 +27,6 @@ const FilterProvider = ({
FilterProvider.propTypes = {
fallbackFilter: PropTypes.filter,
gmpname: PropTypes.string,
locationQuery: PropTypes.shape({
filter: PropTypes.string,
}),
pageName: PropTypes.string,
};

Expand Down
1 change: 0 additions & 1 deletion src/web/entities/withEntitiesContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ const withEntitiesContainer =
<FilterProvider
fallbackFilter={fallbackFilter}
gmpname={gmpname}
locationQuery={searchParams.toString()}
>
{({filter}) => (
<EntitiesContainerWrapper
Expand Down
13 changes: 2 additions & 11 deletions src/web/hooks/usePageFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,7 @@ const useDefaultFilter = pageName =>
* filter and function to reset the filter
*/

const usePageFilter = (
pageName,
gmpName,
{
fallbackFilter,
locationQueryFilterString: initialLocationQueryFilterString,
} = {},
) => {
const usePageFilter = (pageName, gmpName, {fallbackFilter} = {}) => {
const gmp = useGmp();
const dispatch = useDispatch();
const [searchParams, setSearchParams] = useSearchParams();
Expand All @@ -73,9 +66,7 @@ const usePageFilter = (

// use null as value for not set at all
let returnedFilter;
// only use searchParams directly if locationQueryFilterString is undefined
const locationQueryFilterString =
initialLocationQueryFilterString || searchParams.get('filter');
const locationQueryFilterString = searchParams.get('filter');

const [locationQueryFilter, setLocationQueryFilter] = useState(
hasValue(locationQueryFilterString)
Expand Down

0 comments on commit efc436f

Please sign in to comment.