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