diff --git a/examples/getstarted/src/api/restaurant/content-types/restaurant/schema.json b/examples/getstarted/src/api/restaurant/content-types/restaurant/schema.json index 5658d6b517..7692e2b7c7 100755 --- a/examples/getstarted/src/api/restaurant/content-types/restaurant/schema.json +++ b/examples/getstarted/src/api/restaurant/content-types/restaurant/schema.json @@ -56,7 +56,9 @@ "i18n": { "localized": true } - } + }, + "repeatable": false, + "required": true }, "contactEmail": { "type": "email", diff --git a/examples/getstarted/src/api/temp/content-types/temp/schema.json b/examples/getstarted/src/api/temp/content-types/temp/schema.json index ec7c36aea2..bf35488ac2 100644 --- a/examples/getstarted/src/api/temp/content-types/temp/schema.json +++ b/examples/getstarted/src/api/temp/content-types/temp/schema.json @@ -11,91 +11,41 @@ "options": { "draftAndPublish": false }, - "pluginOptions": { - "i18n": { - "localized": true - } - }, + "pluginOptions": {}, "attributes": { "name": { "type": "string", - "pluginOptions": { - "i18n": { - "localized": true - } - } + "pluginOptions": {} }, - "temp": { - "type": "component", - "repeatable": true, - "component": "default.temp", - "pluginOptions": { - "i18n": { - "localized": true - } - } + "simple": { + "pluginOptions": {}, + "type": "uid" }, - "dz": { - "pluginOptions": { - "i18n": { - "localized": true - } - }, - "type": "dynamiczone", - "components": [ - "basic.simple", - "blog.test-como", - "default.closingperiod", - "default.dish", - "default.openingtimes", - "default.restaurantservice", - "default.temp", - "default.apple", - "default.car" - ], - "required": true, - "min": 2 + "attached": { + "pluginOptions": {}, + "type": "uid", + "targetField": "name" }, - "dz_req": { - "type": "dynamiczone", - "components": [ - "default.apple", - "default.car", - "default.closingperiod", - "default.dish", - "default.openingtimes", - "default.restaurantservice", - "default.temp" - ], - "required": true, - "pluginOptions": { - "i18n": { - "localized": true - } - } + "attached_req": { + "pluginOptions": {}, + "type": "uid", + "targetField": "name", + "required": true }, - "dz_simple": { - "type": "dynamiczone", - "components": [ - "basic.simple" - ], - "pluginOptions": { - "i18n": { - "localized": true - } - } + "req": { + "pluginOptions": {}, + "type": "uid", + "required": true }, - "dz_max": { - "type": "dynamiczone", - "components": [ - "basic.simple" - ], - "max": 2, - "pluginOptions": { - "i18n": { - "localized": true - } - } + "default_val": { + "pluginOptions": {}, + "type": "uid", + "default": "to", + "minLength": 4 + }, + "date": { + "type": "date", + "required": true } } } diff --git a/examples/getstarted/src/components/default/closingperiod.json b/examples/getstarted/src/components/default/closingperiod.json index 55889fab9e..40c69c850c 100644 --- a/examples/getstarted/src/components/default/closingperiod.json +++ b/examples/getstarted/src/components/default/closingperiod.json @@ -7,7 +7,8 @@ }, "attributes": { "label": { - "type": "string" + "type": "string", + "default": "toto" }, "start_date": { "type": "date", @@ -19,11 +20,15 @@ }, "media": { "type": "media", + "multiple": false, "required": false }, "dish": { "component": "default.dish", - "type": "component" + "type": "component", + "repeatable": true, + "required": true, + "min": 2 } } } diff --git a/packages/core/admin/admin/src/content-manager/components/EditViewDataManagerProvider/utils/cleanData.js b/packages/core/admin/admin/src/content-manager/components/EditViewDataManagerProvider/utils/cleanData.js index da8b24aeb9..694b17beb6 100644 --- a/packages/core/admin/admin/src/content-manager/components/EditViewDataManagerProvider/utils/cleanData.js +++ b/packages/core/admin/admin/src/content-manager/components/EditViewDataManagerProvider/utils/cleanData.js @@ -36,6 +36,7 @@ const cleanData = (retrievedData, currentSchema, componentsSchema) => { case 'time': { cleanedData = value; + // FIXME if (value && value.split(':').length < 3) { cleanedData = `${value}:00`; } diff --git a/packages/core/admin/admin/src/content-manager/components/EditViewDataManagerProvider/utils/schema.js b/packages/core/admin/admin/src/content-manager/components/EditViewDataManagerProvider/utils/schema.js index 38eed57f8a..c8295d0456 100644 --- a/packages/core/admin/admin/src/content-manager/components/EditViewDataManagerProvider/utils/schema.js +++ b/packages/core/admin/admin/src/content-manager/components/EditViewDataManagerProvider/utils/schema.js @@ -9,7 +9,7 @@ import { isNaN, toNumber, } from 'lodash'; -import moment from 'moment'; + import * as yup from 'yup'; import { translatedErrors as errorsTrads } from '@strapi/helper-plugin'; @@ -291,10 +291,6 @@ const createYupSchemaAttribute = (type, validations, options) => { return !!value; } - if (['date', 'datetime'].includes(type)) { - return moment(value)._isValid === true; - } - if (type === 'boolean') { return value !== null; } diff --git a/packages/core/admin/admin/src/content-manager/components/InputUID/index.js b/packages/core/admin/admin/src/content-manager/components/InputUID/index.js index eb6c3e2b9e..c4d338c7e0 100644 --- a/packages/core/admin/admin/src/content-manager/components/InputUID/index.js +++ b/packages/core/admin/admin/src/content-manager/components/InputUID/index.js @@ -1,4 +1,4 @@ -import React, { useEffect, useState, useRef } from 'react'; +import React, { useEffect, useState, useRef, memo } from 'react'; import PropTypes from 'prop-types'; import { useCMEditViewDataManager } from '@strapi/helper-plugin'; import { useIntl } from 'react-intl'; @@ -7,42 +7,49 @@ import { axiosInstance } from '../../../core/utils'; import { getRequestUrl, getTrad } from '../../utils'; import UID_REGEX from './regex'; import { TextInput } from '@strapi/parts/TextInput'; -import { Text } from '@strapi/parts/Text'; +import { Text } from '@strapi/parts/Text'; import Reload from '@strapi/icons/Reload'; import AlertSucessIcon from '@strapi/icons/AlertSucessIcon'; import AlertWarningIcon from '@strapi/icons/AlertWarningIcon'; import LoadingIcon from '@strapi/icons/LoadingIcon'; import useDebounce from './useDebounce'; -import { EndActionWrapper, FieldActionWrapper, TextValidation, LoadingWrapper } from './endActionStyle'; +import { + EndActionWrapper, + FieldActionWrapper, + TextValidation, + LoadingWrapper, +} from './endActionStyle'; // { - - // attribute, - // contentTypeUID, - // description, - // error: inputError, - // label: inputLabel, - // labelIcon, - // name, - // onChange, - // validations, - // value, - // editable, - // ...inputProps + +// attribute, +// contentTypeUID, +// description, +// error: inputError, +// label: inputLabel, +// labelIcon, +// name, +// onChange, +// validations, +// value, +// editable, +// ...inputProps // } -const InputUID = ({ - attribute, - contentTypeUID, - description, - disabled, - error, - intlLabel, - labelAction, - name, - onChange, - value, - ...rest -}) => { +const InputUID = props => { + const { + attribute, + contentTypeUID, + description, + disabled, + error, + intlLabel, + labelAction, + name, + onChange, + value, + ...rest + } = props; + const { modifiedData, initialData, layout } = useCMEditViewDataManager(); const [isLoading, setIsLoading] = useState(false); const [availability, setAvailability] = useState(null); @@ -57,11 +64,11 @@ const InputUID = ({ const [regenerateLabel, setRegenerateLabel] = useState(null); const label = intlLabel.id - ? formatMessage( - { id: intlLabel.id, defaultMessage: intlLabel.defaultMessage }, - { ...intlLabel.values } - ) - : name; + ? formatMessage( + { id: intlLabel.id, defaultMessage: intlLabel.defaultMessage }, + { ...intlLabel.values } + ) + : name; generateUid.current = async (shouldSetInitialValue = false) => { setIsLoading(true); @@ -172,36 +179,42 @@ const InputUID = ({ onChange(e); }; - + return ( - - {availability && availability.isAvailable && !regenerateLabel && - + {availability && availability.isAvailable && !regenerateLabel && ( + - Available - - } - {availability && !availability.isAvailable && !regenerateLabel && - + + Available + + + )} + {availability && !availability.isAvailable && !regenerateLabel && ( + - Unavailable - - } - {regenerateLabel && - - {regenerateLabel} - - } - generateUid.current()} - label='regenerate' + + Unavailable + + + )} + {regenerateLabel && ( + + + {regenerateLabel} + + + )} + generateUid.current()} + label="regenerate" onMouseEnter={handleGenerateMouseEnter} onMouseLeave={handleGenerateMouseLeave} > @@ -209,9 +222,9 @@ const InputUID = ({ - ) : + ) : ( - } + )} } @@ -323,4 +336,5 @@ const InputUID = ({ // value: '', // }; +// export default memo(InputUID, isEqual); export default InputUID; diff --git a/packages/core/admin/admin/src/content-manager/components/Inputs/index.js b/packages/core/admin/admin/src/content-manager/components/Inputs/index.js index 7ab89b7bdc..09ad281894 100644 --- a/packages/core/admin/admin/src/content-manager/components/Inputs/index.js +++ b/packages/core/admin/admin/src/content-manager/components/Inputs/index.js @@ -15,7 +15,6 @@ import InputJSON from '../InputJSON'; import GenericInput from './GenericInput'; import InputUID from '../InputUID'; // import SelectWrapper from '../SelectWrapper'; -// import WysiwygWithErrors from '../WysiwygWithErrors'; import { connect, @@ -54,7 +53,7 @@ function Inputs({ const fieldName = useMemo(() => { return getFieldName(keys); }, [keys]); - + const validations = useMemo(() => { const inputValidations = omit( fieldSchema, @@ -204,7 +203,7 @@ function Inputs({ // // ); } - + return (