Skip to content
This repository was archived by the owner on Jan 28, 2020. It is now read-only.

Commit e6b3cca

Browse files
author
George Schneeloch
committed
Moved spinner into separate React class
1 parent f1f02b8 commit e6b3cca

File tree

5 files changed

+78
-18
lines changed

5 files changed

+78
-18
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
define(['QUnit', 'jquery', 'react', 'test_utils', 'react_spinner'],
2+
function (QUnit, $, React, TestUtils, ReactSpinner) {
3+
"use strict";
4+
5+
QUnit.module('Test ReactSpinner', {
6+
beforeEach: function () {
7+
TestUtils.setup();
8+
},
9+
afterEach: function () {
10+
TestUtils.cleanup();
11+
}
12+
});
13+
14+
QUnit.test('Test turning spinner on', function (assert) {
15+
var done = assert.async();
16+
17+
var afterMount = function (component) {
18+
// Assert that spinner turns on.
19+
assert.equal(
20+
$(React.findDOMNode(component)).find(".spinner").size(),
21+
1
22+
);
23+
done();
24+
};
25+
26+
React.addons.TestUtils.renderIntoDocument(
27+
<ReactSpinner ref={afterMount}/>
28+
);
29+
});
30+
}
31+
);

ui/static/ui/js/require_config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var REQUIRE_PATHS = {
55
bootstrap: "bootstrap/dist/js/bootstrap.min",
66
icheck: "icheck/icheck.min",
77
retina: "retina.js/dist/retina.min",
8-
React: "react/react-with-addons.min",
8+
React: "react/react-with-addons",
99
react_infinite: "react-infinite/dist/react-infinite.min",
1010
react_datagrid: "../lib/js/react-datagrid.min",
1111
lodash: "lodash/lodash.min",
@@ -49,6 +49,7 @@ var REQUIRE_PATHS = {
4949
icheckbox: "../ui/js/util/icheckbox.jsx?noext",
5050
infinite_list: "../ui/js/util/infinite_list.jsx?noext",
5151
react_overlay_loader: "../ui/js/util/react_overlay_loader.jsx?noext",
52+
react_spinner: "../ui/js/util/react_spinner.jsx?noext",
5253
select2_component: "../ui/js/util/select2_component.jsx?noext",
5354
status_box: "../ui/js/util/status_box.jsx?noext",
5455
};

ui/static/ui/js/util/react_overlay_loader.jsx

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,18 @@
1-
define("react_overlay_loader", ["react", "spin"],
2-
function (React, Spinner) {
1+
define("react_overlay_loader", ["react", "react_spinner"],
2+
function (React, ReactSpinner) {
33
'use strict';
44

55
/**
66
* Adapted from react-loader
77
* https://github.com/quickleft/react-loader
88
*/
99
return React.createClass({
10-
componentDidUpdate: function () {
11-
this.spin();
12-
},
13-
componentDidMount: function () {
14-
this.spin();
15-
},
16-
spin: function () {
17-
if (this.isMounted() && !this.props.loaded) {
18-
var target = React.findDOMNode(this.refs.loader);
19-
20-
var spinner = new Spinner({zIndex: 0});
21-
spinner.spin(target);
22-
}
23-
},
2410
render: function () {
2511
var loader;
2612
var opacity = 1;
2713

2814
if (!this.props.loaded) {
29-
loader = <div ref="loader"/>;
15+
loader = <ReactSpinner />;
3016
opacity = 0.6;
3117
}
3218
var children;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
define("react_spinner", ["react", "spin", "jquery"],
2+
function (React, Spinner, $) {
3+
'use strict';
4+
5+
return React.createClass({
6+
spin: function () {
7+
if (this.isMounted()) {
8+
var target = React.findDOMNode(this);
9+
target.innerHTML = '';
10+
11+
var spinner = this.makeSpinner();
12+
spinner.spin(target);
13+
}
14+
},
15+
makeSpinner: function() {
16+
var props = $.extend({}, this.props);
17+
if (props.zIndex === undefined) {
18+
props.zIndex = 0;
19+
}
20+
return new Spinner(props);
21+
},
22+
componentDidUpdate: function () {
23+
this.spin();
24+
},
25+
componentDidMount: function () {
26+
this.spin();
27+
},
28+
render: function() {
29+
var radius = this.makeSpinner().opts.radius;
30+
31+
return <div style={{
32+
width: radius * 2,
33+
left: radius
34+
}}>
35+
</div>;
36+
}
37+
});
38+
}
39+
);

ui/templates/repository.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@
120120
<script type="text/jsx"
121121
src="{% static "ui/js/util/react_overlay_loader.jsx" %}">
122122
</script>
123+
<script type="text/jsx"
124+
src="{% static "ui/js/util/react_spinner.jsx" %}">
125+
</script>
123126
<script type="text/jsx"
124127
src="{% static "ui/js/util/select2_component.jsx" %}">
125128
</script>

0 commit comments

Comments
 (0)