Skip to content

Commit 9741a69

Browse files
committed
Add LoadingDiv
1 parent 1f56612 commit 9741a69

File tree

3 files changed

+24
-12
lines changed

3 files changed

+24
-12
lines changed

components/dash-core-components/src/fragments/Graph.react.js

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
} from 'ramda';
1515
import PropTypes from 'prop-types';
1616
import {graphPropTypes, graphDefaultProps} from '../components/Graph.react';
17+
import LoadingDiv from '../utils/LoadingDiv';
1718
/* global Plotly:true */
1819

1920
/**
@@ -514,18 +515,10 @@ class PlotlyGraph extends Component {
514515
}
515516

516517
render() {
517-
const {className, id, style, loading_state} = this.props;
518+
const {className, id, style} = this.props;
518519

519520
return (
520-
<div
521-
id={id}
522-
key={id}
523-
data-dash-is-loading={
524-
(loading_state && loading_state.is_loading) || undefined
525-
}
526-
className={className}
527-
style={style}
528-
>
521+
<LoadingDiv id={id} key={id} className={className} style={style}>
529522
<ResizeDetector
530523
handleHeight={true}
531524
handleWidth={true}
@@ -535,7 +528,7 @@ class PlotlyGraph extends Component {
535528
onResize={this.graphResize}
536529
/>
537530
<div ref={this.gd} style={{height: '100%', width: '100%'}} />
538-
</div>
531+
</LoadingDiv>
539532
);
540533
}
541534
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
4+
export default function LoadingDiv({children, ...props}) {
5+
const ctx = window.dash_component_api.useDashContext();
6+
const loading = ctx.useLoading();
7+
return (
8+
<div {...props} data-dash-is-loading={loading || undefined}>
9+
{children}
10+
</div>
11+
);
12+
}
13+
14+
LoadingDiv.propTypes = {
15+
children: PropTypes.node,
16+
};

dash/dash-renderer/src/wrapper/DashContext.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ export function DashContextProvider(props: DashContextProviderProps) {
4242
}, [stringPath]);
4343

4444
const useLoading = useCallback(() => {
45-
return useSelector(state => !!pathOr(false, [stringPath], state));
45+
return useSelector((state: any) => {
46+
const load = pathOr([], [stringPath], state.loading);
47+
return load.length > 0;
48+
});
4649
}, [stringPath]);
4750

4851
const ctxValue = useMemo(() => {

0 commit comments

Comments
 (0)