Skip to content
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

fix: add loader for healthcheck #563

Merged
merged 2 commits into from
Oct 19, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import cn from 'bem-cn-lite';
import type {IResponseError} from '../../../../../types/api/error';
import type {IIssuesTree} from '../../../../../types/store/healthcheck';
import {ResponseError} from '../../../../../components/Errors/ResponseError';
import {Loader} from '../../../../../components/Loader';

import IssueTree from './IssuesViewer/IssueTree';

Expand All @@ -13,17 +14,23 @@ const b = cn('healthcheck');

interface HealthcheckDetailsProps {
issueTrees?: IIssuesTree[];
loading?: boolean;
wasLoaded?: boolean;
error?: IResponseError;
}

export function HealthcheckDetails(props: HealthcheckDetailsProps) {
const {issueTrees, error} = props;
const {issueTrees, loading, wasLoaded, error} = props;

const renderContent = () => {
if (error) {
return <ResponseError error={error} defaultMessage={i18n('no-data')} />;
}

if (loading && !wasLoaded) {
return <Loader size="m" />;
}

if (!issueTrees || !issueTrees.length) {
return i18n('status_message.ok');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {IResponseError} from '../../../../../types/api/error';
import {DiagnosticCard} from '../../../../../components/DiagnosticCard/DiagnosticCard';
import EntityStatus from '../../../../../components/EntityStatus/EntityStatus';
import {ResponseError} from '../../../../../components/Errors/ResponseError';
import {Loader} from '../../../../../components/Loader';

import i18n from './i18n';
import './Healthcheck.scss';
Expand All @@ -19,17 +20,22 @@ interface HealthcheckPreviewProps {
selfCheckResult: SelfCheckResult;
issuesStatistics?: [StatusFlag, number][];
loading?: boolean;
wasLoaded?: boolean;
onUpdate: VoidFunction;
error?: IResponseError;
active?: boolean;
}

export function HealthcheckPreview(props: HealthcheckPreviewProps) {
const {selfCheckResult, issuesStatistics, loading, onUpdate, error, active} = props;
const {selfCheckResult, issuesStatistics, loading, wasLoaded, onUpdate, error, active} = props;

const renderHeader = () => {
const modifier = selfCheckResult.toLowerCase();

if (loading && !wasLoaded) {
return null;
}

return (
<div className={b('preview-header')}>
<div className={b('preview-title-wrapper')}>
Expand All @@ -50,6 +56,10 @@ export function HealthcheckPreview(props: HealthcheckPreviewProps) {
return <ResponseError error={error} defaultMessage={i18n('no-data')} />;
}

if (loading && !wasLoaded) {
return <Loader size="m" />;
}

return (
<div className={b('preview-content')}>
{!issuesStatistics || !issuesStatistics.length ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ interface MetricsCardsProps {
selfCheckResult: SelfCheckResult;
fetchHealthcheck: VoidFunction;
healthcheckLoading?: boolean;
healthCheckWasLoaded?: boolean;
healthcheckError?: IResponseError;
}

Expand All @@ -47,6 +48,7 @@ export function MetricsCards({
selfCheckResult,
fetchHealthcheck,
healthcheckLoading,
healthCheckWasLoaded,
healthcheckError,
}: MetricsCardsProps) {
const location = useLocation();
Expand Down Expand Up @@ -124,6 +126,7 @@ export function MetricsCards({
issuesStatistics={issuesStatistics}
onUpdate={fetchHealthcheck}
loading={healthcheckLoading}
wasLoaded={healthCheckWasLoaded}
error={healthcheckError}
active={metricsTab === TENANT_METRICS_TABS_IDS.healthcheck}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,22 @@ export function TenantOverview({
return <TenantMemory path={tenantName} />;
}
case TENANT_METRICS_TABS_IDS.healthcheck: {
return <HealthcheckDetails issueTrees={issueTrees} error={healthcheckError} />;
return (
<HealthcheckDetails
issueTrees={issueTrees}
loading={healthcheckLoading}
wasLoaded={healthCheckWasLoaded}
error={healthcheckError}
/>
);
}
default: {
return undefined;
}
}
};

if ((tenantLoading && !tenantWasLoaded) || (healthcheckLoading && !healthCheckWasLoaded)) {
if (tenantLoading && !tenantWasLoaded) {
return (
<div className={b('loader')}>
<Loader size="m" />
Expand All @@ -160,6 +167,7 @@ export function TenantOverview({
selfCheckResult={selfCheckResult}
fetchHealthcheck={fetchHealthcheck}
healthcheckLoading={healthcheckLoading}
healthCheckWasLoaded={healthCheckWasLoaded}
healthcheckError={healthcheckError}
/>
</div>
Expand Down