Skip to content
Merged
5 changes: 5 additions & 0 deletions changelog/unreleased/issue-22105.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type = "f"
message = "Fix browser navigation not restoring the previous search"

issues = ["22105", "18484"]
pulls = ["24583"]
4 changes: 2 additions & 2 deletions graylog2-web-interface/src/views/components/Search.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import mockSearchesClusterConfig from 'fixtures/searchClusterConfig';

import OriginalSearch from './Search';

import { useSyncWithQueryParameters } from '../hooks/SyncWithQueryParameters';
import useSyncWithQueryParameters from '../hooks/useSyncWithQueryParameters';

jest.mock('views/logic/fieldtypes/useFieldTypes');

Expand All @@ -49,7 +49,7 @@ jest.mock('views/components/DashboardSearchBar', () => () => (
</button>
));

jest.mock('views/hooks/SyncWithQueryParameters');
jest.mock('views/hooks/useSyncWithQueryParameters');

jest.mock('routing/withLocation', () => (Component) => (props) => (
<Component location={{ query: {}, pathname: '', search: '' }} {...props} />
Expand Down
20 changes: 16 additions & 4 deletions graylog2-web-interface/src/views/components/SynchronizeUrl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,33 @@
*/
import { useEffect } from 'react';

import { useSyncWithQueryParameters } from 'views/hooks/SyncWithQueryParameters';
import useSyncWithQueryParameters from 'views/hooks/useSyncWithQueryParameters';
import bindSearchParamsFromQuery from 'views/hooks/BindSearchParamsFromQuery';
import type { ViewsDispatch } from 'views/stores/useViewsDispatch';
import useViewsDispatch from 'views/stores/useViewsDispatch';
import type { RootState } from 'views/types';
import { selectView } from 'views/logic/slices/viewSelectors';
import useViewsDispatch from 'views/stores/useViewsDispatch';
import { selectSearchExecutionState } from 'views/logic/slices/searchExecutionSelectors';
import useLocation from 'routing/useLocation';
import useQuery from 'routing/useQuery';
import { updateView } from 'views/logic/slices/viewSlice';

const bindSearchParamsFromQueryThunk =
(query: { [key: string]: unknown }) => (_dispatch: ViewsDispatch, getState: () => RootState) => {
(query: { [key: string]: unknown }) => async (dispatch: ViewsDispatch, getState: () => RootState) => {
const view = selectView(getState());
const executionState = selectSearchExecutionState(getState());
bindSearchParamsFromQuery({ view, query, retry: () => Promise.resolve(), executionState });

const result = await bindSearchParamsFromQuery({ view, query, retry: () => Promise.resolve(), executionState });

if (!result) {
return Promise.resolve();
}

const [newView] = result;

if (newView !== view) {
return dispatch(updateView(newView, true));
}
Copy link
Contributor Author

@linuspahl linuspahl Dec 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is required to update the reflux store with the new view which contains the changes URL query params.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling updateView also executes a new search and creates a new entry in the undo / redo stack.

};

const useBindSearchParamsFromQuery = (query: { [key: string]: unknown }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import isDeepEqual from 'stores/isDeepEqual';
import type { ViewHook, ViewHookArguments } from 'views/logic/hooks/ViewHook';
import View from 'views/logic/views/View';
import normalizeSearchURLQueryParams from 'views/logic/NormalizeSearchURLQueryParams';
import createSearch from 'views/logic/slices/createSearch';

const bindSearchParamsFromQuery: ViewHook = async ({ query, view, executionState }: ViewHookArguments) => {
if (view.type !== View.Type.Search) {
Expand Down Expand Up @@ -68,11 +67,8 @@ const bindSearchParamsFromQuery: ViewHook = async ({ query, view, executionState
return [view, executionState];
}

const newSearch = view.search.toBuilder().newId().queries([newQuery]).build();

const savedSearch = await createSearch(newSearch);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are now calling updateView in bindSearchParamsFromQueryThunk we don't need to call it here anymore.


const newView = view.toBuilder().search(savedSearch).build();
const newSearch = view.search.toBuilder().queries([newQuery]).build();
const newView = view.toBuilder().search(newSearch).build();

return [newView, executionState];
};
Expand Down

This file was deleted.

Loading
Loading