Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

Commit f1a0bb6

Browse files
Use new loading API and show propsName and componentName for now
1 parent ecb35a5 commit f1a0bb6

File tree

10 files changed

+142
-33
lines changed

10 files changed

+142
-33
lines changed

dash_core_components/Loading.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@ class Loading(Component):
1212
- id (string; optional)
1313
- loadingProp (string; optional): String that determines which prop to listen to when loading
1414
- className (string; optional): Additional CSS class for the root DOM node
15-
- loading (optional): Object that holds the loading prop, a bool that determines if the component is loading, and the actual
16-
prop that's causing the load as a String.. loading has the following type: dict containing keys 'loading', 'prop'.
15+
- status (optional): Object that holds the status object coming from dash-renderer. status has the following type: dict containing keys 'isLoading', 'propName', 'componentName'.
1716
Those keys have the following types:
18-
- loading (boolean; optional)
19-
- prop (string; optional)
17+
- isLoading (boolean; optional): Determines if the component is loading or not
18+
- propName (string; optional): Holds which property is loading
19+
- componentName (string; optional): Holds the name of the component that is loading
2020
2121
Available events: """
2222
@_explicitize_args
23-
def __init__(self, children=None, id=Component.UNDEFINED, loadingProp=Component.UNDEFINED, className=Component.UNDEFINED, loading=Component.UNDEFINED, **kwargs):
24-
self._prop_names = ['children', 'id', 'loadingProp', 'className', 'loading']
23+
def __init__(self, children=None, id=Component.UNDEFINED, loadingProp=Component.UNDEFINED, className=Component.UNDEFINED, status=Component.UNDEFINED, **kwargs):
24+
self._prop_names = ['children', 'id', 'loadingProp', 'className', 'status']
2525
self._type = 'Loading'
2626
self._namespace = 'dash_core_components'
2727
self._valid_wildcard_attributes = []
2828
self.available_events = []
29-
self.available_properties = ['children', 'id', 'loadingProp', 'className', 'loading']
29+
self.available_properties = ['children', 'id', 'loadingProp', 'className', 'status']
3030
self.available_wildcard_properties = []
3131

3232
_explicit_args = kwargs.pop('_explicit_args')

dash_core_components/dash_core_components.dev.js

Lines changed: 13 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dash_core_components/dash_core_components.min.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dash_core_components/metadata.json

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2059,22 +2059,29 @@
20592059
"required": false,
20602060
"description": "Additional CSS class for the root DOM node"
20612061
},
2062-
"loading": {
2062+
"status": {
20632063
"type": {
20642064
"name": "shape",
20652065
"value": {
2066-
"loading": {
2066+
"isLoading": {
20672067
"name": "bool",
2068+
"description": "Determines if the component is loading or not",
20682069
"required": false
20692070
},
2070-
"prop": {
2071+
"propName": {
20712072
"name": "string",
2073+
"description": "Holds which property is loading",
2074+
"required": false
2075+
},
2076+
"componentName": {
2077+
"name": "string",
2078+
"description": "Holds the name of the component that is loading",
20722079
"required": false
20732080
}
20742081
}
20752082
},
20762083
"required": false,
2077-
"description": "Object that holds the loading prop, a bool that determines if the component is loading, and the actual\nprop that's causing the load as a String."
2084+
"description": "Object that holds the status object coming from dash-renderer"
20782085
}
20792086
}
20802087
},

dash_core_components/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"build:js": "webpack --mode production",
2222
"build:js-dev": "webpack --mode development",
2323
"build:py": "node ./extract-meta src/components > dash_core_components/metadata.json && cp package.json dash_core_components && npm run generate-python-classes",
24-
"build:all": "npm run build:js && npm run build:py",
24+
"build:all": "npm run build:js && npm run build:js-dev && npm run build:py",
2525
"build:all-dev": "npm run build:js-dev && npm run build:py",
2626
"build:watch": "watch 'npm run build:all' src"
2727
},

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"build:js": "webpack --mode production",
2222
"build:js-dev": "webpack --mode development",
2323
"build:py": "node ./extract-meta src/components > dash_core_components/metadata.json && cp package.json dash_core_components && npm run generate-python-classes",
24-
"build:all": "npm run build:js && npm run build:py",
24+
"build:all": "npm run build:js && npm run build:js-dev && npm run build:py",
2525
"build:all-dev": "npm run build:js-dev && npm run build:py",
2626
"build:watch": "watch 'npm run build:all' src"
2727
},

src/components/Loading.react.js

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,12 @@ export default class Loading extends Component {
1010
}
1111

1212
render() {
13-
const {loading} = this.props.loading;
14-
15-
window.console.log('loading prop:', this.props.loading.prop);
16-
17-
if (loading) {
13+
const status = this.props.status;
14+
if (status && status.isLoading) {
1815
return (
1916
<div>
2017
<div className="spinner-verts">
18+
<h3 className='dash-loading-title'>Loading {status.componentName}'s {status.propName}</h3>
2119
<div className="rect1" />
2220
<div className="rect2" />
2321
<div className="rect3" />
@@ -84,7 +82,7 @@ export default class Loading extends Component {
8482
</div>
8583
);
8684
}
87-
return this.props.children;
85+
return this.props.children || null;
8886
}
8987
}
9088

@@ -94,14 +92,14 @@ Loading.propTypes = {
9492
/**
9593
* Array that holds components to render
9694
*/
97-
children: React.PropTypes.oneOfType([
98-
React.PropTypes.arrayOf(React.PropTypes.node),
99-
React.PropTypes.node,
95+
children: PropTypes.oneOfType([
96+
PropTypes.arrayOf(PropTypes.node),
97+
PropTypes.node,
10098
]),
10199

102100
/**
103-
* String that determines which prop to listen to when loading
104-
*/
101+
* String that determines which prop to listen to when loading
102+
*/
105103
loadingProp: PropTypes.string,
106104

107105
/**
@@ -110,8 +108,20 @@ Loading.propTypes = {
110108
className: PropTypes.string,
111109

112110
/**
113-
* Object that holds the loading prop, a bool that determines if the component is loading, and the actual
114-
* prop that's causing the load as a String.
111+
* Object that holds the status object coming from dash-renderer
115112
*/
116-
loading: PropTypes.shape({loading: PropTypes.bool, prop: PropTypes.string}),
113+
status: PropTypes.shape({
114+
/**
115+
* Determines if the component is loading or not
116+
*/
117+
isLoading: PropTypes.bool,
118+
/**
119+
* Holds which property is loading
120+
*/
121+
propName: PropTypes.string,
122+
/**
123+
* Holds the name of the component that is loading
124+
*/
125+
componentName: PropTypes.string
126+
}),
117127
};

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import Checklist from './components/Checklist.react';
1111
import SyntaxHighlighter from './components/SyntaxHighlighter.react';
1212
import Interval from './components/Interval.react';
1313
import Markdown from './components/Markdown.react';
14+
import Loading from './components/Loading.react';
1415
import Location from './components/Location.react';
1516
import Link from './components/Link.react';
1617
import Textarea from './components/Textarea.react';
@@ -36,6 +37,7 @@ export {
3637
Tab,
3738
Interval,
3839
Markdown,
40+
Loading,
3941
Location,
4042
Link,
4143
Textarea,

test/unit/Loading.test.js

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import Loading from '../../src/components/Loading.react.js';
2+
import React from 'react';
3+
import {render} from 'enzyme';
4+
5+
test('Loading renders', () => {
6+
const statusMock = {
7+
isLoading: true,
8+
propName: 'children',
9+
componentName: 'div'
10+
}
11+
const loading = render(
12+
<Loading status={statusMock}>
13+
<div>Loading is done!</div>
14+
</Loading>
15+
);
16+
17+
expect(loading.html()).toBeDefined();
18+
});
19+
test('Loading renders without status', () => {
20+
const loading = render(
21+
<Loading>
22+
<div>Loading is done!</div>
23+
</Loading>
24+
);
25+
26+
expect(loading.html()).toBeDefined();
27+
});
28+
test('Loading renders without status.isLoading', () => {
29+
const statusMock = {
30+
propName: 'children',
31+
componentName: 'div'
32+
}
33+
const loading = render(
34+
<Loading status={statusMock}>
35+
<div>Loading is done!</div>
36+
</Loading>
37+
);
38+
39+
expect(loading.html()).toBeDefined();
40+
});
41+
test('Loading renders without status.propName', () => {
42+
const statusMock = {
43+
isLoading: true,
44+
componentName: 'div'
45+
}
46+
const loading = render(
47+
<Loading status={statusMock}>
48+
<div>Loading is done!</div>
49+
</Loading>
50+
);
51+
52+
expect(loading.html()).toBeDefined();
53+
});
54+
test('Loading renders without status.componentName', () => {
55+
const statusMock = {
56+
isLoading: true,
57+
propName: 'children'
58+
}
59+
const loading = render(
60+
<Loading status={statusMock}>
61+
<div>Loading is done!</div>
62+
</Loading>
63+
);
64+
65+
expect(loading.html()).toBeDefined();
66+
});
67+
test('Loading renders without children', () => {
68+
const statusMock = {
69+
isLoading: false,
70+
propName: 'children',
71+
componentName: 'div'
72+
}
73+
const loading = render(
74+
<Loading status={statusMock} />
75+
);
76+
77+
expect(loading.html()).toBeDefined();
78+
});

0 commit comments

Comments
 (0)