2018-02-08 12:01:06 +01:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* HomePage
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { createStructuredSelector } from 'reselect';
|
|
|
|
import { injectIntl } from 'react-intl';
|
|
|
|
import { bindActionCreators, compose } from 'redux';
|
|
|
|
|
2018-02-15 17:46:57 +01:00
|
|
|
// You can find these components in either
|
|
|
|
// ./node_modules/strapi-helper-plugin/lib/src
|
|
|
|
// or strapi/packages/strapi-helper-plugin/lib/src
|
|
|
|
import ContainerFluid from 'components/ContainerFluid';
|
|
|
|
import InputSearch from 'components/InputSearch';
|
2018-02-16 15:39:35 +01:00
|
|
|
// import InputSelect from 'components/InputSelect';
|
2018-02-19 17:05:23 +01:00
|
|
|
import PageFooter from 'components/PageFooter';
|
2018-02-15 17:46:57 +01:00
|
|
|
import PluginHeader from 'components/PluginHeader';
|
|
|
|
|
2018-02-15 18:26:05 +01:00
|
|
|
// Plugin's component
|
2018-02-16 15:39:35 +01:00
|
|
|
import EntriesNumber from 'components/EntriesNumber';
|
2018-02-16 16:53:01 +01:00
|
|
|
import List from 'components/List';
|
2018-02-15 18:26:05 +01:00
|
|
|
import PluginInputFile from 'components/PluginInputFile';
|
2018-02-15 17:46:57 +01:00
|
|
|
|
|
|
|
// Utils
|
2018-02-08 12:01:06 +01:00
|
|
|
import injectReducer from 'utils/injectReducer';
|
|
|
|
import injectSaga from 'utils/injectSaga';
|
|
|
|
|
2018-02-15 17:46:57 +01:00
|
|
|
// Actions
|
|
|
|
import {
|
2018-02-19 17:05:23 +01:00
|
|
|
changeParams,
|
2018-02-19 15:14:32 +01:00
|
|
|
deleteData,
|
2018-02-16 15:39:35 +01:00
|
|
|
getData,
|
2018-02-19 15:14:32 +01:00
|
|
|
onDrop,
|
2018-02-15 17:46:57 +01:00
|
|
|
onSearch,
|
|
|
|
} from './actions';
|
|
|
|
|
2018-02-08 12:01:06 +01:00
|
|
|
// Selectors
|
|
|
|
import selectHomePage from './selectors';
|
|
|
|
|
|
|
|
// Styles
|
|
|
|
import styles from './styles.scss';
|
|
|
|
|
|
|
|
import reducer from './reducer';
|
|
|
|
import saga from './saga';
|
|
|
|
|
|
|
|
export class HomePage extends React.Component {
|
2018-02-19 15:14:32 +01:00
|
|
|
getChildContext = () => (
|
|
|
|
{
|
|
|
|
deleteData: this.props.deleteData,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2018-02-16 15:39:35 +01:00
|
|
|
componentDidMount() {
|
|
|
|
this.props.getData();
|
|
|
|
}
|
|
|
|
|
2018-02-19 15:14:32 +01:00
|
|
|
componentWillReceiveProps(nextProps) {
|
|
|
|
if (nextProps.deleteSuccess !== this.props.deleteSuccess) {
|
|
|
|
this.props.getData();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-19 17:05:23 +01:00
|
|
|
handleChangeParams = (e) => {
|
|
|
|
const { history, params } = this.props;
|
|
|
|
const search = e.target.nanme === 'params.limit' ?
|
2018-02-19 17:41:05 +01:00
|
|
|
`page=${params.currentPage}&limit=${e.target.value}&sort=${params.sort}`
|
2018-02-19 17:05:23 +01:00
|
|
|
: `page=${e.target.value}&limit=${params.limit}&sort=${params.sort}`
|
|
|
|
this.props.history.push({
|
|
|
|
pathname: history.pathname,
|
|
|
|
search,
|
|
|
|
});
|
|
|
|
|
|
|
|
this.props.changeParams(e);
|
|
|
|
}
|
|
|
|
|
2018-02-15 17:46:57 +01:00
|
|
|
renderInputSearch = () =>
|
|
|
|
<InputSearch
|
2018-02-15 18:26:05 +01:00
|
|
|
autoFocus
|
2018-02-15 17:46:57 +01:00
|
|
|
name="search"
|
|
|
|
onChange={this.props.onSearch}
|
|
|
|
placeholder="upload.HomePage.InputSearch.placeholder"
|
|
|
|
style={{ marginTop: '-10px' }}
|
2018-02-15 18:26:05 +01:00
|
|
|
value={this.props.search}
|
2018-02-15 17:46:57 +01:00
|
|
|
/>
|
|
|
|
|
2018-02-08 12:01:06 +01:00
|
|
|
render() {
|
|
|
|
return (
|
2018-02-15 17:46:57 +01:00
|
|
|
<ContainerFluid>
|
|
|
|
<div className={styles.homePageUpload}>
|
|
|
|
<PluginHeader
|
|
|
|
title={{
|
|
|
|
id: 'upload.HomePage.title',
|
|
|
|
}}
|
|
|
|
description={{
|
|
|
|
id: 'upload.HomePage.description',
|
|
|
|
}}
|
|
|
|
overrideRendering={this.renderInputSearch}
|
|
|
|
/>
|
|
|
|
</div>
|
2018-02-15 18:26:05 +01:00
|
|
|
<PluginInputFile
|
|
|
|
name="files"
|
2018-02-16 14:17:24 +01:00
|
|
|
onDrop={this.props.onDrop}
|
2018-02-15 18:26:05 +01:00
|
|
|
/>
|
2018-02-16 15:39:35 +01:00
|
|
|
<div className={styles.entriesWrapper}>
|
|
|
|
<div>
|
|
|
|
{/* NOTE: Prepare for bulk actions}
|
|
|
|
<InputSelect
|
|
|
|
name="bulkAction"
|
|
|
|
onChange={() => console.log('change')}
|
|
|
|
selectOptions={[{ value: 'select all'}]}
|
2018-02-16 16:53:01 +01:00
|
|
|
style={{ minWidth: '200px', height: '32px', marginTop: '-8px' }}
|
2018-02-16 15:39:35 +01:00
|
|
|
/>
|
|
|
|
*/}
|
|
|
|
</div>
|
|
|
|
<EntriesNumber number={this.props.entriesNumber} />
|
|
|
|
</div>
|
2018-02-19 13:10:35 +01:00
|
|
|
<List
|
|
|
|
data={this.props.uploadedFiles}
|
|
|
|
/>
|
2018-02-19 17:05:23 +01:00
|
|
|
<div className="col-md-12">
|
|
|
|
<PageFooter
|
2018-02-19 17:41:05 +01:00
|
|
|
count={this.props.entriesNumber}
|
2018-02-19 17:05:23 +01:00
|
|
|
onChangeParams={this.handleChangeParams}
|
|
|
|
params={this.props.params}
|
|
|
|
/>
|
|
|
|
</div>
|
2018-02-15 17:46:57 +01:00
|
|
|
</ContainerFluid>
|
2018-02-08 12:01:06 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-19 15:14:32 +01:00
|
|
|
HomePage.childContextTypes = {
|
|
|
|
deleteData: PropTypes.func.isRequired,
|
|
|
|
};
|
|
|
|
|
2018-02-08 12:01:06 +01:00
|
|
|
HomePage.contextTypes = {
|
|
|
|
router: PropTypes.object,
|
2018-02-19 13:10:35 +01:00
|
|
|
uploadedFiles: PropTypes.arrayOf(PropTypes.object),
|
2018-02-08 12:01:06 +01:00
|
|
|
};
|
|
|
|
|
2018-02-19 17:05:23 +01:00
|
|
|
HomePage.defaultProps = {
|
|
|
|
params: {
|
|
|
|
limit: 10,
|
2018-02-19 17:41:05 +01:00
|
|
|
currentPage: 1,
|
2018-02-19 17:05:23 +01:00
|
|
|
sort: 'updatedAt',
|
|
|
|
},
|
|
|
|
uploadedFiles: [{}],
|
|
|
|
};
|
|
|
|
|
2018-02-08 12:01:06 +01:00
|
|
|
HomePage.propTypes = {
|
2018-02-19 17:05:23 +01:00
|
|
|
changeParams: PropTypes.func.isRequired,
|
2018-02-16 15:39:35 +01:00
|
|
|
getData: PropTypes.func.isRequired,
|
2018-02-16 14:17:24 +01:00
|
|
|
onDrop: PropTypes.func.isRequired,
|
2018-02-15 17:46:57 +01:00
|
|
|
onSearch: PropTypes.func.isRequired,
|
|
|
|
search: PropTypes.string.isRequired,
|
2018-02-08 12:01:06 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
function mapDispatchToProps(dispatch) {
|
|
|
|
return bindActionCreators(
|
|
|
|
{
|
2018-02-19 17:05:23 +01:00
|
|
|
changeParams,
|
2018-02-19 15:14:32 +01:00
|
|
|
deleteData,
|
2018-02-16 15:39:35 +01:00
|
|
|
getData,
|
2018-02-19 15:14:32 +01:00
|
|
|
onDrop,
|
2018-02-15 17:46:57 +01:00
|
|
|
onSearch,
|
2018-02-08 12:01:06 +01:00
|
|
|
},
|
|
|
|
dispatch,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-02-15 17:46:57 +01:00
|
|
|
const mapStateToProps = selectHomePage();
|
2018-02-08 12:01:06 +01:00
|
|
|
|
|
|
|
const withConnect = connect(mapStateToProps, mapDispatchToProps);
|
|
|
|
|
|
|
|
const withReducer = injectReducer({ key: 'homePage', reducer });
|
|
|
|
const withSaga = injectSaga({ key: 'homePage', saga });
|
|
|
|
|
|
|
|
export default compose(
|
|
|
|
withReducer,
|
|
|
|
withSaga,
|
|
|
|
withConnect,
|
|
|
|
)(injectIntl(HomePage));
|