mirror of
https://github.com/strapi/strapi.git
synced 2025-08-09 09:14:49 +00:00
Merge branch 'master' into fix-left-menu-link-container-scroll
This commit is contained in:
commit
ae71c340fe
@ -30,12 +30,7 @@ import getQueryParameters from 'utils/getQueryParameters';
|
|||||||
import injectReducer from 'utils/injectReducer';
|
import injectReducer from 'utils/injectReducer';
|
||||||
import injectSaga from 'utils/injectSaga';
|
import injectSaga from 'utils/injectSaga';
|
||||||
|
|
||||||
import {
|
import { changeParams, deleteData, getData, setParams } from './actions';
|
||||||
changeParams,
|
|
||||||
deleteData,
|
|
||||||
getData,
|
|
||||||
setParams,
|
|
||||||
} from './actions';
|
|
||||||
|
|
||||||
import reducer from './reducer';
|
import reducer from './reducer';
|
||||||
import saga from './saga';
|
import saga from './saga';
|
||||||
@ -64,8 +59,9 @@ export class ListPage extends React.Component {
|
|||||||
* Helper to retrieve the current model data
|
* Helper to retrieve the current model data
|
||||||
* @return {Object} the current model
|
* @return {Object} the current model
|
||||||
*/
|
*/
|
||||||
getCurrentModel = () => get(this.props.models, ['models', this.getCurrentModelName()]) || get(this.props.models, ['plugins', this.getSource(), 'models', this.getCurrentModelName()]);
|
getCurrentModel = () =>
|
||||||
|
get(this.props.models, ['models', this.getCurrentModelName()]) ||
|
||||||
|
get(this.props.models, ['plugins', this.getSource(), 'models', this.getCurrentModelName()]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper to retrieve the current model name
|
* Helper to retrieve the current model name
|
||||||
@ -77,7 +73,7 @@ export class ListPage extends React.Component {
|
|||||||
* Function to fetch data
|
* Function to fetch data
|
||||||
* @param {Object} props
|
* @param {Object} props
|
||||||
*/
|
*/
|
||||||
getData = (props) => {
|
getData = props => {
|
||||||
const source = getQueryParameters(props.location.search, 'source');
|
const source = getQueryParameters(props.location.search, 'source');
|
||||||
const limit = toInteger(getQueryParameters(props.location.search, 'limit')) || 10;
|
const limit = toInteger(getQueryParameters(props.location.search, 'limit')) || 10;
|
||||||
const page = toInteger(getQueryParameters(props.location.search, 'page')) || 1;
|
const page = toInteger(getQueryParameters(props.location.search, 'page')) || 1;
|
||||||
@ -86,7 +82,7 @@ export class ListPage extends React.Component {
|
|||||||
|
|
||||||
this.props.setParams(params);
|
this.props.setParams(params);
|
||||||
this.props.getData(props.match.params.slug, source);
|
this.props.getData(props.match.params.slug, source);
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper to retrieve the model's source
|
* Helper to retrieve the model's source
|
||||||
@ -99,53 +95,64 @@ export class ListPage extends React.Component {
|
|||||||
* @return {Array}
|
* @return {Array}
|
||||||
*/
|
*/
|
||||||
generateTableHeaders = () => {
|
generateTableHeaders = () => {
|
||||||
const currentSchema = get(this.props.schema, [this.getCurrentModelName()]) || get(this.props.schema, ['plugins', this.getSource(), this.getCurrentModelName()]);
|
const currentSchema =
|
||||||
const tableHeaders = map(currentSchema.list, (value) => ({
|
get(this.props.schema, [this.getCurrentModelName()]) ||
|
||||||
|
get(this.props.schema, ['plugins', this.getSource(), this.getCurrentModelName()]);
|
||||||
|
const tableHeaders = map(currentSchema.list, value => ({
|
||||||
name: value,
|
name: value,
|
||||||
label: currentSchema.fields[value].label,
|
label: currentSchema.fields[value].label,
|
||||||
type: currentSchema.fields[value].type,
|
type: currentSchema.fields[value].type,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
tableHeaders.splice(0, 0, { name: this.getCurrentModel().primaryKey || 'id', label: 'Id', type: 'string' });
|
tableHeaders.splice(0, 0, {
|
||||||
|
name: this.getCurrentModel().primaryKey || 'id',
|
||||||
|
label: 'Id',
|
||||||
|
type: 'string',
|
||||||
|
});
|
||||||
|
|
||||||
return tableHeaders;
|
return tableHeaders;
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* [findPageSort description]
|
* [findPageSort description]
|
||||||
* @param {Object} props [description]
|
* @param {Object} props [description]
|
||||||
* @return {String} the model's primaryKey
|
* @return {String} the model's primaryKey
|
||||||
*/
|
*/
|
||||||
findPageSort = (props) => {
|
findPageSort = props => {
|
||||||
const { match: { params: { slug } } } = props;
|
const { match: { params: { slug } } } = props;
|
||||||
const source = this.getSource();
|
const source = this.getSource();
|
||||||
const modelPrimaryKey = get(
|
const modelPrimaryKey = get(props.models, ['models', slug.toLowerCase(), 'primaryKey']);
|
||||||
props.models,
|
|
||||||
['models', slug.toLowerCase(), 'primaryKey'],
|
|
||||||
);
|
|
||||||
// Check if the model is in a plugin
|
// Check if the model is in a plugin
|
||||||
const pluginModelPrimaryKey = get(
|
const pluginModelPrimaryKey = get(props.models.plugins, [
|
||||||
props.models.plugins,
|
source,
|
||||||
[source, 'models', slug.toLowerCase(), 'primaryKey'],
|
'models',
|
||||||
|
slug.toLowerCase(),
|
||||||
|
'primaryKey',
|
||||||
|
]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
getQueryParameters(props.location.search, 'sort') ||
|
||||||
|
modelPrimaryKey ||
|
||||||
|
pluginModelPrimaryKey ||
|
||||||
|
'id'
|
||||||
);
|
);
|
||||||
|
};
|
||||||
|
|
||||||
return getQueryParameters(props.location.search, 'sort') || modelPrimaryKey || pluginModelPrimaryKey || 'id';
|
handleChangeParams = e => {
|
||||||
}
|
|
||||||
|
|
||||||
handleChangeParams = (e) => {
|
|
||||||
const { history, listPage: { params } } = this.props;
|
const { history, listPage: { params } } = this.props;
|
||||||
const search = e.target.name === 'params.limit' ?
|
const search =
|
||||||
`page=${params.currentPage}&limit=${e.target.value}&sort=${params.sort}`
|
e.target.name === 'params.limit'
|
||||||
: `page=${e.target.value}&limit=${params.limit}&sort=${params.sort}`;
|
? `page=${params.currentPage}&limit=${e.target.value}&sort=${params.sort}&source=${this.getSource()}`
|
||||||
|
: `page=${e.target.value}&limit=${params.limit}&sort=${params.sort}&source=${this.getSource()}`;
|
||||||
this.props.history.push({
|
this.props.history.push({
|
||||||
pathname: history.pathname,
|
pathname: history.pathname,
|
||||||
search,
|
search,
|
||||||
});
|
});
|
||||||
|
|
||||||
this.props.changeParams(e);
|
this.props.changeParams(e);
|
||||||
}
|
};
|
||||||
|
|
||||||
handleChangeSort = (sort) => {
|
handleChangeSort = sort => {
|
||||||
const target = {
|
const target = {
|
||||||
name: 'params.sort',
|
name: 'params.sort',
|
||||||
value: sort,
|
value: sort,
|
||||||
@ -158,17 +165,16 @@ export class ListPage extends React.Component {
|
|||||||
search: `?page=${params.page}&limit=${params.limit}&sort=${sort}&source=${this.getSource()}`,
|
search: `?page=${params.page}&limit=${params.limit}&sort=${sort}&source=${this.getSource()}`,
|
||||||
});
|
});
|
||||||
this.props.changeParams({ target });
|
this.props.changeParams({ target });
|
||||||
}
|
};
|
||||||
|
|
||||||
handleDelete = (e) => {
|
handleDelete = e => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
this.props.deleteData(this.state.target, this.getCurrentModelName(), this.getSource());
|
this.props.deleteData(this.state.target, this.getCurrentModelName(), this.getSource());
|
||||||
this.setState({ showWarning: false });
|
this.setState({ showWarning: false });
|
||||||
}
|
};
|
||||||
|
|
||||||
|
toggleModalWarning = e => {
|
||||||
toggleModalWarning = (e) => {
|
|
||||||
if (!isUndefined(e)) {
|
if (!isUndefined(e)) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
@ -178,7 +184,7 @@ export class ListPage extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.setState({ showWarning: !this.state.showWarning });
|
this.setState({ showWarning: !this.state.showWarning });
|
||||||
}
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { listPage, listPage: { params } } = this.props;
|
const { listPage, listPage: { params } } = this.props;
|
||||||
@ -189,10 +195,13 @@ export class ListPage extends React.Component {
|
|||||||
entity: capitalize(this.props.match.params.slug) || 'Content Manager',
|
entity: capitalize(this.props.match.params.slug) || 'Content Manager',
|
||||||
},
|
},
|
||||||
kind: 'primaryAddShape',
|
kind: 'primaryAddShape',
|
||||||
onClick: () => this.props.history.push({
|
onClick: () =>
|
||||||
pathname: `${this.props.location.pathname}/create`,
|
this.props.history.push({
|
||||||
search: `?source=${this.getSource()}`,
|
pathname: `${this.props.location.pathname}/create`,
|
||||||
}),
|
search: `?redirectUrl=/plugins/content-manager/${this.getCurrentModelName()}?page=${
|
||||||
|
params.page
|
||||||
|
}&limit=${params.limit}&sort=${params.sort}&source=${this.getSource()}`,
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -202,7 +211,10 @@ export class ListPage extends React.Component {
|
|||||||
<PluginHeader
|
<PluginHeader
|
||||||
actions={pluginHeaderActions}
|
actions={pluginHeaderActions}
|
||||||
description={{
|
description={{
|
||||||
id: listPage.count > 1 ? 'content-manager.containers.List.pluginHeaderDescription' : 'content-manager.containers.List.pluginHeaderDescription.singular',
|
id:
|
||||||
|
listPage.count > 1
|
||||||
|
? 'content-manager.containers.List.pluginHeaderDescription'
|
||||||
|
: 'content-manager.containers.List.pluginHeaderDescription.singular',
|
||||||
values: {
|
values: {
|
||||||
label: listPage.count,
|
label: listPage.count,
|
||||||
},
|
},
|
||||||
@ -223,7 +235,9 @@ export class ListPage extends React.Component {
|
|||||||
history={this.props.history}
|
history={this.props.history}
|
||||||
primaryKey={this.getCurrentModel().primaryKey || 'id'}
|
primaryKey={this.getCurrentModel().primaryKey || 'id'}
|
||||||
handleDelete={this.toggleModalWarning}
|
handleDelete={this.toggleModalWarning}
|
||||||
redirectUrl={`?redirectUrl=/plugins/content-manager/${this.getCurrentModelName().toLowerCase()}?page=${params.page}&limit=${params.limit}&sort=${params.sort}&source=${this.getSource()}`}
|
redirectUrl={`?redirectUrl=/plugins/content-manager/${this.getCurrentModelName().toLowerCase()}?page=${
|
||||||
|
params.page
|
||||||
|
}&limit=${params.limit}&sort=${params.sort}&source=${this.getSource()}`}
|
||||||
/>
|
/>
|
||||||
<PopUpWarning
|
<PopUpWarning
|
||||||
isOpen={this.state.showWarning}
|
isOpen={this.state.showWarning}
|
||||||
@ -287,8 +301,4 @@ const withConnect = connect(mapStateToProps, mapDispatchToProps);
|
|||||||
const withReducer = injectReducer({ key: 'listPage', reducer });
|
const withReducer = injectReducer({ key: 'listPage', reducer });
|
||||||
const withSaga = injectSaga({ key: 'listPage', saga });
|
const withSaga = injectSaga({ key: 'listPage', saga });
|
||||||
|
|
||||||
export default compose(
|
export default compose(withReducer, withSaga, withConnect)(ListPage);
|
||||||
withReducer,
|
|
||||||
withSaga,
|
|
||||||
withConnect,
|
|
||||||
)(ListPage);
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user