mirror of
https://github.com/strapi/strapi.git
synced 2025-09-25 08:19:07 +00:00
Add createdAt and updatedAt back into the CM layouts and metas
This commit is contained in:
parent
daf2e5010d
commit
3bc73a28c0
@ -109,7 +109,6 @@ DynamicTable.propTypes = {
|
||||
contentType: PropTypes.shape({
|
||||
attributes: PropTypes.object.isRequired,
|
||||
metadatas: PropTypes.object.isRequired,
|
||||
info: PropTypes.shape({ label: PropTypes.string.isRequired }).isRequired,
|
||||
layouts: PropTypes.shape({
|
||||
list: PropTypes.array.isRequired,
|
||||
editRelations: PropTypes.array,
|
||||
|
@ -74,7 +74,6 @@ FieldPicker.propTypes = {
|
||||
contentType: PropTypes.shape({
|
||||
attributes: PropTypes.object.isRequired,
|
||||
metadatas: PropTypes.object.isRequired,
|
||||
info: PropTypes.shape({ label: PropTypes.string.isRequired }).isRequired,
|
||||
layouts: PropTypes.shape({
|
||||
list: PropTypes.array.isRequired,
|
||||
editRelations: PropTypes.array,
|
||||
|
@ -43,7 +43,6 @@ ListViewLayout.propTypes = {
|
||||
contentType: PropTypes.shape({
|
||||
attributes: PropTypes.object.isRequired,
|
||||
metadatas: PropTypes.object.isRequired,
|
||||
info: PropTypes.shape({ label: PropTypes.string.isRequired }).isRequired,
|
||||
layouts: PropTypes.shape({
|
||||
list: PropTypes.array.isRequired,
|
||||
editRelations: PropTypes.array,
|
||||
|
@ -13,8 +13,7 @@
|
||||
"dependencies": {
|
||||
"@sindresorhus/slugify": "1.1.0",
|
||||
"@strapi/utils": "3.6.8",
|
||||
"lodash": "4.17.21",
|
||||
"pluralize": "^8.0.0"
|
||||
"lodash": "4.17.21"
|
||||
},
|
||||
"author": {
|
||||
"name": "Strapi team",
|
||||
|
@ -1,7 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const { upperFirst, prop, pick, getOr } = require('lodash/fp');
|
||||
const pluralize = require('pluralize');
|
||||
const { pick, getOr } = require('lodash/fp');
|
||||
const { contentTypes: contentTypesUtils } = require('@strapi/utils');
|
||||
|
||||
const dtoFields = [
|
||||
@ -21,16 +20,8 @@ module.exports = () => ({
|
||||
toContentManagerModel(contentType) {
|
||||
return {
|
||||
...contentType,
|
||||
options: {
|
||||
...contentType.options,
|
||||
timestamps: [],
|
||||
},
|
||||
apiID: contentType.modelName,
|
||||
isDisplayed: isVisible(contentType),
|
||||
info: {
|
||||
...contentType.info,
|
||||
label: formatContentTypeLabel(contentType),
|
||||
},
|
||||
attributes: {
|
||||
id: {
|
||||
type: 'integer',
|
||||
@ -43,34 +34,23 @@ module.exports = () => ({
|
||||
toDto: pick(dtoFields),
|
||||
});
|
||||
|
||||
const formatContentTypeLabel = contentType => {
|
||||
const name = prop('info.name', contentType) || contentType.modelName;
|
||||
|
||||
try {
|
||||
return contentTypesUtils.isSingleType(contentType)
|
||||
? upperFirst(name)
|
||||
: upperFirst(pluralize(name));
|
||||
} catch (error) {
|
||||
// in case pluralize throws cyrillic characters
|
||||
return upperFirst(name);
|
||||
}
|
||||
};
|
||||
|
||||
const formatAttributes = contentType => {
|
||||
const { getVisibleAttributes } = contentTypesUtils;
|
||||
const { getVisibleAttributes, getTimestamps } = contentTypesUtils;
|
||||
|
||||
// only get attributes that can be seen in the auto generated Edit view or List view
|
||||
return getVisibleAttributes(contentType).reduce((acc, key) => {
|
||||
const attribute = contentType.attributes[key];
|
||||
return getVisibleAttributes(contentType)
|
||||
.concat(getTimestamps(contentType))
|
||||
.reduce((acc, key) => {
|
||||
const attribute = contentType.attributes[key];
|
||||
|
||||
// ignore morph until they are handled in the front
|
||||
if (attribute.type === 'relation' && attribute.relation.toLowerCase().includes('morph')) {
|
||||
// ignore morph until they are handled in the front
|
||||
if (attribute.type === 'relation' && attribute.relation.toLowerCase().includes('morph')) {
|
||||
return acc;
|
||||
}
|
||||
|
||||
acc[key] = formatAttribute(key, attribute);
|
||||
return acc;
|
||||
}
|
||||
|
||||
acc[key] = formatAttribute(key, attribute);
|
||||
return acc;
|
||||
}, {});
|
||||
}, {});
|
||||
};
|
||||
|
||||
// FIXME: not needed
|
||||
|
@ -98,12 +98,12 @@ const isTimestamp = (schema, name) => {
|
||||
return false;
|
||||
}
|
||||
|
||||
const timestampsOpt = _.get(schema, ['options', 'timestamps']);
|
||||
if (!timestampsOpt || !Array.isArray(timestampsOpt)) {
|
||||
const timestamps = contentTypesUtils.getTimestamps(schema);
|
||||
if (!timestamps || !Array.isArray(timestamps)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (timestampsOpt.includes(name)) {
|
||||
if (timestamps.includes(name)) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
@ -56,36 +56,6 @@ describe('Content Manager End to End', () => {
|
||||
await builder.cleanup();
|
||||
});
|
||||
|
||||
describe('Content Types api', () => {
|
||||
test('Label is pluralized', async () => {
|
||||
const res = await rq({
|
||||
url: `/content-manager/content-types`,
|
||||
method: 'GET',
|
||||
});
|
||||
|
||||
expect(res.statusCode).toBe(200);
|
||||
expect(res.body.data).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
info: expect.objectContaining({
|
||||
label: 'Articles',
|
||||
}),
|
||||
}),
|
||||
expect.objectContaining({
|
||||
info: expect.objectContaining({
|
||||
label: 'Tags',
|
||||
}),
|
||||
}),
|
||||
expect.objectContaining({
|
||||
info: expect.objectContaining({
|
||||
label: 'Categories',
|
||||
}),
|
||||
}),
|
||||
])
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Test manyToMany relation (article - tag) with Content Manager', () => {
|
||||
beforeAll(async () => {
|
||||
data = {
|
||||
|
@ -35,24 +35,6 @@ describe('Content Manager single types', () => {
|
||||
await builder.cleanup();
|
||||
});
|
||||
|
||||
test('Label is not pluralized', async () => {
|
||||
const res = await rq({
|
||||
url: `/content-manager/content-types?kind=singleType`,
|
||||
method: 'GET',
|
||||
});
|
||||
|
||||
expect(res.statusCode).toBe(200);
|
||||
expect(res.body.data).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
info: expect.objectContaining({
|
||||
label: 'Single-type-model',
|
||||
}),
|
||||
}),
|
||||
])
|
||||
);
|
||||
});
|
||||
|
||||
test('find single type content returns 404 when not created', async () => {
|
||||
const res = await rq({
|
||||
url: `/content-manager/single-types/${uid}`,
|
||||
|
@ -59,6 +59,12 @@ describe('Content types utils', () => {
|
||||
type: 'string',
|
||||
writable: false,
|
||||
},
|
||||
createdAt: {
|
||||
type: 'datetime',
|
||||
},
|
||||
updatedAt: {
|
||||
type: 'datetime',
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const _ = require('lodash');
|
||||
const { has } = require('lodash/fp');
|
||||
|
||||
const SINGLE_TYPE = 'singleType';
|
||||
const COLLECTION_TYPE = 'collectionType';
|
||||
@ -31,8 +32,18 @@ const constants = {
|
||||
COLLECTION_TYPE,
|
||||
};
|
||||
|
||||
const getTimestamps = () => {
|
||||
return [CREATED_AT_ATTRIBUTE, UPDATED_AT_ATTRIBUTE];
|
||||
const getTimestamps = model => {
|
||||
const attributes = [];
|
||||
|
||||
if (has(CREATED_AT_ATTRIBUTE, model.attributes)) {
|
||||
attributes.push(CREATED_AT_ATTRIBUTE);
|
||||
}
|
||||
|
||||
if (has(UPDATED_AT_ATTRIBUTE, model.attributes)) {
|
||||
attributes.push(UPDATED_AT_ATTRIBUTE);
|
||||
}
|
||||
|
||||
return attributes;
|
||||
};
|
||||
|
||||
const getNonWritableAttributes = (model = {}) => {
|
||||
@ -42,7 +53,7 @@ const getNonWritableAttributes = (model = {}) => {
|
||||
[]
|
||||
);
|
||||
|
||||
return _.uniq([ID_ATTRIBUTE, ...getTimestamps(), ...nonWritableAttributes]);
|
||||
return _.uniq([ID_ATTRIBUTE, ...getTimestamps(model), ...nonWritableAttributes]);
|
||||
};
|
||||
|
||||
const getWritableAttributes = (model = {}) => {
|
||||
@ -60,7 +71,7 @@ const getNonVisibleAttributes = model => {
|
||||
[]
|
||||
);
|
||||
|
||||
return _.uniq([ID_ATTRIBUTE, ...getTimestamps(), ...nonVisibleAttributes]);
|
||||
return _.uniq([ID_ATTRIBUTE, ...getTimestamps(model), ...nonVisibleAttributes]);
|
||||
};
|
||||
|
||||
const getVisibleAttributes = model => {
|
||||
@ -137,6 +148,7 @@ module.exports = {
|
||||
isWritableAttribute,
|
||||
getNonVisibleAttributes,
|
||||
getVisibleAttributes,
|
||||
getTimestamps,
|
||||
isVisibleAttribute,
|
||||
hasDraftAndPublish,
|
||||
isDraft,
|
||||
|
Loading…
x
Reference in New Issue
Block a user