1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 |
|
7 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
8 |
|
9 | var _body = require('./body');
|
10 |
|
11 | var _body2 = _interopRequireDefault(_body);
|
12 |
|
13 | var _head = require('./head');
|
14 |
|
15 | var _head2 = _interopRequireDefault(_head);
|
16 |
|
17 | var _foot = require('./foot');
|
18 |
|
19 | var _foot2 = _interopRequireDefault(_foot);
|
20 |
|
21 | var _style = require('./style.css');
|
22 |
|
23 | var _style2 = _interopRequireDefault(_style);
|
24 |
|
25 | var _sortBy = require('lodash/sortBy');
|
26 |
|
27 | var _sortBy2 = _interopRequireDefault(_sortBy);
|
28 |
|
29 | var _debounce = require('lodash/debounce');
|
30 |
|
31 | var _debounce2 = _interopRequireDefault(_debounce);
|
32 |
|
33 | var _reactAddonsShallowCompare = require('react-addons-shallow-compare');
|
34 |
|
35 | var _reactAddonsShallowCompare2 = _interopRequireDefault(_reactAddonsShallowCompare);
|
36 |
|
37 | var _react = require('react');
|
38 |
|
39 | var _react2 = _interopRequireDefault(_react);
|
40 |
|
41 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
42 |
|
43 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
44 |
|
45 | function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
46 |
|
47 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
48 |
|
49 | var ResultsTable = function (_Component) {
|
50 | _inherits(ResultsTable, _Component);
|
51 |
|
52 | function ResultsTable() {
|
53 | var _ref;
|
54 |
|
55 | var _temp, _this, _ret;
|
56 |
|
57 | _classCallCheck(this, ResultsTable);
|
58 |
|
59 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
60 | args[_key] = arguments[_key];
|
61 | }
|
62 |
|
63 | return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = ResultsTable.__proto__ || Object.getPrototypeOf(ResultsTable)).call.apply(_ref, [this].concat(args))), _this), _this.state = {
|
64 | sortBy: 'label',
|
65 | orderByDesc: true,
|
66 | showPrevious: false,
|
67 | showNext: true
|
68 | }, _this.onScroll = function (event) {
|
69 | event.persist();
|
70 | _this.updateNavigationIndicators(event);
|
71 | }, _this.onHeaderClick = function (header) {
|
72 | if (_this.state.sortBy === header.props.id) {
|
73 | return _this.setState({ orderByDesc: !_this.state.orderByDesc });
|
74 | }
|
75 |
|
76 | return _this.setState({
|
77 | sortBy: header.props.id,
|
78 | orderByDesc: true
|
79 | });
|
80 | }, _this.updateNavigationIndicators = (0, _debounce2.default)(function (event) {
|
81 | var scrollLeft = event.target.scrollLeft;
|
82 |
|
83 | var _this$refs$body$getWi = _this.refs.body.getWidth(),
|
84 | width = _this$refs$body$getWi.width,
|
85 | scrollWidth = _this$refs$body$getWi.scrollWidth;
|
86 |
|
87 | _this.setState({
|
88 | showPrevious: scrollLeft > 60,
|
89 | showNext: scrollLeft + width < scrollWidth - 60
|
90 | });
|
91 | }, 200), _temp), _possibleConstructorReturn(_this, _ret);
|
92 | }
|
93 |
|
94 | |
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 | |
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 | _createClass(ResultsTable, [{
|
109 | key: 'shouldComponentUpdate',
|
110 |
|
111 |
|
112 | |
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 |
|
119 | value: function shouldComponentUpdate(nextProps, nextState) {
|
120 | return (0, _reactAddonsShallowCompare2.default)(this, nextProps, nextState);
|
121 | }
|
122 |
|
123 | |
124 |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 |
|
131 | |
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 |
|
140 |
|
141 | }, {
|
142 | key: 'getEntries',
|
143 |
|
144 |
|
145 | |
146 |
|
147 |
|
148 |
|
149 |
|
150 | value: function getEntries() {
|
151 | var _this2 = this;
|
152 |
|
153 | var entries = (0, _sortBy2.default)(this.props.entries, function (entry) {
|
154 | var sorter = entry[_this2.state.sortBy];
|
155 | return (0, _react.isValidElement)(sorter) ? sorter.props[sorter.props.sortBy] : sorter;
|
156 | });
|
157 | return this.state.orderByDesc ? entries : entries.reverse();
|
158 | }
|
159 |
|
160 | |
161 |
|
162 |
|
163 |
|
164 |
|
165 |
|
166 |
|
167 |
|
168 |
|
169 |
|
170 | }, {
|
171 | key: 'render',
|
172 |
|
173 |
|
174 | |
175 |
|
176 |
|
177 |
|
178 |
|
179 | value: function render() {
|
180 | return _react2.default.createElement(
|
181 | 'table',
|
182 | { className: _style2.default.component, ref: 'component' },
|
183 | _react2.default.createElement(_head2.default, {
|
184 | sortBy: this.state.sortBy,
|
185 | orderByDesc: this.state.orderByDesc,
|
186 | entries: this.getEntries(),
|
187 | onHeaderClick: this.onHeaderClick,
|
188 | showNavigation: this.state.showPrevious
|
189 | }),
|
190 | _react2.default.createElement(_body2.default, {
|
191 | ref: 'body',
|
192 | entries: this.getEntries(),
|
193 | countries: this.props.countries,
|
194 | onScroll: this.onScroll
|
195 | }),
|
196 | _react2.default.createElement(_foot2.default, {
|
197 | sortBy: this.state.sortBy,
|
198 | orderByDesc: this.state.orderByDesc,
|
199 | entries: this.getEntries(),
|
200 | onHeaderClick: this.onHeaderClick,
|
201 | showNavigation: this.state.showNext
|
202 | })
|
203 | );
|
204 | }
|
205 | }]);
|
206 |
|
207 | return ResultsTable;
|
208 | }(_react.Component);
|
209 |
|
210 | ResultsTable.propTypes = {
|
211 | entries: _react.PropTypes.array.isRequired,
|
212 | countries: _react.PropTypes.array.isRequired
|
213 | };
|
214 | exports.default = ResultsTable; |
\ | No newline at end of file |