mirror of
https://github.com/strapi/strapi.git
synced 2025-09-22 14:59:07 +00:00
Apply list settings in listView
This commit is contained in:
parent
4393511aab
commit
3adaf8cdcc
@ -47,7 +47,7 @@ class TableHeader extends React.Component {
|
||||
// Define sort icon
|
||||
let icon;
|
||||
|
||||
if (this.props.sort === header.name) {
|
||||
if (this.props.sort === header.name || this.props.sort === 'id' && header.name === '_id') {
|
||||
icon = <i className={`fa fa-sort-asc ${styles.iconAsc}`} />;
|
||||
} else if (this.props.sort === `-${header.name}`) {
|
||||
icon = <i className={`fa fa-sort-asc ${styles.iconDesc}`} />;
|
||||
|
@ -16,9 +16,6 @@
|
||||
border-collapse: collapse;
|
||||
border-top: 1px solid #F1F1F2 !important;
|
||||
}
|
||||
> td:first-child {
|
||||
// width: 50px;
|
||||
}
|
||||
}
|
||||
|
||||
.truncate {
|
||||
|
@ -111,6 +111,17 @@ export class ListPage extends React.Component {
|
||||
get(this.props.schema, ['models', 'plugins', this.getSource(), this.getCurrentModelName()])
|
||||
);
|
||||
|
||||
getCurrentModelDefaultLimit = () => (
|
||||
get(this.getCurrentModel(), 'pageEntries', 10)
|
||||
);
|
||||
|
||||
getCurrentModelDefaultSort = () => {
|
||||
const sortAttr = get(this.getCurrentModel(), 'defaultSort', 'id');
|
||||
const order = get(this.getCurrentModel(), 'sort', 'ASC');
|
||||
|
||||
return order === 'ASC' ? sortAttr : `-${sortAttr}`;
|
||||
};
|
||||
|
||||
/**
|
||||
* Helper to retrieve the current model name
|
||||
* @return {String} the current model's name
|
||||
@ -123,7 +134,7 @@ export class ListPage extends React.Component {
|
||||
*/
|
||||
getData = (props, setUpdatingParams = false) => {
|
||||
const source = getQueryParameters(props.location.search, 'source');
|
||||
const _limit = toInteger(getQueryParameters(props.location.search, '_limit')) || 10;
|
||||
const _limit = toInteger(getQueryParameters(props.location.search, '_limit')) || this.getCurrentModelDefaultLimit();
|
||||
const _page = toInteger(getQueryParameters(props.location.search, '_page')) || 1;
|
||||
const _sort = this.findPageSort(props);
|
||||
const _q = getQueryParameters(props.location.search, '_q') || '';
|
||||
@ -190,25 +201,9 @@ export class ListPage extends React.Component {
|
||||
* @return {String} the model's primaryKey
|
||||
*/
|
||||
findPageSort = props => {
|
||||
const {
|
||||
match: {
|
||||
params: { slug },
|
||||
},
|
||||
} = props;
|
||||
const source = this.getSource();
|
||||
const modelPrimaryKey = get(props.schema, [slug.toLowerCase(), 'primaryKey']);
|
||||
// Check if the model is in a plugin
|
||||
const pluginModelPrimaryKey = get(props.schema.plugins, [
|
||||
source,
|
||||
slug.toLowerCase(),
|
||||
'primaryKey',
|
||||
]);
|
||||
|
||||
return (
|
||||
getQueryParameters(props.location.search, '_sort') ||
|
||||
modelPrimaryKey ||
|
||||
pluginModelPrimaryKey ||
|
||||
'id'
|
||||
this.getCurrentModelDefaultSort()
|
||||
);
|
||||
};
|
||||
|
||||
|
@ -38,7 +38,7 @@ class SettingPage extends React.PureComponent {
|
||||
getModelName = () => {
|
||||
const { match: { params: { slug } } } = this.props;
|
||||
|
||||
return last(slug.split('::'));
|
||||
return slug.split('::');
|
||||
}
|
||||
|
||||
getPath = () => {
|
||||
@ -49,11 +49,11 @@ class SettingPage extends React.PureComponent {
|
||||
|
||||
getSelectOptions = (input) => {
|
||||
const { schema: { models } } = this.props;
|
||||
const currentAttributes = models[this.getModelName()].attributes;
|
||||
const selectOptions = [models[this.getModelName()].primaryKey]
|
||||
const currentAttributes = get(models, this.getModelName().concat(['attributes']), []);
|
||||
const selectOptions = [get(models, this.getModelName().concat(['primaryKey']), 'id')]
|
||||
.concat(Object.keys(currentAttributes)
|
||||
.filter(attr => currentAttributes[attr].type !== 'json' && currentAttributes[attr].type !== 'array'));
|
||||
|
||||
|
||||
return input.name === 'defaultSort' ? selectOptions : input.selectOptions;
|
||||
}
|
||||
|
||||
@ -99,7 +99,7 @@ class SettingPage extends React.PureComponent {
|
||||
<div className={cn('container-fluid', styles.containerFluid)}>
|
||||
<PluginHeader
|
||||
actions={this.getPluginHeaderActions()}
|
||||
title={`Content Manager - ${upperFirst(this.getModelName())}`}
|
||||
title={`Content Manager - ${upperFirst(last(this.getModelName()))}`}
|
||||
description={{ id: 'content-manager.containers.SettingPage.pluginHeaderDescription' }}
|
||||
/>
|
||||
<PopUpWarning
|
||||
|
Loading…
x
Reference in New Issue
Block a user