2018-02-08 12:01:06 +01:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* HomePage
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { injectIntl } from 'react-intl';
|
|
|
|
import { bindActionCreators, compose } from 'redux';
|
2018-02-23 12:21:57 +01:00
|
|
|
import { isEmpty } from 'lodash';
|
2019-12-16 15:47:44 +01:00
|
|
|
import { Header } from '@buffetjs/custom';
|
2019-04-16 18:23:26 +02:00
|
|
|
import {
|
|
|
|
getQueryParameters,
|
|
|
|
ContainerFluid,
|
|
|
|
InputSearch,
|
|
|
|
PageFooter,
|
2019-12-16 15:47:44 +01:00
|
|
|
GlobalContext,
|
2019-04-16 18:23:26 +02:00
|
|
|
} from 'strapi-helper-plugin';
|
2018-02-08 12:01:06 +01:00
|
|
|
|
2019-02-22 11:11:25 +01:00
|
|
|
import pluginId from '../../pluginId';
|
2019-09-16 12:23:52 +02:00
|
|
|
import { HomePageContextProvider } from '../../contexts/HomePage';
|
2019-02-22 11:11:25 +01:00
|
|
|
|
|
|
|
// Plugin's component
|
|
|
|
import EntriesNumber from '../../components/EntriesNumber';
|
|
|
|
import List from '../../components/List';
|
|
|
|
import PluginInputFile from '../../components/PluginInputFile';
|
2019-09-11 11:00:40 +02:00
|
|
|
import { EntriesWrapper, Wrapper } from './components';
|
2019-02-22 11:11:25 +01:00
|
|
|
|
2020-01-24 15:39:14 +01:00
|
|
|
/* eslint-disable */
|
|
|
|
|
2018-02-15 17:46:57 +01:00
|
|
|
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,
|
2018-02-23 12:21:57 +01:00
|
|
|
setParams,
|
2018-02-15 17:46:57 +01:00
|
|
|
} from './actions';
|
2018-02-08 12:01:06 +01:00
|
|
|
import selectHomePage from './selectors';
|
|
|
|
import reducer from './reducer';
|
|
|
|
import saga from './saga';
|
|
|
|
|
|
|
|
export class HomePage extends React.Component {
|
2019-12-16 15:47:44 +01:00
|
|
|
static contextType = GlobalContext;
|
|
|
|
|
2019-08-13 11:31:10 +02:00
|
|
|
UNSAFE_componentWillMount() {
|
2018-02-23 12:21:57 +01:00
|
|
|
if (!isEmpty(this.props.location.search)) {
|
2018-05-16 17:10:43 +02:00
|
|
|
const _page = parseInt(this.getURLParams('_page'), 10);
|
|
|
|
const _limit = parseInt(this.getURLParams('_limit'), 10);
|
|
|
|
const _sort = this.getURLParams('_sort');
|
2018-02-23 12:21:57 +01:00
|
|
|
|
2018-05-16 17:10:43 +02:00
|
|
|
this.props.setParams({ _limit, _page, _sort });
|
2018-02-23 12:21:57 +01:00
|
|
|
}
|
|
|
|
}
|
2018-02-16 15:39:35 +01:00
|
|
|
componentDidMount() {
|
|
|
|
this.props.getData();
|
|
|
|
}
|
|
|
|
|
2019-08-13 11:31:10 +02:00
|
|
|
UNSAFE_componentWillReceiveProps(nextProps) {
|
2018-02-19 15:14:32 +01:00
|
|
|
if (nextProps.deleteSuccess !== this.props.deleteSuccess) {
|
|
|
|
this.props.getData();
|
|
|
|
}
|
2018-02-23 12:21:57 +01:00
|
|
|
if (nextProps.location.search !== this.props.location.search) {
|
|
|
|
this.props.getData();
|
|
|
|
}
|
2018-02-19 15:14:32 +01:00
|
|
|
}
|
|
|
|
|
2019-04-16 18:23:26 +02:00
|
|
|
getURLParams = type => getQueryParameters(this.props.location.search, type);
|
2018-02-23 12:21:57 +01:00
|
|
|
|
2019-04-16 18:23:26 +02:00
|
|
|
changeSort = name => {
|
|
|
|
const {
|
|
|
|
params: { _limit, _page },
|
|
|
|
} = this.props;
|
2018-02-23 14:57:15 +01:00
|
|
|
const target = {
|
2018-05-16 17:10:43 +02:00
|
|
|
name: 'params._sort',
|
2018-02-23 14:57:15 +01:00
|
|
|
value: name,
|
|
|
|
};
|
2018-05-16 17:10:43 +02:00
|
|
|
const search = `_page=${_page}&_limit=${_limit}&_sort=${name}`;
|
2018-02-23 14:57:15 +01:00
|
|
|
|
|
|
|
this.props.changeParams({ target });
|
|
|
|
this.props.history.push({
|
|
|
|
pathname: this.props.history.pathname,
|
|
|
|
search,
|
|
|
|
});
|
2019-04-16 18:23:26 +02:00
|
|
|
};
|
2018-02-23 14:57:15 +01:00
|
|
|
|
2019-04-16 18:23:26 +02:00
|
|
|
handleChangeParams = e => {
|
2018-02-19 17:05:23 +01:00
|
|
|
const { history, params } = this.props;
|
2019-04-16 18:23:26 +02:00
|
|
|
const search =
|
|
|
|
e.target.name === 'params._limit'
|
|
|
|
? `_page=${params._page}&_limit=${e.target.value}&_sort=${params._sort}`
|
2019-07-30 17:25:18 +02:00
|
|
|
: `_page=${e.target.value}&_limit=${params._limit}&_sort=${params._sort}`;
|
2018-02-19 17:05:23 +01:00
|
|
|
this.props.history.push({
|
|
|
|
pathname: history.pathname,
|
|
|
|
search,
|
|
|
|
});
|
|
|
|
|
|
|
|
this.props.changeParams(e);
|
2019-04-16 18:23:26 +02:00
|
|
|
};
|
2018-02-19 17:05:23 +01:00
|
|
|
|
2018-02-22 12:31:41 +01:00
|
|
|
renderInputSearch = () => (
|
2018-02-15 17:46:57 +01:00
|
|
|
<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"
|
2019-12-16 15:47:44 +01:00
|
|
|
style={{ marginTop: '-11px' }}
|
2018-02-15 18:26:05 +01:00
|
|
|
value={this.props.search}
|
2018-02-15 17:46:57 +01:00
|
|
|
/>
|
2019-04-16 18:23:26 +02:00
|
|
|
);
|
2018-02-15 17:46:57 +01:00
|
|
|
|
2018-02-08 12:01:06 +01:00
|
|
|
render() {
|
2019-12-16 15:47:44 +01:00
|
|
|
const { formatMessage } = this.context;
|
|
|
|
|
2018-02-08 12:01:06 +01:00
|
|
|
return (
|
2019-09-16 12:23:52 +02:00
|
|
|
<HomePageContextProvider deleteData={this.props.deleteData}>
|
2019-12-16 15:47:44 +01:00
|
|
|
<ContainerFluid className="container-fluid">
|
2019-09-16 12:23:52 +02:00
|
|
|
<Wrapper>
|
2019-12-16 15:47:44 +01:00
|
|
|
<Header
|
|
|
|
actions={[
|
|
|
|
{
|
|
|
|
Component: this.renderInputSearch,
|
2019-12-16 15:56:42 +01:00
|
|
|
key: 'input-search',
|
2019-12-16 15:47:44 +01:00
|
|
|
},
|
|
|
|
]}
|
2019-09-16 12:23:52 +02:00
|
|
|
title={{
|
2019-12-16 15:47:44 +01:00
|
|
|
label: formatMessage({
|
|
|
|
id: 'upload.HomePage.title',
|
|
|
|
}),
|
2019-09-16 12:23:52 +02:00
|
|
|
}}
|
2019-12-16 15:47:44 +01:00
|
|
|
content={formatMessage({
|
2019-09-16 12:23:52 +02:00
|
|
|
id: 'upload.HomePage.description',
|
2019-12-16 15:47:44 +01:00
|
|
|
})}
|
2019-09-16 12:23:52 +02:00
|
|
|
/>
|
|
|
|
</Wrapper>
|
|
|
|
<PluginInputFile
|
|
|
|
name="files"
|
|
|
|
onDrop={this.props.onDrop}
|
|
|
|
showLoader={this.props.uploadFilesLoading}
|
2018-02-15 17:46:57 +01:00
|
|
|
/>
|
2019-09-16 12:23:52 +02:00
|
|
|
<EntriesWrapper>
|
|
|
|
<div>
|
|
|
|
{/* NOTE: Prepare for bulk actions}
|
2018-05-16 17:10:43 +02:00
|
|
|
<InputSelect
|
2018-02-16 15:39:35 +01:00
|
|
|
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-05-16 17:10:43 +02:00
|
|
|
/>
|
2018-02-16 15:39:35 +01:00
|
|
|
*/}
|
2019-09-16 12:23:52 +02:00
|
|
|
</div>
|
|
|
|
<EntriesNumber number={this.props.entriesNumber} />
|
|
|
|
</EntriesWrapper>
|
|
|
|
<List
|
|
|
|
data={this.props.uploadedFiles}
|
|
|
|
changeSort={this.changeSort}
|
|
|
|
sort={this.props.params._sort}
|
2018-02-19 17:05:23 +01:00
|
|
|
/>
|
2019-09-16 12:23:52 +02:00
|
|
|
<div className="col-md-12">
|
|
|
|
<PageFooter
|
|
|
|
count={this.props.entriesNumber}
|
|
|
|
context={{ emitEvent: () => {} }}
|
|
|
|
onChangeParams={this.handleChangeParams}
|
|
|
|
params={this.props.params}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</ContainerFluid>
|
|
|
|
</HomePageContextProvider>
|
2018-02-08 12:01:06 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-19 17:05:23 +01:00
|
|
|
HomePage.defaultProps = {
|
|
|
|
params: {
|
2018-05-16 17:10:43 +02:00
|
|
|
_limit: 10,
|
|
|
|
_page: 1,
|
|
|
|
_sort: 'updatedAt',
|
2018-02-19 17:05:23 +01:00
|
|
|
},
|
2018-02-23 14:57:15 +01:00
|
|
|
uploadedFiles: [],
|
2018-02-19 17:05:23 +01:00
|
|
|
};
|
|
|
|
|
2018-02-08 12:01:06 +01:00
|
|
|
HomePage.propTypes = {
|
2018-02-19 17:05:23 +01:00
|
|
|
changeParams: PropTypes.func.isRequired,
|
2018-02-22 12:08:11 +01:00
|
|
|
deleteData: PropTypes.func.isRequired,
|
|
|
|
deleteSuccess: PropTypes.bool.isRequired,
|
|
|
|
entriesNumber: PropTypes.number.isRequired,
|
2018-02-16 15:39:35 +01:00
|
|
|
getData: PropTypes.func.isRequired,
|
2018-02-22 12:08:11 +01:00
|
|
|
history: PropTypes.object.isRequired,
|
2018-02-23 12:21:57 +01:00
|
|
|
location: PropTypes.object.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,
|
2018-02-22 12:08:11 +01:00
|
|
|
params: PropTypes.object,
|
2018-02-15 17:46:57 +01:00
|
|
|
search: PropTypes.string.isRequired,
|
2018-02-23 12:21:57 +01:00
|
|
|
setParams: PropTypes.func.isRequired,
|
2018-02-22 12:08:11 +01:00
|
|
|
uploadedFiles: PropTypes.arrayOf(PropTypes.object),
|
2018-03-06 09:31:44 +01:00
|
|
|
uploadFilesLoading: PropTypes.bool.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-23 12:21:57 +01:00
|
|
|
setParams,
|
2018-02-08 12:01:06 +01:00
|
|
|
},
|
2019-07-30 17:25:18 +02:00
|
|
|
dispatch
|
2018-02-08 12:01:06 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-02-15 17:46:57 +01:00
|
|
|
const mapStateToProps = selectHomePage();
|
2018-02-08 12:01:06 +01:00
|
|
|
|
2020-01-28 18:20:21 +01:00
|
|
|
const withConnect = connect(mapStateToProps, mapDispatchToProps);
|
2018-02-08 12:01:06 +01:00
|
|
|
|
2019-04-16 18:23:26 +02:00
|
|
|
const withReducer = strapi.injectReducer({
|
|
|
|
key: 'homePage',
|
|
|
|
reducer,
|
|
|
|
pluginId,
|
|
|
|
});
|
2019-02-11 18:56:17 +01:00
|
|
|
const withSaga = strapi.injectSaga({ key: 'homePage', saga, pluginId });
|
2018-02-08 12:01:06 +01:00
|
|
|
|
|
|
|
export default compose(
|
|
|
|
withReducer,
|
|
|
|
withSaga,
|
2019-07-30 17:25:18 +02:00
|
|
|
withConnect
|
2018-02-08 12:01:06 +01:00
|
|
|
)(injectIntl(HomePage));
|