mirror of
https://github.com/strapi/strapi.git
synced 2025-09-28 01:40:11 +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({
|
contentType: PropTypes.shape({
|
||||||
attributes: PropTypes.object.isRequired,
|
attributes: PropTypes.object.isRequired,
|
||||||
metadatas: PropTypes.object.isRequired,
|
metadatas: PropTypes.object.isRequired,
|
||||||
info: PropTypes.shape({ label: PropTypes.string.isRequired }).isRequired,
|
|
||||||
layouts: PropTypes.shape({
|
layouts: PropTypes.shape({
|
||||||
list: PropTypes.array.isRequired,
|
list: PropTypes.array.isRequired,
|
||||||
editRelations: PropTypes.array,
|
editRelations: PropTypes.array,
|
||||||
|
@ -74,7 +74,6 @@ FieldPicker.propTypes = {
|
|||||||
contentType: PropTypes.shape({
|
contentType: PropTypes.shape({
|
||||||
attributes: PropTypes.object.isRequired,
|
attributes: PropTypes.object.isRequired,
|
||||||
metadatas: PropTypes.object.isRequired,
|
metadatas: PropTypes.object.isRequired,
|
||||||
info: PropTypes.shape({ label: PropTypes.string.isRequired }).isRequired,
|
|
||||||
layouts: PropTypes.shape({
|
layouts: PropTypes.shape({
|
||||||
list: PropTypes.array.isRequired,
|
list: PropTypes.array.isRequired,
|
||||||
editRelations: PropTypes.array,
|
editRelations: PropTypes.array,
|
||||||
|
@ -43,7 +43,6 @@ ListViewLayout.propTypes = {
|
|||||||
contentType: PropTypes.shape({
|
contentType: PropTypes.shape({
|
||||||
attributes: PropTypes.object.isRequired,
|
attributes: PropTypes.object.isRequired,
|
||||||
metadatas: PropTypes.object.isRequired,
|
metadatas: PropTypes.object.isRequired,
|
||||||
info: PropTypes.shape({ label: PropTypes.string.isRequired }).isRequired,
|
|
||||||
layouts: PropTypes.shape({
|
layouts: PropTypes.shape({
|
||||||
list: PropTypes.array.isRequired,
|
list: PropTypes.array.isRequired,
|
||||||
editRelations: PropTypes.array,
|
editRelations: PropTypes.array,
|
||||||
|
@ -13,8 +13,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@sindresorhus/slugify": "1.1.0",
|
"@sindresorhus/slugify": "1.1.0",
|
||||||
"@strapi/utils": "3.6.8",
|
"@strapi/utils": "3.6.8",
|
||||||
"lodash": "4.17.21",
|
"lodash": "4.17.21"
|
||||||
"pluralize": "^8.0.0"
|
|
||||||
},
|
},
|
||||||
"author": {
|
"author": {
|
||||||
"name": "Strapi team",
|
"name": "Strapi team",
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const { upperFirst, prop, pick, getOr } = require('lodash/fp');
|
const { pick, getOr } = require('lodash/fp');
|
||||||
const pluralize = require('pluralize');
|
|
||||||
const { contentTypes: contentTypesUtils } = require('@strapi/utils');
|
const { contentTypes: contentTypesUtils } = require('@strapi/utils');
|
||||||
|
|
||||||
const dtoFields = [
|
const dtoFields = [
|
||||||
@ -21,16 +20,8 @@ module.exports = () => ({
|
|||||||
toContentManagerModel(contentType) {
|
toContentManagerModel(contentType) {
|
||||||
return {
|
return {
|
||||||
...contentType,
|
...contentType,
|
||||||
options: {
|
|
||||||
...contentType.options,
|
|
||||||
timestamps: [],
|
|
||||||
},
|
|
||||||
apiID: contentType.modelName,
|
apiID: contentType.modelName,
|
||||||
isDisplayed: isVisible(contentType),
|
isDisplayed: isVisible(contentType),
|
||||||
info: {
|
|
||||||
...contentType.info,
|
|
||||||
label: formatContentTypeLabel(contentType),
|
|
||||||
},
|
|
||||||
attributes: {
|
attributes: {
|
||||||
id: {
|
id: {
|
||||||
type: 'integer',
|
type: 'integer',
|
||||||
@ -43,24 +34,13 @@ module.exports = () => ({
|
|||||||
toDto: pick(dtoFields),
|
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 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
|
// only get attributes that can be seen in the auto generated Edit view or List view
|
||||||
return getVisibleAttributes(contentType).reduce((acc, key) => {
|
return getVisibleAttributes(contentType)
|
||||||
|
.concat(getTimestamps(contentType))
|
||||||
|
.reduce((acc, key) => {
|
||||||
const attribute = contentType.attributes[key];
|
const attribute = contentType.attributes[key];
|
||||||
|
|
||||||
// ignore morph until they are handled in the front
|
// ignore morph until they are handled in the front
|
||||||
|
@ -98,12 +98,12 @@ const isTimestamp = (schema, name) => {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const timestampsOpt = _.get(schema, ['options', 'timestamps']);
|
const timestamps = contentTypesUtils.getTimestamps(schema);
|
||||||
if (!timestampsOpt || !Array.isArray(timestampsOpt)) {
|
if (!timestamps || !Array.isArray(timestamps)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (timestampsOpt.includes(name)) {
|
if (timestamps.includes(name)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -56,36 +56,6 @@ describe('Content Manager End to End', () => {
|
|||||||
await builder.cleanup();
|
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', () => {
|
describe('Test manyToMany relation (article - tag) with Content Manager', () => {
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
data = {
|
data = {
|
||||||
|
@ -35,24 +35,6 @@ describe('Content Manager single types', () => {
|
|||||||
await builder.cleanup();
|
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 () => {
|
test('find single type content returns 404 when not created', async () => {
|
||||||
const res = await rq({
|
const res = await rq({
|
||||||
url: `/content-manager/single-types/${uid}`,
|
url: `/content-manager/single-types/${uid}`,
|
||||||
|
@ -59,6 +59,12 @@ describe('Content types utils', () => {
|
|||||||
type: 'string',
|
type: 'string',
|
||||||
writable: false,
|
writable: false,
|
||||||
},
|
},
|
||||||
|
createdAt: {
|
||||||
|
type: 'datetime',
|
||||||
|
},
|
||||||
|
updatedAt: {
|
||||||
|
type: 'datetime',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
|
const { has } = require('lodash/fp');
|
||||||
|
|
||||||
const SINGLE_TYPE = 'singleType';
|
const SINGLE_TYPE = 'singleType';
|
||||||
const COLLECTION_TYPE = 'collectionType';
|
const COLLECTION_TYPE = 'collectionType';
|
||||||
@ -31,8 +32,18 @@ const constants = {
|
|||||||
COLLECTION_TYPE,
|
COLLECTION_TYPE,
|
||||||
};
|
};
|
||||||
|
|
||||||
const getTimestamps = () => {
|
const getTimestamps = model => {
|
||||||
return [CREATED_AT_ATTRIBUTE, UPDATED_AT_ATTRIBUTE];
|
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 = {}) => {
|
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 = {}) => {
|
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 => {
|
const getVisibleAttributes = model => {
|
||||||
@ -137,6 +148,7 @@ module.exports = {
|
|||||||
isWritableAttribute,
|
isWritableAttribute,
|
||||||
getNonVisibleAttributes,
|
getNonVisibleAttributes,
|
||||||
getVisibleAttributes,
|
getVisibleAttributes,
|
||||||
|
getTimestamps,
|
||||||
isVisibleAttribute,
|
isVisibleAttribute,
|
||||||
hasDraftAndPublish,
|
hasDraftAndPublish,
|
||||||
isDraft,
|
isDraft,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user