Skip to content

chore: dashboard lazy load tabs #1794

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ui/src/pages/Dashboard/Custom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ export const CustomDashboard = ({
<DashboardCore width="100%" height="auto" />
</DashboardContextProvider>
) : null;

export default CustomDashboard;
55 changes: 36 additions & 19 deletions ui/src/pages/Dashboard/DashboardPage.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import React, { useEffect, useRef, useState } from 'react';
import React, { ReactChild, Suspense, useEffect, useRef, useState } from 'react';
import WaitSpinner from '@splunk/react-ui/WaitSpinner';
import TabLayout from '@splunk/react-ui/TabLayout';
import styled from 'styled-components';
import variables from '@splunk/themes/variables';
import pick from '@splunk/themes/pick';
import ErrorBoundary from '../../components/ErrorBoundary/ErrorBoundary';
import { OverviewDashboard } from './Overview';
import { DataIngestionDashboard } from './DataIngestion';
import { ErrorDashboard } from './Error';
import { ResourceDashboard } from './Resource';
import { CustomDashboard } from './Custom';

import { getBuildDirPath } from '../../util/script';
import { getUnifiedConfigs } from '../../util/util';
import { GlobalDashboardStyle } from './dashboardStyle';
import { WaitSpinnerWrapper } from '../../components/table/CustomTableStyle';

const CustomDashboard = React.lazy(() => import('./Custom'));
const DataIngestionDashboard = React.lazy(() => import('./DataIngestion'));
const OverviewDashboard = React.lazy(() => import('./Overview'));
const ErrorDashboard = React.lazy(() => import('./Error'));
const ResourceDashboard = React.lazy(() => import('./Resource'));

/**
*
Expand Down Expand Up @@ -48,6 +50,20 @@ const DashboardStyles = styled.div`
})};
`;

const LazyPanel = ({
label,
panelId,
children,
}: {
label: string;
panelId: string;
children: ReactChild;
}) => (
<TabLayout.Panel label={label} panelId={panelId}>
<Suspense fallback={<WaitSpinnerWrapper size="medium" />}>{children}</Suspense>
</TabLayout.Panel>
);

function DashboardPage() {
const [overviewDef, setOverviewDef] = useState<Record<string, unknown> | null>(null);
const [dataIngestionDef, setDataIngestionDef] = useState<Record<string, unknown> | null>(null);
Expand Down Expand Up @@ -106,39 +122,40 @@ function DashboardPage() {
style={{ minHeight: '98vh' }}
>
{dataIngestionDef && (
<TabLayout.Panel label="Data ingestion" panelId="dataIngestionTabPanel">
<LazyPanel label="Data ingestion" panelId="dataIngestionTabPanel">
<DataIngestionDashboard dashboardDefinition={dataIngestionDef} />
</TabLayout.Panel>
</LazyPanel>
)}
{errorDef && (
<TabLayout.Panel label="Errors" panelId="errorsTabPanel">
<ErrorDashboard dashboardDefinition={errorDef} />
</TabLayout.Panel>
<LazyPanel label="Errors" panelId="errorsTabPanel">
<Suspense fallback={<WaitSpinnerWrapper size="medium" />}>
<ErrorDashboard dashboardDefinition={errorDef} />
</Suspense>
</LazyPanel>
)}
{resourceDef && (
<TabLayout.Panel
label="Resource consumption"
panelId="resourceTabPanel"
>
<LazyPanel label="Resource consumption" panelId="resourceTabPanel">
<ResourceDashboard dashboardDefinition={resourceDef} />
</TabLayout.Panel>
</LazyPanel>
)}
{customDef && (
<TabLayout.Panel
<LazyPanel
label={
globalConfig.pages.dashboard?.settings?.custom_tab_name ||
'Custom'
}
panelId="customTabPanel"
>
<CustomDashboard dashboardDefinition={customDef} />
</TabLayout.Panel>
</LazyPanel>
)}
</TabLayout>
) : (
// if overview is null then custom tab is the only displayed component
// so no need to show table
<CustomDashboard dashboardDefinition={customDef} />
<Suspense fallback={<WaitSpinnerWrapper size="medium" />}>
<CustomDashboard dashboardDefinition={customDef} />
</Suspense>
)}
{!overviewDef && !customDef ? (
<WaitSpinner size="medium" data-testid="wait-spinner" />
Expand Down
2 changes: 2 additions & 0 deletions ui/src/pages/Dashboard/DataIngestion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,5 @@ export const DataIngestionDashboard = ({
</DashboardContextProvider>
);
};

export default DataIngestionDashboard;
2 changes: 2 additions & 0 deletions ui/src/pages/Dashboard/Error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,5 @@ export const ErrorDashboard = ({
</DashboardContextProvider>
) : null;
};

export default ErrorDashboard;
2 changes: 2 additions & 0 deletions ui/src/pages/Dashboard/Overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ export const OverviewDashboard = ({
</DashboardContextProvider>
) : null;
};

export default OverviewDashboard;
2 changes: 2 additions & 0 deletions ui/src/pages/Dashboard/Resource.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,5 @@ export const ResourceDashboard = ({
</DashboardContextProvider>
) : null;
};

export default ResourceDashboard;
Loading