diff --git a/packages/strapi-plugin-content-manager/admin/src/components/TableHeader/index.js b/packages/strapi-plugin-content-manager/admin/src/components/TableHeader/index.js index fdb2f8731b..5a0ce6016e 100755 --- a/packages/strapi-plugin-content-manager/admin/src/components/TableHeader/index.js +++ b/packages/strapi-plugin-content-manager/admin/src/components/TableHeader/index.js @@ -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 = ; } else if (this.props.sort === `-${header.name}`) { icon = ; diff --git a/packages/strapi-plugin-content-manager/admin/src/components/TableRow/styles.scss b/packages/strapi-plugin-content-manager/admin/src/components/TableRow/styles.scss index 70dfed74f2..f01f5dc497 100755 --- a/packages/strapi-plugin-content-manager/admin/src/components/TableRow/styles.scss +++ b/packages/strapi-plugin-content-manager/admin/src/components/TableRow/styles.scss @@ -16,9 +16,6 @@ border-collapse: collapse; border-top: 1px solid #F1F1F2 !important; } - > td:first-child { - // width: 50px; - } } .truncate { diff --git a/packages/strapi-plugin-content-manager/admin/src/containers/ListPage/index.js b/packages/strapi-plugin-content-manager/admin/src/containers/ListPage/index.js index 5c060fecbf..12cfe08b99 100644 --- a/packages/strapi-plugin-content-manager/admin/src/containers/ListPage/index.js +++ b/packages/strapi-plugin-content-manager/admin/src/containers/ListPage/index.js @@ -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() ); }; diff --git a/packages/strapi-plugin-content-manager/admin/src/containers/SettingPage/index.js b/packages/strapi-plugin-content-manager/admin/src/containers/SettingPage/index.js index 4513f93636..8ecb264ff5 100644 --- a/packages/strapi-plugin-content-manager/admin/src/containers/SettingPage/index.js +++ b/packages/strapi-plugin-content-manager/admin/src/containers/SettingPage/index.js @@ -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 {