Moved propTypes and defaultProps as static properties in class components

This commit is contained in:
Alejandro Celaya 2018-08-27 16:53:09 +02:00
parent 47e6e1ca1f
commit 0b089e24de
18 changed files with 168 additions and 209 deletions

View file

@ -9,12 +9,12 @@ import PropTypes from 'prop-types';
import { resetSelectedServer } from '../servers/reducers/selectedServer';
import './Home.scss';
const propTypes = {
export class HomeComponent extends React.Component {
static propTypes = {
resetSelectedServer: PropTypes.func,
servers: PropTypes.object,
};
export class HomeComponent extends React.Component {
componentDidMount() {
this.props.resetSelectedServer();
}
@ -51,8 +51,6 @@ export class HomeComponent extends React.Component {
}
}
HomeComponent.propTypes = propTypes;
const Home = connect(pick([ 'servers' ]), { resetSelectedServer })(HomeComponent);
export default Home;

View file

@ -10,11 +10,11 @@ import ServersDropdown from '../servers/ServersDropdown';
import './MainHeader.scss';
import shlinkLogo from './shlink-logo-white.png';
const propTypes = {
export class MainHeaderComponent extends React.Component {
static propTypes = {
location: PropTypes.object,
};
export class MainHeaderComponent extends React.Component {
state = { isOpen: false };
handleToggle = () => {
this.setState(({ isOpen }) => ({
@ -64,8 +64,6 @@ export class MainHeaderComponent extends React.Component {
}
}
MainHeaderComponent.propTypes = propTypes;
const MainHeader = withRouter(MainHeaderComponent);
export default MainHeader;

View file

@ -17,14 +17,14 @@ import TagsList from '../tags/TagsList';
import { serverType } from '../servers/prop-types';
import AsideMenu from './AsideMenu';
const propTypes = {
export class MenuLayoutComponent extends React.Component {
static propTypes = {
match: PropTypes.object,
selectServer: PropTypes.func,
location: PropTypes.object,
selectedServer: serverType,
};
export class MenuLayoutComponent extends React.Component {
state = { showSideBar: false };
// FIXME Shouldn't use componentWillMount, but this code has to be run before children components are rendered
@ -105,8 +105,6 @@ export class MenuLayoutComponent extends React.Component {
}
}
MenuLayoutComponent.propTypes = propTypes;
const MenuLayout = compose(
connect(pick([ 'selectedServer', 'shortUrlsListParams' ]), { selectServer }),
withRouter

View file

@ -2,18 +2,18 @@ import React from 'react';
import { withRouter } from 'react-router-dom';
import PropTypes from 'prop-types';
const propTypes = {
export class ScrollToTopComponent extends React.Component {
static propTypes = {
location: PropTypes.object,
window: PropTypes.shape({
scrollTo: PropTypes.func,
}),
children: PropTypes.node,
};
const defaultProps = {
static defaultProps = {
window,
};
export class ScrollToTopComponent extends React.Component {
componentDidUpdate(prevProps) {
const { location, window } = this.props;
@ -27,9 +27,6 @@ export class ScrollToTopComponent extends React.Component {
}
}
ScrollToTopComponent.defaultProps = defaultProps;
ScrollToTopComponent.propTypes = propTypes;
const ScrollToTop = withRouter(ScrollToTopComponent);
export default ScrollToTop;

View file

@ -5,12 +5,12 @@ import PropTypes from 'prop-types';
import DeleteServerModal from './DeleteServerModal';
import { serverType } from './prop-types';
const propTypes = {
export default class DeleteServerButton extends React.Component {
static propTypes = {
server: serverType,
className: PropTypes.string,
};
export default class DeleteServerButton extends React.Component {
state = { isModalOpen: false };
render() {
@ -37,5 +37,3 @@ export default class DeleteServerButton extends React.Component {
);
}
}
DeleteServerButton.propTypes = propTypes;

View file

@ -9,10 +9,11 @@ import serversExporter from '../servers/services/ServersExporter';
import { listServers } from './reducers/server';
import { serverType } from './prop-types';
const defaultProps = {
export class ServersDropdownComponent extends React.Component {
static defaultProps = {
serversExporter,
};
const propTypes = {
static propTypes = {
servers: PropTypes.object,
serversExporter: PropTypes.shape({
exportServers: PropTypes.func,
@ -22,7 +23,6 @@ const propTypes = {
listServers: PropTypes.func,
};
export class ServersDropdownComponent extends React.Component {
renderServers = () => {
const { servers, selectedServer, selectServer, serversExporter } = this.props;
@ -70,9 +70,6 @@ export class ServersDropdownComponent extends React.Component {
}
}
ServersDropdownComponent.defaultProps = defaultProps;
ServersDropdownComponent.propTypes = propTypes;
const ServersDropdown = connect(
pick([ 'servers', 'selectedServer' ]),
{ listServers, selectServer }

View file

@ -7,18 +7,18 @@ import PropTypes from 'prop-types';
import { createServers } from '../reducers/server';
import serversImporter, { serversImporterType } from '../services/ServersImporter';
const defaultProps = {
export class ImportServersBtnComponent extends React.Component {
static defaultProps = {
serversImporter,
onImport: () => ({}),
};
const propTypes = {
static propTypes = {
onImport: PropTypes.func,
serversImporter: serversImporterType,
createServers: PropTypes.func,
fileRef: PropTypes.oneOfType([ PropTypes.object, PropTypes.node ]),
};
export class ImportServersBtnComponent extends React.Component {
constructor(props) {
super(props);
this.fileRef = props.fileRef || React.createRef();
@ -58,9 +58,6 @@ export class ImportServersBtnComponent extends React.Component {
}
}
ImportServersBtnComponent.defaultProps = defaultProps;
ImportServersBtnComponent.propTypes = propTypes;
const ImportServersBtn = connect(null, { createServers })(ImportServersBtnComponent);
export default ImportServersBtn;

View file

@ -20,7 +20,8 @@ import { serverType } from '../servers/prop-types';
import { getShortUrlVisits, shortUrlVisitsType } from './reducers/shortUrlVisits';
import './ShortUrlVisits.scss';
const propTypes = {
export class ShortUrlsVisitsComponent extends React.Component {
static propTypes = {
processOsStats: PropTypes.func,
processBrowserStats: PropTypes.func,
processCountriesStats: PropTypes.func,
@ -30,14 +31,13 @@ const propTypes = {
selectedServer: serverType,
shortUrlVisits: shortUrlVisitsType,
};
const defaultProps = {
static defaultProps = {
processOsStats,
processBrowserStats,
processCountriesStats,
processReferrersStats,
};
export class ShortUrlsVisitsComponent extends React.Component {
state = { startDate: undefined, endDate: undefined };
loadVisits = () => {
const { match: { params }, getShortUrlVisits } = this.props;
@ -210,9 +210,6 @@ export class ShortUrlsVisitsComponent extends React.Component {
}
}
ShortUrlsVisitsComponent.propTypes = propTypes;
ShortUrlsVisitsComponent.defaultProps = defaultProps;
const ShortUrlsVisits = connect(
pick([ 'selectedServer', 'shortUrlVisits' ]),
{ getShortUrlVisits }

View file

@ -20,7 +20,8 @@ const SORTABLE_FIELDS = {
visits: 'Visits',
};
const propTypes = {
export class ShortUrlsListComponent extends React.Component {
static propTypes = {
listShortUrls: PropTypes.func,
shortUrlsListParams: shortUrlsListParamsType,
match: PropTypes.object,
@ -31,7 +32,6 @@ const propTypes = {
selectedServer: serverType,
};
export class ShortUrlsListComponent extends React.Component {
refreshList = (extraParams) => {
const { listShortUrls, shortUrlsListParams } = this.props;
@ -186,8 +186,6 @@ export class ShortUrlsListComponent extends React.Component {
}
}
ShortUrlsListComponent.propTypes = propTypes;
const ShortUrlsList = connect(
pick([ 'selectedServer', 'shortUrlsListParams' ]),
{ listShortUrls }

View file

@ -9,13 +9,13 @@ import { createShortUrlResultType } from '../reducers/shortUrlCreationResult';
import { stateFlagTimeout } from '../../utils/utils';
import './CreateShortUrlResult.scss';
const propTypes = {
export default class CreateShortUrlResult extends React.Component {
static propTypes = {
resetCreateShortUrl: PropTypes.func,
error: PropTypes.bool,
result: createShortUrlResultType,
};
export default class CreateShortUrlResult extends React.Component {
state = { showCopyTooltip: false };
componentDidMount() {
@ -62,5 +62,3 @@ export default class CreateShortUrlResult extends React.Component {
);
}
}
CreateShortUrlResult.propTypes = propTypes;

View file

@ -13,7 +13,8 @@ import {
import ExternalLink from '../../utils/ExternalLink';
import { shortUrlType } from '../reducers/shortUrlsList';
const propTypes = {
export class EditTagsModalComponent extends React.Component {
static propTypes = {
isOpen: PropTypes.bool.isRequired,
toggle: PropTypes.func.isRequired,
url: PropTypes.string.isRequired,
@ -24,7 +25,6 @@ const propTypes = {
resetShortUrlsTags: PropTypes.func,
};
export class EditTagsModalComponent extends React.Component {
saveTags = () => {
const { editShortUrlTags, shortUrl, toggle } = this.props;
@ -90,8 +90,6 @@ export class EditTagsModalComponent extends React.Component {
}
}
EditTagsModalComponent.propTypes = propTypes;
const EditTagsModal = connect(
pick([ 'shortUrlTags' ]),
{ editShortUrlTags, resetShortUrlsTags, shortUrlTagsEdited }

View file

@ -11,14 +11,14 @@ import { stateFlagTimeout } from '../../utils/utils';
import { ShortUrlsRowMenu } from './ShortUrlsRowMenu';
import './ShortUrlsRow.scss';
const propTypes = {
export class ShortUrlsRow extends React.Component {
static propTypes = {
refreshList: PropTypes.func,
shortUrlsListParams: shortUrlsListParamsType,
selectedServer: serverType,
shortUrl: shortUrlType,
};
export class ShortUrlsRow extends React.Component {
state = { copiedToClipboard: false };
renderTags(tags) {
@ -73,5 +73,3 @@ export class ShortUrlsRow extends React.Component {
);
}
}
ShortUrlsRow.propTypes = propTypes;

View file

@ -17,14 +17,14 @@ import QrCodeModal from './QrCodeModal';
import './ShortUrlsRowMenu.scss';
import EditTagsModal from './EditTagsModal';
const propTypes = {
export class ShortUrlsRowMenu extends React.Component {
static propTypes = {
completeShortUrl: PropTypes.string,
onCopyToClipboard: PropTypes.func,
selectedServer: serverType,
shortUrl: shortUrlType,
};
export class ShortUrlsRowMenu extends React.Component {
state = {
isOpen: false,
isQrModalOpen: false,
@ -91,5 +91,3 @@ export class ShortUrlsRowMenu extends React.Component {
);
}
}
ShortUrlsRowMenu.propTypes = propTypes;

View file

@ -10,16 +10,16 @@ import './TagCard.scss';
import DeleteTagConfirmModal from './helpers/DeleteTagConfirmModal';
import EditTagModal from './helpers/EditTagModal';
const propTypes = {
export default class TagCard extends React.Component {
static propTypes = {
tag: PropTypes.string,
currentServerId: PropTypes.string,
colorGenerator: colorGeneratorType,
};
const defaultProps = {
static defaultProps = {
colorGenerator,
};
export default class TagCard extends React.Component {
state = { isDeleteModalOpen: false, isEditModalOpen: false };
render() {
@ -69,6 +69,3 @@ export default class TagCard extends React.Component {
);
}
}
TagCard.propTypes = propTypes;
TagCard.defaultProps = defaultProps;

View file

@ -9,7 +9,9 @@ import TagCard from './TagCard';
const { ceil } = Math;
const TAGS_GROUP_SIZE = 4;
const propTypes = {
export class TagsListComponent extends React.Component {
static propTypes = {
filterTags: PropTypes.func,
listTags: PropTypes.func,
tagsList: PropTypes.shape({
@ -18,7 +20,6 @@ const propTypes = {
match: PropTypes.object,
};
export class TagsListComponent extends React.Component {
componentDidMount() {
const { listTags } = this.props;
@ -85,8 +86,6 @@ export class TagsListComponent extends React.Component {
}
}
TagsListComponent.propTypes = propTypes;
const TagsList = connect(pick([ 'tagsList' ]), { listTags, filterTags })(TagsListComponent);
export default TagsList;

View file

@ -5,7 +5,8 @@ import PropTypes from 'prop-types';
import { pick } from 'ramda';
import { deleteTag, tagDeleted, tagDeleteType } from '../reducers/tagDelete';
const propTypes = {
export class DeleteTagConfirmModalComponent extends React.Component {
static propTypes = {
tag: PropTypes.string.isRequired,
toggle: PropTypes.func.isRequired,
isOpen: PropTypes.bool.isRequired,
@ -14,7 +15,6 @@ const propTypes = {
tagDeleted: PropTypes.func,
};
export class DeleteTagConfirmModalComponent extends React.Component {
doDelete = () => {
const { tag, toggle, deleteTag } = this.props;
@ -68,8 +68,6 @@ export class DeleteTagConfirmModalComponent extends React.Component {
}
}
DeleteTagConfirmModalComponent.propTypes = propTypes;
const DeleteTagConfirmModal = connect(
pick([ 'tagDelete' ]),
{ deleteTag, tagDeleted }

View file

@ -10,7 +10,8 @@ import colorGenerator, { colorGeneratorType } from '../../utils/ColorGenerator';
import { editTag, tagEdited } from '../reducers/tagEdit';
import './EditTagModal.scss';
const propTypes = {
export class EditTagModalComponent extends React.Component {
static propTypes = {
tag: PropTypes.string,
editTag: PropTypes.func,
toggle: PropTypes.func,
@ -22,11 +23,10 @@ const propTypes = {
editing: PropTypes.bool,
}),
};
const defaultProps = {
static defaultProps = {
colorGenerator,
};
export class EditTagModalComponent extends React.Component {
saveTag = (e) => {
e.preventDefault();
const { tag: oldName, editTag, toggle } = this.props;
@ -133,9 +133,6 @@ export class EditTagModalComponent extends React.Component {
}
}
EditTagModalComponent.propTypes = propTypes;
EditTagModalComponent.defaultProps = defaultProps;
const EditTagModal = connect(pick([ 'tagEdit' ]), { editTag, tagEdited })(EditTagModalComponent);
export default EditTagModal;

View file

@ -6,17 +6,18 @@ import classnames from 'classnames';
import './SearchField.scss';
const DEFAULT_SEARCH_INTERVAL = 500;
const propTypes = {
export default class SearchField extends React.Component {
static propTypes = {
onChange: PropTypes.func.isRequired,
className: PropTypes.string,
placeholder: PropTypes.string,
};
const defaultProps = {
static defaultProps = {
className: '',
placeholder: 'Search...',
};
export default class SearchField extends React.Component {
state = { showClearBtn: false, searchTerm: '' };
timer = null;
@ -64,6 +65,3 @@ export default class SearchField extends React.Component {
);
}
}
SearchField.propTypes = propTypes;
SearchField.defaultProps = defaultProps;