mirror of
https://github.com/datahub-project/datahub.git
synced 2025-11-02 03:39:03 +00:00
fix(ui) Remove initial redirect logic from frontend (#8401)
This commit is contained in:
parent
dafb15071a
commit
564d8a3760
@ -3,7 +3,6 @@ import { useGetMeLazyQuery } from '../../graphql/me.generated';
|
||||
import { useGetGlobalViewsSettingsLazyQuery } from '../../graphql/app.generated';
|
||||
import { CorpUser, PlatformPrivileges } from '../../types.generated';
|
||||
import { UserContext, LocalState, DEFAULT_STATE, State } from './userContext';
|
||||
import { useInitialRedirect } from './useInitialRedirect';
|
||||
|
||||
// TODO: Migrate all usage of useAuthenticatedUser to using this provider.
|
||||
|
||||
@ -125,11 +124,6 @@ const UserContextProvider = ({ children }: { children: React.ReactNode }) => {
|
||||
}
|
||||
}, [state, localState.selectedViewUrn, setDefaultSelectedView]);
|
||||
|
||||
/**
|
||||
* Route to the most recently visited path once on first load of home page, if present in local storage.
|
||||
*/
|
||||
useInitialRedirect(state, localState, setState, updateLocalState);
|
||||
|
||||
return (
|
||||
<UserContext.Provider
|
||||
value={{
|
||||
|
||||
@ -1,52 +0,0 @@
|
||||
import { useEffect } from 'react';
|
||||
import { useHistory, useLocation } from 'react-router';
|
||||
import { PageRoutes } from '../../conf/Global';
|
||||
|
||||
export function useInitialRedirect(state, localState, setState, setLocalState) {
|
||||
const location = useLocation();
|
||||
const history = useHistory();
|
||||
|
||||
/**
|
||||
* Route to the most recently visited path once on first load of home page, if present in local storage.
|
||||
*/
|
||||
useEffect(() => {
|
||||
if (!state.loadedInitialPath) {
|
||||
if (location.pathname === PageRoutes.ROOT && localState.selectedPath !== location.pathname) {
|
||||
if (localState.selectedPath && !localState.selectedPath.includes(PageRoutes.EMBED)) {
|
||||
history.replace({
|
||||
pathname: localState.selectedPath,
|
||||
search: localState.selectedSearch || '',
|
||||
});
|
||||
}
|
||||
}
|
||||
setState({
|
||||
...state,
|
||||
loadedInitialPath: true,
|
||||
});
|
||||
}
|
||||
}, [
|
||||
localState.selectedPath,
|
||||
localState.selectedSearch,
|
||||
location.pathname,
|
||||
location.search,
|
||||
state,
|
||||
history,
|
||||
setState,
|
||||
]);
|
||||
|
||||
/**
|
||||
* When the location of the browse changes, save the latest to local state.
|
||||
*/
|
||||
useEffect(() => {
|
||||
if (
|
||||
(localState.selectedPath !== location.pathname || localState.selectedSearch !== location.search) &&
|
||||
!location.pathname.includes(PageRoutes.EMBED)
|
||||
) {
|
||||
setLocalState({
|
||||
...localState,
|
||||
selectedPath: location.pathname,
|
||||
selectedSearch: location.search,
|
||||
});
|
||||
}
|
||||
}, [location.pathname, location.search, localState, setLocalState]);
|
||||
}
|
||||
@ -22,10 +22,6 @@ export type State = {
|
||||
loadedPersonalDefaultViewUrn: boolean;
|
||||
hasSetDefaultView: boolean;
|
||||
};
|
||||
/**
|
||||
* Whether the initial page path has been loaded.
|
||||
*/
|
||||
loadedInitialPath: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -54,7 +50,6 @@ export const DEFAULT_STATE: State = {
|
||||
loadedPersonalDefaultViewUrn: false,
|
||||
hasSetDefaultView: false,
|
||||
},
|
||||
loadedInitialPath: false,
|
||||
};
|
||||
|
||||
export const DEFAULT_CONTEXT = {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user