mirror of
https://github.com/strapi/strapi.git
synced 2025-11-02 02:44:55 +00:00
Merge pull request #17155 from strapi/chore/remove-step-from-time
This commit is contained in:
commit
d2d5476f07
@ -75,20 +75,9 @@ function Inputs({
|
||||
return foundAttributeType === 'dynamiczone';
|
||||
}, [currentContentTypeLayout, fieldName]);
|
||||
|
||||
const inputType = useMemo(() => {
|
||||
return getInputType(type);
|
||||
}, [type]);
|
||||
const inputType = getInputType(type);
|
||||
|
||||
const inputValue = useMemo(() => {
|
||||
// Fix for input file multipe
|
||||
if (type === 'media' && !value) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return value;
|
||||
}, [type, value]);
|
||||
|
||||
const step = getStep(type);
|
||||
const inputValue = type === 'media' && !value ? [] : value;
|
||||
|
||||
const isUserAllowedToEditField = useMemo(() => {
|
||||
const joinedName = fieldName.join('.');
|
||||
@ -159,36 +148,6 @@ function Inputs({
|
||||
|
||||
const { label, description, placeholder, visible } = metadatas;
|
||||
|
||||
/**
|
||||
* It decides whether using the default `step` accoding to its `inputType` or the one
|
||||
* obtained from `metadatas`.
|
||||
*
|
||||
* The `metadatas.step` is returned when the `inputValue` is divisible by it or when the
|
||||
* `inputValue` is empty, otherwise the default `step` is returned.
|
||||
*/
|
||||
const inputStep = useMemo(() => {
|
||||
if (!metadatas.step || (inputType !== 'datetime' && inputType !== 'time')) {
|
||||
return step;
|
||||
}
|
||||
|
||||
if (!inputValue) {
|
||||
return metadatas.step;
|
||||
}
|
||||
|
||||
let minutes;
|
||||
|
||||
/**
|
||||
* Wtf is this?
|
||||
*/
|
||||
if (inputType === 'datetime') {
|
||||
minutes = parseInt(inputValue.substr(14, 2), 10);
|
||||
} else if (inputType === 'time') {
|
||||
minutes = parseInt(inputValue.slice(-2), 10);
|
||||
}
|
||||
|
||||
return minutes % metadatas.step === 0 ? metadatas.step : step;
|
||||
}, [inputType, inputValue, metadatas.step, step]);
|
||||
|
||||
if (visible === false) {
|
||||
return null;
|
||||
}
|
||||
@ -271,7 +230,7 @@ function Inputs({
|
||||
options={options}
|
||||
placeholder={placeholder ? { id: placeholder, defaultMessage: placeholder } : null}
|
||||
required={fieldSchema.required || false}
|
||||
step={inputStep}
|
||||
step={getStep(type)}
|
||||
type={customFieldUid || inputType}
|
||||
// validations={validations}
|
||||
value={inputValue}
|
||||
@ -317,9 +276,6 @@ const getStep = (type) => {
|
||||
case 'float':
|
||||
case 'decimal':
|
||||
return 0.01;
|
||||
case 'time':
|
||||
case 'datetime':
|
||||
return 15;
|
||||
default:
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -20,10 +20,6 @@ const FIELD_SIZES = [
|
||||
[12, '100%'],
|
||||
];
|
||||
|
||||
const TIME_FIELD_OPTIONS = [1, 5, 10, 15, 30, 60];
|
||||
|
||||
const TIME_FIELD_TYPES = ['datetime', 'time'];
|
||||
|
||||
const ModalForm = ({ onMetaChange, onSizeChange }) => {
|
||||
const { formatMessage } = useIntl();
|
||||
const { modifiedData, selectedField, attributes, fieldForm } = useLayoutDnd();
|
||||
@ -131,33 +127,10 @@ const ModalForm = ({ onMetaChange, onSizeChange }) => {
|
||||
</GridItem>
|
||||
);
|
||||
|
||||
const hasTimePicker = TIME_FIELD_TYPES.includes(attributes[selectedField].type);
|
||||
|
||||
const timeStepField = (
|
||||
<GridItem col={6} key="step">
|
||||
<Select
|
||||
value={get(fieldForm, ['metadata', 'step'], 1)}
|
||||
name="step"
|
||||
onChange={(value) => onMetaChange({ target: { name: 'step', value } })}
|
||||
label={formatMessage({
|
||||
id: getTrad('containers.SettingPage.editSettings.step.label'),
|
||||
defaultMessage: 'Time interval (minutes)',
|
||||
})}
|
||||
>
|
||||
{TIME_FIELD_OPTIONS.map((value) => (
|
||||
<Option key={value} value={value}>
|
||||
{value}
|
||||
</Option>
|
||||
))}
|
||||
</Select>
|
||||
</GridItem>
|
||||
);
|
||||
|
||||
return (
|
||||
<>
|
||||
{metaFields}
|
||||
{isResizable && sizeField}
|
||||
{hasTimePicker && timeStepField}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
@ -71,15 +71,6 @@ const createMetadasSchema = (schema) => {
|
||||
|
||||
return yup.string().oneOf(validAttributes.concat('id')).default('id');
|
||||
}),
|
||||
step: yup
|
||||
.number()
|
||||
.integer()
|
||||
.positive()
|
||||
.test(
|
||||
'isDivisibleBy60',
|
||||
'Step must be either 1 or divisible by 60',
|
||||
(value) => !value || value === 1 || (value * 24) % 60 === 0
|
||||
),
|
||||
})
|
||||
.noUnknown()
|
||||
.required(),
|
||||
|
||||
@ -231,7 +231,6 @@ const GenericInput = ({
|
||||
|
||||
onChange({ target: { name, value: formattedDate, type } });
|
||||
}}
|
||||
step={step}
|
||||
onClear={() => onChange({ target: { name, value: null, type } })}
|
||||
placeholder={formattedPlaceholder}
|
||||
required={required}
|
||||
@ -434,7 +433,6 @@ const GenericInput = ({
|
||||
}}
|
||||
placeholder={formattedPlaceholder}
|
||||
required={required}
|
||||
step={step}
|
||||
value={time}
|
||||
/>
|
||||
);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user