- navigate('/')} data-cy="testsuite-header-back-button">
+ navigate(runOriginPath)} data-cy="testsuite-header-back-button">
diff --git a/web/src/hooks/useRouterSync.ts b/web/src/hooks/useRouterSync.ts
index c90433d65f..18b962e50b 100644
--- a/web/src/hooks/useRouterSync.ts
+++ b/web/src/hooks/useRouterSync.ts
@@ -8,6 +8,10 @@ const useRouterSync = () => {
useEffect(() => {
return RouterMiddleware.startListening({testId: params.testId, runId: params.runId});
}, [params.runId, params.testId]);
+
+ useEffect(() => {
+ return RouterMiddleware.startListeningForLocationChange();
+ }, []);
};
export default useRouterSync;
diff --git a/web/src/redux/Router.middleware.ts b/web/src/redux/Router.middleware.ts
index a9d55037be..b6ea46df62 100644
--- a/web/src/redux/Router.middleware.ts
+++ b/web/src/redux/Router.middleware.ts
@@ -1,23 +1,30 @@
import {createListenerMiddleware} from '@reduxjs/toolkit';
+import type {TypedStartListening} from '@reduxjs/toolkit';
import {LOCATION_CHANGE} from 'redux-first-history';
import {parse} from 'query-string';
import RouterActions from './actions/Router.actions';
-import {RootState} from './store';
+import {runOriginPathAdded} from './slices/User.slice';
+import {AppDispatch, RootState} from './store';
+type AppStartListening = TypedStartListening;
const listener = createListenerMiddleware();
+const startAppListening = listener.startListening as AppStartListening;
const sideEffectActionList = [RouterActions.updateSelectedAssertion, RouterActions.updateSelectedSpan];
+const runUrlRegex = /^\/(test|testsuite)\/([^\/]+)\/run\/([^\/]+)(.*)$/;
+
const RouterMiddleware = () => ({
middleware: listener.middleware,
+
startListening(params = {}) {
- return listener.startListening({
+ return startAppListening({
predicate: ({type = ''}) =>
type === LOCATION_CHANGE || (type.endsWith('/fulfilled') && !type.startsWith('router/')),
effect(_, {dispatch, getState}) {
const {
router: {location},
- } = getState() as RootState;
+ } = getState();
const search = parse(location?.search || '');
@@ -27,6 +34,31 @@ const RouterMiddleware = () => ({
},
});
},
+
+ startListeningForLocationChange() {
+ return startAppListening({
+ predicate: action => {
+ const pathname = action?.payload?.location?.pathname ?? '';
+ return action?.type === LOCATION_CHANGE && pathname.match(runUrlRegex);
+ },
+ effect: async (_, {dispatch, getOriginalState, getState}) => {
+ const {
+ router: {location: prevLocation},
+ } = getOriginalState();
+
+ const {
+ router: {location: currLocation},
+ } = getState();
+
+ const prevPathname = prevLocation?.pathname ?? '';
+
+ if (!prevPathname.match(runUrlRegex)) {
+ const defaultPath = currLocation?.pathname?.includes('testsuite') ? '/testsuites' : '/';
+ dispatch(runOriginPathAdded(prevLocation?.pathname ?? defaultPath));
+ }
+ },
+ });
+ },
});
export default RouterMiddleware();
diff --git a/web/src/redux/slices/User.slice.ts b/web/src/redux/slices/User.slice.ts
index 2084e0925a..8f36cd8d88 100644
--- a/web/src/redux/slices/User.slice.ts
+++ b/web/src/redux/slices/User.slice.ts
@@ -1,9 +1,10 @@
-import {createAction, createSlice} from '@reduxjs/toolkit';
+import {PayloadAction, createAction, createSlice} from '@reduxjs/toolkit';
import UserPreferencesService from 'services/UserPreferences.service';
import {IUserState, TUserPreferenceKey, TUserPreferenceValue} from 'types/User.types';
export const initialState: IUserState = {
preferences: UserPreferencesService.get(),
+ runOriginPath: '/',
};
interface ISetUserPreferencesProps {
@@ -20,7 +21,11 @@ export const setUserPreference = createAction('user/setUserPreference', ({key, v
const userSlice = createSlice({
name: 'user',
initialState,
- reducers: {},
+ reducers: {
+ runOriginPathAdded(state, {payload}: PayloadAction) {
+ state.runOriginPath = payload;
+ },
+ },
extraReducers: builder => {
builder.addCase(setUserPreference, (state, {payload: {preferences}}) => {
state.preferences = preferences;
@@ -28,5 +33,5 @@ const userSlice = createSlice({
},
});
-// export const {} = testDefinitionSlice.actions;
+export const {runOriginPathAdded} = userSlice.actions;
export default userSlice.reducer;
diff --git a/web/src/selectors/User.selectors.ts b/web/src/selectors/User.selectors.ts
index 204af363f0..277b635e7f 100644
--- a/web/src/selectors/User.selectors.ts
+++ b/web/src/selectors/User.selectors.ts
@@ -13,6 +13,8 @@ const UserSelectors = () => ({
return user.preferences[key];
}
),
+
+ selectRunOriginPath: (state: RootState) => state.user.runOriginPath,
});
export default UserSelectors();
diff --git a/web/src/types/User.types.ts b/web/src/types/User.types.ts
index 1672b5b1b8..684ec379d9 100644
--- a/web/src/types/User.types.ts
+++ b/web/src/types/User.types.ts
@@ -12,4 +12,5 @@ export type TUserPreferenceValue