Skip to content

Commit

Permalink
Enable & enforce react/sort-comp ESLint rule
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtekmaj committed Aug 12, 2019
1 parent aad1b8c commit 65daa8b
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 49 deletions.
1 change: 0 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"reservedFirst": ["key"]
}],
"react/require-default-props": "off",
"react/sort-comp": "off",
"react/sort-prop-types": "error"
},
"overrides": [
Expand Down
96 changes: 48 additions & 48 deletions src/Calendar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,54 +153,6 @@ const getActiveStartDate = (props) => {
};

export default class Calendar extends Component {
get drillDownAvailable() {
const { maxDetail, minDetail } = this.props;
const { view } = this.state;

const views = getLimitedViews(minDetail, maxDetail);

return views.indexOf(view) < views.length - 1;
}

get drillUpAvailable() {
const { maxDetail, minDetail } = this.props;
const { view } = this.state;

const views = getLimitedViews(minDetail, maxDetail);

return views.indexOf(view) > 0;
}

get valueType() {
const { maxDetail } = this.props;

return getValueType(maxDetail);
}

/**
* Gets current value in a desired format.
*/
getProcessedValue(value) {
const {
minDate, maxDate, maxDetail, returnValue,
} = this.props;

const processFunction = (() => {
switch (returnValue) {
case 'start':
return getDetailValueFrom;
case 'end':
return getDetailValueTo;
case 'range':
return getDetailValueArray;
default:
throw new Error('Invalid returnValue.');
}
})();

return processFunction(value, minDate, maxDate, maxDetail);
}

static getDerivedStateFromProps(nextProps, prevState) {
const {
minDate, maxDate, minDetail, maxDetail,
Expand Down Expand Up @@ -256,6 +208,54 @@ export default class Calendar extends Component {

state = {};

get drillDownAvailable() {
const { maxDetail, minDetail } = this.props;
const { view } = this.state;

const views = getLimitedViews(minDetail, maxDetail);

return views.indexOf(view) < views.length - 1;
}

get drillUpAvailable() {
const { maxDetail, minDetail } = this.props;
const { view } = this.state;

const views = getLimitedViews(minDetail, maxDetail);

return views.indexOf(view) > 0;
}

get valueType() {
const { maxDetail } = this.props;

return getValueType(maxDetail);
}

/**
* Gets current value in a desired format.
*/
getProcessedValue(value) {
const {
minDate, maxDate, maxDetail, returnValue,
} = this.props;

const processFunction = (() => {
switch (returnValue) {
case 'start':
return getDetailValueFrom;
case 'end':
return getDetailValueTo;
case 'range':
return getDetailValueArray;
default:
throw new Error('Invalid returnValue.');
}
})();

return processFunction(value, minDate, maxDate, maxDetail);
}

/**
* Called when the user uses navigation buttons.
*/
Expand Down

0 comments on commit 65daa8b

Please sign in to comment.