From 29d8df2c9ebd8b5bb07809c8e9d71046db6d762d Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 22 Sep 2017 10:00:46 +0100 Subject: [PATCH] De-lint TruncatedList --- .eslintignore.errorfiles | 1 - .../views/elements/TruncatedList.js | 27 ++++++++++--------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/.eslintignore.errorfiles b/.eslintignore.errorfiles index 28e56e6e32..f9c5e58099 100644 --- a/.eslintignore.errorfiles +++ b/.eslintignore.errorfiles @@ -54,7 +54,6 @@ src/components/views/elements/RoomDirectoryButton.js src/components/views/elements/SettingsButton.js src/components/views/elements/StartChatButton.js src/components/views/elements/TintableSvg.js -src/components/views/elements/TruncatedList.js src/components/views/elements/UserSelector.js src/components/views/login/CaptchaForm.js src/components/views/login/CasLogin.js diff --git a/src/components/views/elements/TruncatedList.js b/src/components/views/elements/TruncatedList.js index d6a8e1fb7e..e35e12e039 100644 --- a/src/components/views/elements/TruncatedList.js +++ b/src/components/views/elements/TruncatedList.js @@ -1,5 +1,6 @@ /* Copyright 2016 OpenMarket Ltd +Copyright 2017 New Vector Ltd Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -13,7 +14,9 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -var React = require('react'); + +import React from 'react'; +import PropTypes from 'prop-types'; import { _t } from '../../../languageHandler'; module.exports = React.createClass({ @@ -21,12 +24,12 @@ module.exports = React.createClass({ propTypes: { // The number of elements to show before truncating. If negative, no truncation is done. - truncateAt: React.PropTypes.number, + truncateAt: PropTypes.number, // The className to apply to the wrapping div - className: React.PropTypes.string, + className: PropTypes.string, // A function which will be invoked when an overflow element is required. // This will be inserted after the children. - createOverflowElement: React.PropTypes.func + createOverflowElement: PropTypes.func, }, getDefaultProps: function() { @@ -36,25 +39,25 @@ module.exports = React.createClass({ return (
{_t("And %(count)s more...", {count: overflowCount})}
); - } + }, }; }, render: function() { - var childsJsx = this.props.children; - var overflowJsx; - var childArray = React.Children.toArray(this.props.children).filter((c) => { + let childsJsx = this.props.children; + let overflowJsx; + const childArray = React.Children.toArray(this.props.children).filter((c) => { return c != null; }); - var childCount = childArray.length; + const childCount = childArray.length; if (this.props.truncateAt >= 0) { - var overflowCount = childCount - this.props.truncateAt; + const overflowCount = childCount - this.props.truncateAt; if (overflowCount > 1) { overflowJsx = this.props.createOverflowElement( - overflowCount, childCount + overflowCount, childCount, ); // cut out the overflow elements @@ -69,5 +72,5 @@ module.exports = React.createClass({ {overflowJsx} ); - } + }, });