Skip to content

Commit 794b81e

Browse files
amanmahajan7malonecj
authored andcommitted
Convert createReactClass components to ES6 classes (Comcast#1094)
* Convert React.class components to ES6 class components * Add missing prop types * Convert canvas to class component * Remove peer dependency on create-react-class package * Conver DateRangeEditor to ES6 class component * Remove create-react-class peer dependency * Fix deleted text * Update migration guide
1 parent 67c659b commit 794b81e

File tree

15 files changed

+503
-545
lines changed

15 files changed

+503
-545
lines changed

config/webpack.common.config.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,6 @@ const config = {
3535
commonjs2: 'react-dom',
3636
amd: 'react-dom'
3737
},
38-
'create-react-class': {
39-
root: 'createReactClass',
40-
commonjs: 'create-react-class',
41-
commonjs2: 'create-react-class',
42-
amd: 'create-react-class'
43-
},
4438
'react/addons': 'React',
4539
moment: 'moment'
4640
},

migrations/v2-v3.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
### Differences
44
### 2.0.0
5-
- Bundles `create-react-class` package with `react-data-grid`;
5+
- Bundles `create-react-class` package with `react-data-grid`;
66

77
### 3.0.0
8-
- Does not bundle `create-react-class` package with `react-data-grid`. It is specified as a peer dependency now;
8+
- <del>Does not bundle `create-react-class` package with `react-data-grid`. It is specified as a peer dependency now [1065](https://github.com/adazzle/react-data-grid/pull/1065);</del> ReactDataGrid is not longer dependent on `create-react-class` as all the components have been migrated to ES6 Classes ([#1078](https://github.com/adazzle/react-data-grid/pull/1078) and [#1094](https://github.com/adazzle/react-data-grid/pull/1094))
99

1010
### Steps for a sucessfull migration
11-
- Install create-react-class package (```npm install create-react-class```)
11+
- <del>Install create-react-class package (```npm install create-react-class```)</del> This is no longer required

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
"react-component"
2424
],
2525
"peerDependencies": {
26-
"create-react-class": "^15.6.2",
2726
"react": "^15.6.2",
2827
"react-dom": "^15.6.2"
2928
},
@@ -56,7 +55,6 @@
5655
"babel-preset-es2015-loose": "^7.0.0",
5756
"babel-preset-react": "^6.3.13",
5857
"copy-dir": "^0.3.0",
59-
"create-react-class": "^15.6.2",
6058
"css-loader": "^0.26.0",
6159
"del": "^1.2.1",
6260
"enzyme": "2.8.0",
Lines changed: 16 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,42 @@
11
const React = require('react');
22
import PropTypes from 'prop-types';
3-
const createReactClass = require('create-react-class');
4-
const ReactDOM = require('react-dom');
53
const Moment = require('moment');
64
const DateRangeFilter = require('./widgets/DateRangeFilter');
75
type DateRangeValue = { startDate: Date; endDate: Date};
86

9-
const DateRangeEditor = createReactClass({
10-
displayName: 'DateRangeEditor',
7+
class DateRangeEditor extends React.Component {
8+
static displayName = 'DateRangeEditor';
119

12-
propTypes: {
10+
static propTypes = {
1311
format: PropTypes.string,
1412
ranges: PropTypes.arrayOf(PropTypes.string),
1513
value: PropTypes.shape({
1614
startDate: PropTypes.Date.isRequired,
1715
endDate: PropTypes.Date.isRequired
1816
}).isRequired
19-
},
17+
};
2018

21-
getDefaultProps(): {format: string; ranges: Array<Date>} {
22-
return {
23-
format: 'YYYY-MM-DD',
24-
ranges: []
25-
};
26-
},
19+
static defaultProps = {
20+
format: 'YYYY-MM-DD',
21+
ranges: []
22+
};
2723

28-
rangeSeparatorChar: ' - ',
24+
rangeSeparatorChar = ' - ';
2925

30-
overrides: {
31-
checkFocus: function() {
32-
this.setTextInputFocus();
33-
},
34-
getInputNode(): HTMLElement {
35-
return ReactDOM.findDOMNode(this.refs.datepicker);
36-
},
37-
getValue(): DateRangeValue {
38-
let dateToParse = this.getInputNode().value;
39-
let dateRanges = dateToParse.split(this.rangeSeparatorChar);
40-
if (dateRanges.length !== 2) {
41-
throw new Error('DateRangeEditor.getValue error : ' + dateToParse + ' is not in the correct format');
42-
}
43-
44-
return {startDate: dateRanges[0].trim(), endDate: dateRanges[1].trim()};
45-
}
46-
},
47-
48-
isDateValid(date: Date): boolean {
26+
isDateValid = (date: Date): boolean => {
4927
return new Moment(date, this.props.format, true).isValid();
50-
},
28+
};
5129

52-
validate(value: DateRangeValue): boolean {
30+
validate = (value: DateRangeValue): boolean => {
5331
return this.isDateValid(value.startDate)
5432
&& this.isDateValid(value.endDate)
5533
&& (new Moment(value.startDate, this.props.format).isBefore(value.endDate)
5634
|| new Moment(value.startDate, this.props.format).isSame(value.endDate));
57-
},
35+
};
5836

59-
handleDateFilterApply(startDate: string, endDate: string) {
37+
handleDateFilterApply = (startDate: string, endDate: string) => {
6038
this.commit({value: {startDate: startDate, endDate: endDate}});
61-
},
39+
};
6240

6341
render(): ?ReactElement {
6442
return (
@@ -67,6 +45,6 @@ const DateRangeEditor = createReactClass({
6745
</div>
6846
);
6947
}
70-
});
48+
}
7149

7250
module.exports = DateRangeEditor;

packages/react-data-grid-examples/src/documentation.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
<!-- JavaScript srcs are placed at the end of the document so the pages load faster -->
2424
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.6.1/react.min.js"></script>
2525
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.6.1/react-dom.min.js"></script>
26-
<script src="https://unpkg.com/[email protected]/create-react-class.min.js"></script>
2726

2827
<!-- Custom styles for our template -->
2928
<link rel="stylesheet" href="assets/css/bootstrap.min.css">

packages/react-data-grid-examples/src/examples.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
<script src="scriptDelegator.js"></script>
4646
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.6.1/react.min.js"></script>
4747
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.6.1/react-dom.min.js"></script>
48-
<script src="https://unpkg.com/[email protected]/create-react-class.min.js"></script>
4948
<script type="text/javascript">
5049
delegateScript('shared.js');
5150
delegateScript('examples.js');

packages/react-data-grid-examples/src/index.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
<link rel="stylesheet" href="assets/css/main.css"></link>
1818
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.6.1/react.min.js"></script>
1919
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.6.1/react-dom.min.js"></script>
20-
<script src="https://unpkg.com/[email protected]/create-react-class.min.js"></script>
2120
<script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
2221
<script src="https://cdnjs.cloudflare.com/ajax/libs/Faker/3.0.1/faker.js"></script>
2322
<script src="https://cdnjs.cloudflare.com/ajax/libs/immutable/3.7.3/immutable.min.js"/></script>

0 commit comments

Comments
 (0)