Skip to content

Commit 947c936

Browse files
author
Edon Zeqiraj
committed
feature: [PROD-14860] add StyledErrorContainer component
1 parent 9676e10 commit 947c936

File tree

5 files changed

+44
-28
lines changed

5 files changed

+44
-28
lines changed

src/charts/SimplePowerBIReportEmbed/SimplePowerBIReportEmbed.js

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,6 @@ import { PowerBIUtils } from '@cosmotech/azure';
1010
import { FadingTooltip } from '../../misc';
1111
import DashboardPlaceholder from '../Dashboard/components';
1212

13-
const StyledErrorContainerDiv = styled('div')(({ theme }) => ({
14-
'z-index': '1', // Need z-index > 0, otherwise the error banner is hidden behind the powerbi loading screen
15-
height: '50px',
16-
width: '100%',
17-
position: 'absolute',
18-
textAlign: 'center',
19-
padding: '5px 0',
20-
backgroundColor: theme.palette.error.main,
21-
color: theme.palette.error.contrastText,
22-
}));
23-
2413
const PREFIX = 'SimplePowerBIReportEmbed';
2514
const classes = { report: `${PREFIX}-report` };
2615

@@ -31,15 +20,6 @@ const Root = styled('div')(({ theme }) => ({
3120
},
3221
}));
3322

34-
function getErrorCode(labels, reports) {
35-
if (!reports?.error?.status && !reports?.error?.statusText) return labels.errors.unknown;
36-
return `${reports?.error?.status ?? ''} ${reports?.error?.statusText ?? ''}`;
37-
}
38-
39-
function getErrorDescription(labels, reports) {
40-
return reports?.error?.powerBIErrorInfo ?? labels.errors.details;
41-
}
42-
4323
function addDynamicParameters(pageName, lang, newConfig, settings, staticFilters, additionalFilters) {
4424
if (pageName !== undefined && pageName[lang] !== undefined) {
4525
newConfig.pageName = pageName[lang];
@@ -189,9 +169,6 @@ export const SimplePowerBIReportEmbed = ({
189169
}
190170
}, [theme, report]);
191171

192-
const errorCode = getErrorCode(labels, reports);
193-
const errorDescription = getErrorDescription(labels, reports);
194-
195172
const refreshReport = useCallback(
196173
(triggerTimeout = true) => {
197174
if (!report) return;
@@ -246,10 +223,6 @@ export const SimplePowerBIReportEmbed = ({
246223

247224
return (
248225
<Root style={{ height: '100%', width: '100%', position: 'relative' }}>
249-
<StyledErrorContainerDiv hidden={reports.status !== 'ERROR'}>
250-
<div style={{ fontWeight: 'bold', fontSize: 'large' }}>{errorCode}</div>
251-
<div style={{ fontWeight: 'bold', fontSize: 'small' }}>{errorDescription}</div>
252-
</StyledErrorContainerDiv>
253226
{placeholder}
254227
<div style={{ width: '100%', display: 'flex', flexDirection: 'row', ...divContainerStyle }}>
255228
{refreshable && (

src/index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@
33

44
export { CreateScenarioButton, SelfDestructLinkButton, SignInButton, RolesEditionButton } from './buttons';
55
export { ScenarioNode, ResourceCard } from './cards';
6-
export { CytoViz, Dashboard, ScenarioManagerTreeList, SimplePowerBIReportEmbed, SupersetEmbed } from './charts';
6+
export {
7+
CytoViz,
8+
Dashboard,
9+
ScenarioManagerTreeList,
10+
SimplePowerBIReportEmbed,
11+
SupersetEmbed,
12+
DashboardPlaceholder,
13+
} from './charts';
714
export { SimpleTwoActionsDialog, DontAskAgainDialog } from './dialogs';
815
export {
916
HierarchicalComboBox,
@@ -30,6 +37,7 @@ export {
3037
export { UserInfo, HelpMenu } from './menus';
3138
export {
3239
ErrorBanner,
40+
StyledErrorContainer,
3341
ErrorBoundary,
3442
ErrorsPanel,
3543
FadingTooltip,
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import { styled } from '@mui/material/styles';
4+
5+
const Container = styled('div')(({ theme }) => ({
6+
zIndex: 1,
7+
height: '50px',
8+
width: '100%',
9+
position: 'absolute',
10+
textAlign: 'center',
11+
padding: '5px 0',
12+
backgroundColor: theme.palette.error.main,
13+
color: theme.palette.error.contrastText,
14+
display: 'flex',
15+
flexDirection: 'column',
16+
justifyContent: 'center',
17+
alignItems: 'center',
18+
}));
19+
20+
const StyledErrorContainer = ({ errorCode, errorDescription, ...rest }) => (
21+
<Container {...rest}>
22+
{errorCode && <div style={{ fontWeight: 'bold', fontSize: 'large' }}>{errorCode}</div>}
23+
{errorDescription && <div style={{ fontWeight: 'bold', fontSize: 'small' }}>{errorDescription}</div>}
24+
</Container>
25+
);
26+
27+
StyledErrorContainer.propTypes = {
28+
errorCode: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
29+
errorDescription: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
30+
children: PropTypes.node,
31+
};
32+
33+
export default StyledErrorContainer;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as StyledErrorContainer } from './StyledErrorContainer';

src/misc/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export { ErrorsPanel } from './ErrorsPanel';
66
export { ScenarioValidationStatusChip } from './ScenarioValidationStatusChip';
77
export { LoadingLine } from './LoadingLine';
88
export { ErrorBanner } from './ErrorBanner';
9+
export { StyledErrorContainer } from './StyledErrorContainer';
910
export { DefaultAvatar } from './DefaultAvatar';
1011
export { FadingTooltip } from './FadingTooltip';
1112
export { TooltipInfo } from './TooltipInfo';

0 commit comments

Comments
 (0)