From 0057553404ee72f32456c904f187b63f8514e3ac Mon Sep 17 00:00:00 2001 From: Shekar Siri Date: Tue, 31 Oct 2023 10:51:06 +0100 Subject: [PATCH] fix(ui): initial data load --- frontend/app/Router.tsx | 19 +++++++++++-------- .../ProjectDropdown/ProjectDropdown.tsx | 8 ++++---- frontend/app/layout/TopHeader.tsx | 15 ++++++--------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/frontend/app/Router.tsx b/frontend/app/Router.tsx index 3d06b3cde..10403a21f 100644 --- a/frontend/app/Router.tsx +++ b/frontend/app/Router.tsx @@ -75,6 +75,11 @@ const Router: React.FC = (props) => { const handleUserLogin = async () => { props.mstore.initClient(); + await fetchUserInfo(); + + const siteIdFromPath = parseInt(location.pathname.split('/')[1]); + await fetchSiteList(siteIdFromPath); + const destinationPath = localStorage.getItem(GLOBAL_DESTINATION_PATH); if ( destinationPath && @@ -84,9 +89,6 @@ const Router: React.FC = (props) => { history.push(destinationPath + location.search); localStorage.removeItem(GLOBAL_DESTINATION_PATH); } - await fetchUserInfo(); - const siteIdFromPath = parseInt(location.pathname.split('/')[1]); - await fetchSiteList(siteIdFromPath); }; useEffect(() => { @@ -135,12 +137,12 @@ const Router: React.FC = (props) => { return isLoggedIn ? ( - - + + - - + + ) : ; }; @@ -150,13 +152,14 @@ const mapStateToProps = (state: Map) => { const jwt = state.getIn(['user', 'jwt']); const changePassword = state.getIn(['user', 'account', 'changePassword']); const userInfoLoading = state.getIn(['user', 'fetchUserInfoRequest', 'loading']); + const sitesLoading = state.getIn(['site', 'fetchListRequest', 'loading']); return { siteId, changePassword, sites: state.getIn(['site', 'list']), isLoggedIn: jwt !== null && !changePassword, - loading: siteId === null || userInfoLoading, + loading: siteId === null || userInfoLoading || sitesLoading, email: state.getIn(['user', 'account', 'email']), account: state.getIn(['user', 'account']), organisation: state.getIn(['user', 'account', 'name']), diff --git a/frontend/app/components/shared/ProjectDropdown/ProjectDropdown.tsx b/frontend/app/components/shared/ProjectDropdown/ProjectDropdown.tsx index 55b98549e..45e502bf5 100644 --- a/frontend/app/components/shared/ProjectDropdown/ProjectDropdown.tsx +++ b/frontend/app/components/shared/ProjectDropdown/ProjectDropdown.tsx @@ -5,7 +5,7 @@ import { CaretDownOutlined, FolderAddOutlined, FolderOutlined } from '@ant-desig import { withRouter, RouteComponentProps } from 'react-router-dom'; import { hasSiteId, siteChangeAvailable } from 'App/routes'; import { setSiteId } from 'Duck/site'; -import { fetchListActive as fetchIntegrationVariables } from 'Duck/customField'; +import { fetchListActive as fetchMetadata } from 'Duck/customField'; import { clearSearch } from 'Duck/search'; import { clearSearch as clearSearchLive } from 'Duck/liveSearch'; import { useModal } from 'Components/Modal'; @@ -27,7 +27,7 @@ interface Props extends RouteComponentProps { sites: Site[]; siteId: string; setSiteId: (siteId: string) => void; - fetchIntegrationVariables: () => void; + fetchMetadata: () => void; clearSearch: (isSession: boolean) => void; clearSearchLive: () => void; initProject: (data: any) => void; @@ -44,7 +44,7 @@ function ProjectDropdown(props: Props) { const handleSiteChange = (newSiteId: string) => { props.setSiteId(newSiteId); // Fixed: should set the new siteId, not the existing one - props.fetchIntegrationVariables(); + props.fetchMetadata(); props.clearSearch(location.pathname.includes('/sessions')); props.clearSearchLive(); @@ -106,7 +106,7 @@ const mapStateToProps = (state: any) => ({ export default withRouter( connect(mapStateToProps, { setSiteId, - fetchIntegrationVariables, + fetchMetadata, clearSearch, clearSearchLive, initProject diff --git a/frontend/app/layout/TopHeader.tsx b/frontend/app/layout/TopHeader.tsx index acd8b0ebc..435b7eabf 100644 --- a/frontend/app/layout/TopHeader.tsx +++ b/frontend/app/layout/TopHeader.tsx @@ -29,16 +29,13 @@ function TopHeader(props: Props) { useEffect(() => { if (!account.id || initialDataFetched) return; + Promise.all([ + userStore.fetchLimits(), + notificationStore.fetchNotificationsCount() - setTimeout(() => { - Promise.all([ - userStore.fetchLimits(), - notificationStore.fetchNotificationsCount() - - ]).then(() => { - userStore.updateKey('initialDataFetched', true); - }); - }, 0); + ]).then(() => { + userStore.updateKey('initialDataFetched', true); + }); }, [account]); return (