diff --git a/packages/strapi-plugin-content-manager/admin/src/containers/EditPage/saga.js b/packages/strapi-plugin-content-manager/admin/src/containers/EditPage/saga.js index 0e4e23aea8..a1d019144b 100644 --- a/packages/strapi-plugin-content-manager/admin/src/containers/EditPage/saga.js +++ b/packages/strapi-plugin-content-manager/admin/src/containers/EditPage/saga.js @@ -42,19 +42,6 @@ function* dataGet(action) { ]; const pluginHeaderTitle = yield call(templateObject, { mainField: action.mainField }, response); - // Remove the updated_at & created_at fields so it is updated correctly when using Postgres or MySQL db - if (response.updated_at) { - delete response.created_at; - delete response.updated_at; - } - - // Remove the updatedAt & createdAt fields so it is updated correctly when using MongoDB - if (response.updatedAt) { - delete response.createdAt; - delete response.updatedAt; - - } - yield put(getDataSucceeded(action.id, response, pluginHeaderTitle.mainField)); } catch(err) { strapi.notification.error('content-manager.error.record.fetch'); @@ -69,6 +56,17 @@ export function* submit() { const source = yield select(makeSelectSource()); const schema = yield select(makeSelectSchema()); let shouldAddTranslationSuffix = false; + // Remove the updated_at & created_at fields so it is updated correctly when using Postgres or MySQL db + if (record.updated_at) { + delete record.created_at; + delete record.updated_at; + } + + // Remove the updatedAt & createdAt fields so it is updated correctly when using MongoDB + if (record.updatedAt) { + delete record.createdAt; + delete record.updatedAt; + } try { // Show button loader diff --git a/packages/strapi-plugin-content-manager/config/functions/bootstrap.js b/packages/strapi-plugin-content-manager/config/functions/bootstrap.js index 8f119a1eb6..f266aa2ad4 100644 --- a/packages/strapi-plugin-content-manager/config/functions/bootstrap.js +++ b/packages/strapi-plugin-content-manager/config/functions/bootstrap.js @@ -91,6 +91,18 @@ module.exports = async cb => { disabled: false, }; }); + + if (model.orm === 'mongoose') { + fields.createdAt = { label: 'createdAt', description: '', type: 'date', disabled: true }; + fields.updatedAt = { label: 'updatedAt', description: '', type: 'date', disabled: true }; + schemaModel.attributes.updatedAt = { type: 'date' }; + schemaModel.attributes.createdAt = { type: 'date' }; + } else { + fields.created_at = { label: 'created_at', description: '', type: 'date', disabled: true }; + fields.updated_at = { label: 'updated_at', description: '', type: 'date', disabled: true }; + schemaModel.attributes.created_at = { type: 'date' }; + schemaModel.attributes.updated_at = { type: 'date' }; + } // Don't display fields that are hidden by default like the resetPasswordToken for the model user fieldsToRemove.forEach(field => { @@ -104,7 +116,6 @@ module.exports = async cb => { // Select fields displayed in list view schemaModel.listDisplay = Object.keys(schemaModel.fields) // Construct Array of attr ex { type: 'string', label: 'Foo', name: 'Foo', description: '' } - // NOTE: Do we allow sort on boolean? .map(attr => { const attrType = schemaModel.fields[attr].type; const sortable = attrType !== 'json' && attrType !== 'array'; @@ -125,11 +136,10 @@ module.exports = async cb => { // This object will be used to customise the label and description and so on of an input. // TODO: maybe add the customBootstrapClass in it; schemaModel.editDisplay.availableFields = Object.keys(schemaModel.fields).reduce((acc, current) => { - // TODO: Add appearance in this object in order to get rid of the layout.json acc[current] = Object.assign( _.pick(_.get(schemaModel, ['fields', current], {}), ['label', 'type', 'description', 'name']), { - editable: true, + editable: ['updatedAt', 'createdAt', 'updated_at', 'created_at'].indexOf(current) === -1, placeholder: '', });