mirror of
https://github.com/strapi/strapi.git
synced 2025-11-02 19:04:38 +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';
|
return foundAttributeType === 'dynamiczone';
|
||||||
}, [currentContentTypeLayout, fieldName]);
|
}, [currentContentTypeLayout, fieldName]);
|
||||||
|
|
||||||
const inputType = useMemo(() => {
|
const inputType = getInputType(type);
|
||||||
return getInputType(type);
|
|
||||||
}, [type]);
|
|
||||||
|
|
||||||
const inputValue = useMemo(() => {
|
const inputValue = type === 'media' && !value ? [] : value;
|
||||||
// Fix for input file multipe
|
|
||||||
if (type === 'media' && !value) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}, [type, value]);
|
|
||||||
|
|
||||||
const step = getStep(type);
|
|
||||||
|
|
||||||
const isUserAllowedToEditField = useMemo(() => {
|
const isUserAllowedToEditField = useMemo(() => {
|
||||||
const joinedName = fieldName.join('.');
|
const joinedName = fieldName.join('.');
|
||||||
@ -159,36 +148,6 @@ function Inputs({
|
|||||||
|
|
||||||
const { label, description, placeholder, visible } = metadatas;
|
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) {
|
if (visible === false) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -271,7 +230,7 @@ function Inputs({
|
|||||||
options={options}
|
options={options}
|
||||||
placeholder={placeholder ? { id: placeholder, defaultMessage: placeholder } : null}
|
placeholder={placeholder ? { id: placeholder, defaultMessage: placeholder } : null}
|
||||||
required={fieldSchema.required || false}
|
required={fieldSchema.required || false}
|
||||||
step={inputStep}
|
step={getStep(type)}
|
||||||
type={customFieldUid || inputType}
|
type={customFieldUid || inputType}
|
||||||
// validations={validations}
|
// validations={validations}
|
||||||
value={inputValue}
|
value={inputValue}
|
||||||
@ -317,9 +276,6 @@ const getStep = (type) => {
|
|||||||
case 'float':
|
case 'float':
|
||||||
case 'decimal':
|
case 'decimal':
|
||||||
return 0.01;
|
return 0.01;
|
||||||
case 'time':
|
|
||||||
case 'datetime':
|
|
||||||
return 15;
|
|
||||||
default:
|
default:
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,10 +20,6 @@ const FIELD_SIZES = [
|
|||||||
[12, '100%'],
|
[12, '100%'],
|
||||||
];
|
];
|
||||||
|
|
||||||
const TIME_FIELD_OPTIONS = [1, 5, 10, 15, 30, 60];
|
|
||||||
|
|
||||||
const TIME_FIELD_TYPES = ['datetime', 'time'];
|
|
||||||
|
|
||||||
const ModalForm = ({ onMetaChange, onSizeChange }) => {
|
const ModalForm = ({ onMetaChange, onSizeChange }) => {
|
||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
const { modifiedData, selectedField, attributes, fieldForm } = useLayoutDnd();
|
const { modifiedData, selectedField, attributes, fieldForm } = useLayoutDnd();
|
||||||
@ -131,33 +127,10 @@ const ModalForm = ({ onMetaChange, onSizeChange }) => {
|
|||||||
</GridItem>
|
</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 (
|
return (
|
||||||
<>
|
<>
|
||||||
{metaFields}
|
{metaFields}
|
||||||
{isResizable && sizeField}
|
{isResizable && sizeField}
|
||||||
{hasTimePicker && timeStepField}
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -71,15 +71,6 @@ const createMetadasSchema = (schema) => {
|
|||||||
|
|
||||||
return yup.string().oneOf(validAttributes.concat('id')).default('id');
|
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()
|
.noUnknown()
|
||||||
.required(),
|
.required(),
|
||||||
|
|||||||
@ -231,7 +231,6 @@ const GenericInput = ({
|
|||||||
|
|
||||||
onChange({ target: { name, value: formattedDate, type } });
|
onChange({ target: { name, value: formattedDate, type } });
|
||||||
}}
|
}}
|
||||||
step={step}
|
|
||||||
onClear={() => onChange({ target: { name, value: null, type } })}
|
onClear={() => onChange({ target: { name, value: null, type } })}
|
||||||
placeholder={formattedPlaceholder}
|
placeholder={formattedPlaceholder}
|
||||||
required={required}
|
required={required}
|
||||||
@ -434,7 +433,6 @@ const GenericInput = ({
|
|||||||
}}
|
}}
|
||||||
placeholder={formattedPlaceholder}
|
placeholder={formattedPlaceholder}
|
||||||
required={required}
|
required={required}
|
||||||
step={step}
|
|
||||||
value={time}
|
value={time}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user