Skip to content

Commit 5f945b4

Browse files
committed
merge: merge branch 'THU/embedded_dashboards_refactoring'
2 parents 779db29 + a886f72 commit 5f945b4

File tree

16 files changed

+265
-352
lines changed

16 files changed

+265
-352
lines changed

src/charts/Dashboard/Dashboard.js

Lines changed: 0 additions & 174 deletions
This file was deleted.

src/charts/Dashboard/components/DashboardPlaceholder/index.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/charts/Dashboard/components/index.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/charts/Dashboard/components/DashboardPlaceholder/DashboardPlaceholder.js renamed to src/charts/DashboardPlaceholder/DashboardPlaceholderLayout.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import React from 'react';
44
import PropTypes from 'prop-types';
55
import { Typography, Grid, Button, LinearProgress } from '@mui/material';
66

7-
const DashboardPlaceholder = (props) => {
7+
const DashboardPlaceholderLayout = (props) => {
88
const { title = null, label, icon, downloadLogsFile, downloadLabel, inProgress = false } = props;
99

1010
return (
@@ -40,7 +40,7 @@ const DashboardPlaceholder = (props) => {
4040
);
4141
};
4242

43-
DashboardPlaceholder.propTypes = {
43+
DashboardPlaceholderLayout.propTypes = {
4444
label: PropTypes.string.isRequired,
4545
title: PropTypes.string,
4646
icon: PropTypes.object,
@@ -49,4 +49,4 @@ DashboardPlaceholder.propTypes = {
4949
inProgress: PropTypes.bool,
5050
};
5151

52-
export default DashboardPlaceholder;
52+
export default DashboardPlaceholderLayout;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from './DashboardPlaceholderLayout';
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Copyright (c) Cosmo Tech.
2+
// Licensed under the MIT license.
3+
import React, { useCallback } from 'react';
4+
import { RUNNER_RUN_STATE } from '../../common/apiConstants';
5+
import DashboardPlaceholderLayout from './DashboardPlaceholderLayout';
6+
7+
const DEFAULT_LABELS = {
8+
noScenario: {
9+
title: 'No scenario yet',
10+
label: 'You can create a scenario by clicking on the CREATE button',
11+
},
12+
noDashboard: { label: "There isn't any dashboard configured for this run type" },
13+
noRun: { label: 'The scenario has not been run yet' },
14+
inProgress: { label: 'Scenario run in progress...' },
15+
hasErrors: { label: 'An error occured during the scenario run' },
16+
hasUnknownStatus: {
17+
label: 'This scenario has an unknown state, if the problem persists, please, contact your administrator',
18+
},
19+
resultsDisplayDisabled: 'Display of results is disabled',
20+
downloadButton: 'Download logs',
21+
errors: {
22+
unknown: 'Unknown error',
23+
details: 'Something went wrong when fetching PowerBI reports info',
24+
},
25+
};
26+
27+
const forgeDashboardPlaceholder = ({
28+
alwaysShowReports,
29+
disabled,
30+
downloadLogsFile,
31+
noDashboardConfigured,
32+
labels: tmpLabels,
33+
scenario,
34+
scenarioDTO,
35+
}) => {
36+
const labels = { ...DEFAULT_LABELS, ...tmpLabels };
37+
38+
const noScenario = scenario === null;
39+
const scenarioLastRunStatus = noScenario ? RUNNER_RUN_STATE.CREATED : scenarioDTO.lastRunStatus;
40+
const noRun = scenarioLastRunStatus === RUNNER_RUN_STATE.CREATED || scenarioLastRunStatus === null;
41+
const runInProgress = scenarioLastRunStatus === RUNNER_RUN_STATE.RUNNING;
42+
const hasError = scenarioLastRunStatus === RUNNER_RUN_STATE.FAILED;
43+
const hasUnknownStatus = scenarioLastRunStatus === RUNNER_RUN_STATE.UNKNOWN;
44+
45+
if (alwaysShowReports) return null;
46+
if (noScenario) return <DashboardPlaceholderLayout label={labels.noScenario.label} title={labels.noScenario.title} />;
47+
if (noRun) return <DashboardPlaceholderLayout label={labels.noRun.label} title={labels.noRun.title} />;
48+
if (runInProgress)
49+
return <DashboardPlaceholderLayout label={labels.inProgress.label} title={labels.inProgress.title} inProgress />;
50+
if (hasError)
51+
return (
52+
<DashboardPlaceholderLayout
53+
label={labels.hasErrors.label}
54+
title={labels.hasErrors.title}
55+
downloadLogsFile={downloadLogsFile}
56+
downloadLabel={labels.downloadButton}
57+
/>
58+
);
59+
if (hasUnknownStatus) return <DashboardPlaceholderLayout label={labels.hasUnknownStatus.label} />;
60+
if (disabled) return <DashboardPlaceholderLayout label={labels.resultsDisplayDisabled} />;
61+
if (noDashboardConfigured) return <DashboardPlaceholderLayout label={labels.noDashboard.label} />;
62+
return null;
63+
};
64+
65+
export const useDashboardPlaceholder = () => {
66+
const getDashboardPlaceholder = useCallback((params) => {
67+
const placeholder = forgeDashboardPlaceholder(params);
68+
return { placeholder, showPlaceholder: placeholder != null };
69+
}, []);
70+
71+
return { getDashboardPlaceholder };
72+
};

0 commit comments

Comments
 (0)