Skip to content

Commit

Permalink
fix(dashboardeditor): add loading state
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephen Stone committed Nov 10, 2020
1 parent e64a314 commit 0f34ba3
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 3 deletions.
16 changes: 14 additions & 2 deletions src/components/DashboardEditor/DashboardEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import {
DASHBOARD_EDITOR_CARD_TYPES,
CARD_ACTIONS,
} from '../../constants/LayoutConstants';
import { DashboardGrid, CardEditor, ErrorBoundary } from '../../index';
import {
DashboardGrid,
CardEditor,
ErrorBoundary,
SkeletonText,
} from '../../index';

import DashboardEditorHeader from './DashboardEditorHeader/DashboardEditorHeader';
import {
Expand Down Expand Up @@ -108,6 +113,8 @@ const propTypes = {
* @returns Array<string> error strings. return empty array if there is no errors
*/
onValidateCardJson: PropTypes.func,
/** optional loading prop to render the PageTitleBar loading state */
isLoading: PropTypes.bool,
/** internationalization strings */
i18n: PropTypes.shape({
headerImportButton: PropTypes.string,
Expand Down Expand Up @@ -158,6 +165,7 @@ const defaultProps = {
onSubmit: null,
submitDisabled: false,
onValidateCardJson: null,
isLoading: false,
i18n: {
headerEditTitleButton: 'Edit title',
headerImportButton: 'Import',
Expand Down Expand Up @@ -212,6 +220,7 @@ const DashboardEditor = ({
onSubmit,
submitDisabled,
onValidateCardJson,
isLoading,
i18n,
}) => {
const mergedI18n = { ...defaultProps.i18n, ...i18n };
Expand Down Expand Up @@ -308,7 +317,9 @@ const DashboardEditor = ({
isSelected,
});

return (
return isLoading ? (
<SkeletonText />
) : (
<div className={baseClassName}>
<div
className={classnames(`${baseClassName}--content`, {
Expand All @@ -334,6 +345,7 @@ const DashboardEditor = ({
selectedBreakpointIndex={selectedBreakpointIndex}
setSelectedBreakpointIndex={setSelectedBreakpointIndex}
breakpointSwitcher={breakpointSwitcher}
isLoading={isLoading}
/>
)}
{notification}
Expand Down
21 changes: 20 additions & 1 deletion src/components/DashboardEditor/DashboardEditor.story.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export const Default = () => (
<Link href="www.ibm.com">Dashboard library</Link>,
<Link href="www.ibm.com">Favorites</Link>,
]}
isLoading={boolean('isLoading', false)}
/>
</div>
);
Expand Down Expand Up @@ -223,6 +224,7 @@ export const WithInitialValue = () => (
<Link href="www.ibm.com">Dashboard library</Link>,
<Link href="www.ibm.com">Favorites</Link>,
]}
isLoading={boolean('isLoading', false)}
/>
</div>
);
Expand Down Expand Up @@ -293,6 +295,7 @@ export const WithCustomOnCardChange = () => (
<Link href="www.ibm.com">Dashboard library</Link>,
<Link href="www.ibm.com">Favorites</Link>,
]}
isLoading={boolean('isLoading', false)}
/>
</div>
);
Expand Down Expand Up @@ -347,6 +350,7 @@ export const WithNotifications = () => (
/>
</>
}
isLoading={boolean('isLoading', false)}
/>
</div>
);
Expand Down Expand Up @@ -381,6 +385,7 @@ export const WithBreakpointSwitcher = () => (
<Link href="www.ibm.com">Favorites</Link>,
]}
breakpointSwitcher={{ enabled: true }}
isLoading={boolean('isLoading', false)}
/>
</div>
);
Expand Down Expand Up @@ -474,6 +479,7 @@ export const CustomCardPreviewRenderer = () => (
</Card>
) : undefined;
}}
isLoading={boolean('isLoading', false)}
/>
</div>
);
Expand All @@ -484,10 +490,23 @@ CustomCardPreviewRenderer.story = {

export const CustomHeaderRenderer = () => (
<div style={{ height: 'calc(100vh - 3rem)', marginRight: '-3rem' }}>
<DashboardEditor renderHeader={() => <h1>Custom Header</h1>} />
<DashboardEditor
renderHeader={() => <h1>Custom Header</h1>}
isLoading={boolean('isLoading', false)}
/>
</div>
);

CustomHeaderRenderer.story = {
name: 'custom header renderer',
};

export const isLoading = () => (
<div style={{ height: 'calc(100vh - 3rem)', marginRight: '-3rem' }}>
<DashboardEditor isLoading={boolean('isLoading', true)} />
</div>
);

isLoading.story = {
name: 'isLoading',
};
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ const propTypes = {
enabled: PropTypes.bool,
allowedBreakpoints: PropTypes.arrayOf(PropTypes.string),
}),
/** optional loading prop to render the PageTitleBar loading state */
isLoading: PropTypes.bool,
};

const defaultProps = {
Expand Down Expand Up @@ -99,6 +101,7 @@ const defaultProps = {
selectedBreakpointIndex: null,
setSelectedBreakpointIndex: null,
breakpointSwitcher: null,
isLoading: false,
};

const DashboardEditorHeader = ({
Expand All @@ -116,6 +119,7 @@ const DashboardEditorHeader = ({
selectedBreakpointIndex,
setSelectedBreakpointIndex,
breakpointSwitcher,
isLoading,
}) => {
const mergedI18n = { ...defaultProps.i18n, i18n };
const baseClassName = `${iotPrefix}--dashboard-editor-header`;
Expand Down Expand Up @@ -223,6 +227,7 @@ const DashboardEditorHeader = ({
title={title}
editable={!!onEditTitle}
onEdit={onEditTitle}
isLoading={isLoading}
i18n={{ editIconDescription: mergedI18n.headerEditTitleButton }}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3033,6 +3033,62 @@ exports[`Storybook Snapshot tests and console checks Storyshots Watson IoT Exper
</div>
`;

exports[`Storybook Snapshot tests and console checks Storyshots Watson IoT Experimental/DashboardEditor isLoading 1`] = `
<div
className="storybook-container"
>
<div
style={
Object {
"position": "relative",
"zIndex": 0,
}
}
>
<div
style={
Object {
"height": "calc(100vh - 3rem)",
"marginRight": "-3rem",
}
}
>
<p
className="bx--skeleton__text"
style={
Object {
"width": "100%",
}
}
/>
</div>
</div>
<button
className="info__show-button"
onClick={[Function]}
style={
Object {
"background": "#027ac5",
"border": "none",
"borderRadius": "0 0 0 5px",
"color": "#fff",
"cursor": "pointer",
"display": "block",
"fontFamily": "sans-serif",
"fontSize": 12,
"padding": "5px 15px",
"position": "fixed",
"right": 0,
"top": 0,
}
}
type="button"
>
Show Info
</button>
</div>
`;

exports[`Storybook Snapshot tests and console checks Storyshots Watson IoT Experimental/DashboardEditor with breakpoint switcher 1`] = `
<div
className="storybook-container"
Expand Down
4 changes: 4 additions & 0 deletions src/utils/__tests__/__snapshots__/publicAPI.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8139,6 +8139,7 @@ Map {
"cards": Array [],
"layouts": Object {},
},
"isLoading": false,
"notification": null,
"onCancel": null,
"onCardChange": null,
Expand Down Expand Up @@ -8289,6 +8290,9 @@ Map {
],
"type": "shape",
},
"isLoading": Object {
"type": "bool",
},
"notification": Object {
"type": "node",
},
Expand Down

0 comments on commit 0f34ba3

Please sign in to comment.