284 lines
7.5 KiB
TypeScript
Raw Normal View History

/* eslint-disable jsx-a11y/no-static-element-interactions */
/* eslint-disable jsx-a11y/click-events-have-key-events */
/* eslint-disable jsx-a11y/anchor-is-valid */
import './AppLayout.styles.scss';
import { Flex } from 'antd';
import getDynamicConfigs from 'api/dynamicConfigs/getDynamicConfigs';
import getUserLatestVersion from 'api/user/getLatestVersion';
import getUserVersion from 'api/user/getVersion';
import cx from 'classnames';
Signoz cloud onboarding v1 (#3525) * Signoz Cloud - Onboarding Flow - Getting Started page * Signoz Cloud - Onboarding Flow - Java lang setup flow * Signoz Cloud - Onboarding Flow - Wireup other lang docs for APM and create empty base component for other modules * Signoz Cloud - Onboarding Flow - remove try signoz cloud button, Update code background * Signoz Cloud - Onboarding Flow - Wire up all docs and modules * Signoz Cloud - Onboarding Flow - Integrate Intercom and other minor fixes * Signoz Cloud - Onboarding Flow - Logs Management - Update Connection Status component * Signoz Cloud - Onboarding Flow - Logs Management - Update light mode styles * Signoz Cloud - Onboarding Flow - Logs Management - Update Logs * Signoz Cloud - Update yarn.lock * Signoz Cloud - Delete Progress Steps component * Signoz Cloud - Poll for connection status, created common Header component * Signoz Cloud - Add polling to check connection status, update components to use common Header component * Signoz Cloud - Render onboarding only if feature flag is enabled * Signoz Cloud - Configure Logs Management Steps * Signoz Cloud - Update intercom snippet and set max width for onboarding flow container to 1440px * Signoz Cloud - Use andD card component for displaying modules * chore: first clean up * Signoz Cloud - Use ONBOARDING and CHAT_SUPPORT FF * Signoz Cloud - Update version check logic and fix minor css issues * fix: feature flag is updated * chore: docusaurus is removed * chore: docusaurus is removed * feat: signoz cloud - fix typecheck errors * feat: signoz cloud - enable chat support based on FF * feat: signoz cloud - fix type errors * feat: signoz cloud - fix type errors * feat: signoz cloud - update webpack config rules --------- Co-authored-by: Palash Gupta <palashgdev@gmail.com>
2023-09-12 19:20:14 +05:30
import ROUTES from 'constants/routes';
Fix(FE): global time (#332) * chore: Router provider is removed * update: localstorage set get is added * update: AppLayout is updated * fix: adapter type is fixed * fix: Metric and metric application is now fixed * fix: Metrics page application is updated * fix: Tracepage is made fix * fix: app layout is updated * fix: global Time reducer is updated * refactor: getService api is added * update: metrics reducer is added * update: service list is fixed * fix: Metrics page is updated * fix: api for the metrics application are done * fix: metrics reducer is updated * fix: metrics application is updated * fix: content layout shift is removed * fix: Metric application is updated * fix: metrics application is updated * fix: Metrics application is updated * fix: Application tab is updated * chore: graph is updated * chore: Metrics application is updated * fix: chart x-axis is label is now fixed * fix: application tab is updated * fix: Top end points is added and re-redering in stopped * fix: fixed the edge case when user changes the global time then updated data is fetched * fix: Settings page is updated * chore: AppLayout is updated * chore: AppLayout is updated * chore: applayout is updated * chore: changed default loading is true in the global time reducer * chore: Global Time option is fixed * chore: Signup and Applayout is updated * chore: Button text is updated * chore: Button in the metrics application is updated * chore: dashboard menu item position in the side nav is updated * fix: Logo is now redirecting to the Application page * fix: Application page is updated * fix: AppLayout is updated * fix: starting and ending time is fixed * fix: Metrics Application is updated to the previous chart data * update: getDateArrayFromStartAndEnd function is added * update: Empty graph data is added * fix: External Call and DB Call Tabs graph are updated when there is no data a empty data is rendered * fix: onboarding modal condition is fixed and new calling api every 50000 ms to fetch the data * fix: onBoarding condition modal is updated * fix: onBoarding condition modal is updated * fix: onBoarding condition modal is updated * fix: Application chart re rendering issue is fixed * fix: Application page is changed when we change the global time * chore: step size is increased from 30 to 60 * chore: build is now fixed * chore: metrics application page is updated * fix: empty graph is now fixed * fix: application metrics graph is now fixed * fix: Time selection for custom is fixed * fix: usage graph is fixed * fix: global time selector is fixed and empty graph on click handler is added * fix: metrics application is now fixed
2021-10-20 09:24:55 +05:30
import SideNav from 'container/SideNav';
import TopNav from 'container/TopNav';
import { useIsDarkMode } from 'hooks/useDarkMode';
import useLicense from 'hooks/useLicense';
import { useNotifications } from 'hooks/useNotifications';
import history from 'lib/history';
import ErrorBoundaryFallback from 'pages/ErrorBoundaryFallback/ErrorBoundaryFallback';
import { ReactNode, useEffect, useMemo, useRef, useState } from 'react';
import { ErrorBoundary } from 'react-error-boundary';
import { Helmet } from 'react-helmet-async';
import { useTranslation } from 'react-i18next';
import { useQueries } from 'react-query';
import { useDispatch, useSelector } from 'react-redux';
import { useLocation } from 'react-router-dom';
import { Dispatch } from 'redux';
import { AppState } from 'store/reducers';
import AppActions from 'types/actions';
import {
UPDATE_CONFIGS,
UPDATE_CURRENT_ERROR,
UPDATE_CURRENT_VERSION,
UPDATE_LATEST_VERSION,
UPDATE_LATEST_VERSION_ERROR,
} from 'types/actions/app';
import AppReducer from 'types/reducer/app';
import { getFormattedDate, getRemainingDays } from 'utils/timeUtils';
import { ChildrenContainer, Layout, LayoutContent } from './styles';
import { getRouteKey } from './utils';
function AppLayout(props: AppLayoutProps): JSX.Element {
const { isLoggedIn, user, role } = useSelector<AppState, AppReducer>(
2023-05-19 19:04:41 +05:30
(state) => state.app,
);
Signoz cloud onboarding v1 (#3525) * Signoz Cloud - Onboarding Flow - Getting Started page * Signoz Cloud - Onboarding Flow - Java lang setup flow * Signoz Cloud - Onboarding Flow - Wireup other lang docs for APM and create empty base component for other modules * Signoz Cloud - Onboarding Flow - remove try signoz cloud button, Update code background * Signoz Cloud - Onboarding Flow - Wire up all docs and modules * Signoz Cloud - Onboarding Flow - Integrate Intercom and other minor fixes * Signoz Cloud - Onboarding Flow - Logs Management - Update Connection Status component * Signoz Cloud - Onboarding Flow - Logs Management - Update light mode styles * Signoz Cloud - Onboarding Flow - Logs Management - Update Logs * Signoz Cloud - Update yarn.lock * Signoz Cloud - Delete Progress Steps component * Signoz Cloud - Poll for connection status, created common Header component * Signoz Cloud - Add polling to check connection status, update components to use common Header component * Signoz Cloud - Render onboarding only if feature flag is enabled * Signoz Cloud - Configure Logs Management Steps * Signoz Cloud - Update intercom snippet and set max width for onboarding flow container to 1440px * Signoz Cloud - Use andD card component for displaying modules * chore: first clean up * Signoz Cloud - Use ONBOARDING and CHAT_SUPPORT FF * Signoz Cloud - Update version check logic and fix minor css issues * fix: feature flag is updated * chore: docusaurus is removed * chore: docusaurus is removed * feat: signoz cloud - fix typecheck errors * feat: signoz cloud - enable chat support based on FF * feat: signoz cloud - fix type errors * feat: signoz cloud - fix type errors * feat: signoz cloud - update webpack config rules --------- Co-authored-by: Palash Gupta <palashgdev@gmail.com>
2023-09-12 19:20:14 +05:30
const isDarkMode = useIsDarkMode();
const { data: licenseData, isFetching } = useLicense();
const { pathname } = useLocation();
const { t } = useTranslation(['titles']);
const [
getUserVersionResponse,
getUserLatestVersionResponse,
getDynamicConfigsResponse,
] = useQueries([
{
queryFn: getUserVersion,
2023-05-19 19:04:41 +05:30
queryKey: ['getUserVersion', user?.accessJwt],
enabled: isLoggedIn,
},
{
queryFn: getUserLatestVersion,
2023-05-19 19:04:41 +05:30
queryKey: ['getUserLatestVersion', user?.accessJwt],
enabled: isLoggedIn,
},
{
queryFn: getDynamicConfigs,
2023-05-19 19:04:41 +05:30
queryKey: ['getDynamicConfigs', user?.accessJwt],
},
]);
useEffect(() => {
if (getUserLatestVersionResponse.status === 'idle' && isLoggedIn) {
getUserLatestVersionResponse.refetch();
}
if (getUserVersionResponse.status === 'idle' && isLoggedIn) {
getUserVersionResponse.refetch();
}
if (getDynamicConfigsResponse.status === 'idle') {
getDynamicConfigsResponse.refetch();
}
}, [
getUserLatestVersionResponse,
getUserVersionResponse,
isLoggedIn,
getDynamicConfigsResponse,
]);
const { children } = props;
const dispatch = useDispatch<Dispatch<AppActions>>();
const latestCurrentCounter = useRef(0);
const latestVersionCounter = useRef(0);
const latestConfigCounter = useRef(0);
const { notifications } = useNotifications();
useEffect(() => {
if (
getUserLatestVersionResponse.isFetched &&
getUserLatestVersionResponse.isError &&
latestCurrentCounter.current === 0
) {
latestCurrentCounter.current = 1;
dispatch({
type: UPDATE_LATEST_VERSION_ERROR,
payload: {
isError: true,
},
});
notifications.error({
message: t('oops_something_went_wrong_version'),
});
}
if (
getUserVersionResponse.isFetched &&
getUserVersionResponse.isError &&
latestVersionCounter.current === 0
) {
latestVersionCounter.current = 1;
dispatch({
type: UPDATE_CURRENT_ERROR,
payload: {
isError: true,
},
});
notifications.error({
message: t('oops_something_went_wrong_version'),
});
}
if (
getUserVersionResponse.isFetched &&
getUserLatestVersionResponse.isSuccess &&
getUserVersionResponse.data &&
getUserVersionResponse.data.payload
) {
dispatch({
type: UPDATE_CURRENT_VERSION,
payload: {
currentVersion: getUserVersionResponse.data.payload.version,
2023-02-24 14:57:07 +05:30
ee: getUserVersionResponse.data.payload.ee,
setupCompleted: getUserVersionResponse.data.payload.setupCompleted,
},
});
}
if (
getUserLatestVersionResponse.isFetched &&
getUserLatestVersionResponse.isSuccess &&
getUserLatestVersionResponse.data &&
getUserLatestVersionResponse.data.payload
) {
dispatch({
type: UPDATE_LATEST_VERSION,
payload: {
latestVersion: getUserLatestVersionResponse.data.payload.tag_name,
},
});
}
if (
getDynamicConfigsResponse.isFetched &&
getDynamicConfigsResponse.isSuccess &&
getDynamicConfigsResponse.data &&
getDynamicConfigsResponse.data.payload &&
latestConfigCounter.current === 0
) {
latestConfigCounter.current = 1;
dispatch({
type: UPDATE_CONFIGS,
payload: {
configs: getDynamicConfigsResponse.data.payload,
},
});
}
}, [
dispatch,
isLoggedIn,
pathname,
t,
getUserLatestVersionResponse.isLoading,
getUserLatestVersionResponse.isError,
getUserLatestVersionResponse.data,
getUserVersionResponse.isLoading,
getUserVersionResponse.isError,
getUserVersionResponse.data,
getUserLatestVersionResponse.isFetched,
getUserVersionResponse.isFetched,
getUserLatestVersionResponse.isSuccess,
getDynamicConfigsResponse.data,
getDynamicConfigsResponse.isFetched,
getDynamicConfigsResponse.isSuccess,
notifications,
]);
const isToDisplayLayout = isLoggedIn;
const routeKey = useMemo(() => getRouteKey(pathname), [pathname]);
const pageTitle = t(routeKey);
const renderFullScreen =
pathname === ROUTES.GET_STARTED || pathname === ROUTES.WORKSPACE_LOCKED;
const [showTrialExpiryBanner, setShowTrialExpiryBanner] = useState(false);
useEffect(() => {
if (
!isFetching &&
licenseData?.payload?.onTrial &&
!licenseData?.payload?.trialConvertedToSubscription &&
!licenseData?.payload?.workSpaceBlock &&
getRemainingDays(licenseData?.payload.trialEnd) < 7
) {
setShowTrialExpiryBanner(true);
}
}, [licenseData, isFetching]);
const handleUpgrade = (): void => {
if (role === 'ADMIN') {
history.push(ROUTES.BILLING);
}
};
return (
<Layout className={isDarkMode ? 'darkMode' : 'lightMode'}>
<Helmet>
<title>{pageTitle}</title>
</Helmet>
{showTrialExpiryBanner && (
<div className="trial-expiry-banner">
You are in free trial period. Your free trial will end on{' '}
<span>
{getFormattedDate(licenseData?.payload?.trialEnd || Date.now())}.
</span>
{role === 'ADMIN' ? (
<span>
{' '}
Please{' '}
<a className="upgrade-link" onClick={handleUpgrade}>
upgrade
</a>
to continue using SigNoz features.
</span>
) : (
'Please contact your administrator for upgrading to a paid plan.'
)}
</div>
)}
<Flex className={cx('app-layout', isDarkMode ? 'darkMode' : 'lightMode')}>
{isToDisplayLayout && !renderFullScreen && (
<SideNav licenseData={licenseData} isFetching={isFetching} />
)}
<div className="app-content">
<ErrorBoundary FallbackComponent={ErrorBoundaryFallback}>
<LayoutContent>
<ChildrenContainer>
{isToDisplayLayout && !renderFullScreen && <TopNav />}
{children}
</ChildrenContainer>
</LayoutContent>
</ErrorBoundary>
</div>
</Flex>
</Layout>
);
}
2021-10-22 17:05:10 +05:30
interface AppLayoutProps {
children: ReactNode;
}
export default AppLayout;