mirror of
https://github.com/strapi/strapi.git
synced 2026-01-06 04:03:25 +00:00
Remove useless files
This commit is contained in:
parent
cb93b4d30b
commit
f026c87f75
@ -29,7 +29,6 @@ export const cleanData = (retrievedData, ctLayout, groupLayouts) => {
|
||||
break;
|
||||
case 'media':
|
||||
if (getOtherInfos(layout.schema, [current, 'multiple']) === true) {
|
||||
// const valueWithoutFile =
|
||||
cleanedData = value
|
||||
? helperCleanData(
|
||||
value.filter(file => !(file instanceof File)),
|
||||
|
||||
@ -1,15 +0,0 @@
|
||||
import { isPlainObject, isFunction } from 'lodash';
|
||||
|
||||
export const bindLayout = function (object) {
|
||||
return Object.keys(object).reduce((acc, current) => {
|
||||
if (isPlainObject(object[current])) {
|
||||
acc[current] = bindLayout.call(this, object[current]);
|
||||
} else if (isFunction(object[current])) {
|
||||
acc[current] = object[current].bind(this);
|
||||
} else {
|
||||
acc[current] = object[current];
|
||||
}
|
||||
|
||||
return acc;
|
||||
}, {});
|
||||
};
|
||||
@ -1,130 +0,0 @@
|
||||
import {
|
||||
findIndex,
|
||||
forEach,
|
||||
includes,
|
||||
isArray,
|
||||
isBoolean,
|
||||
isEmpty,
|
||||
isNaN,
|
||||
isNull,
|
||||
isNumber,
|
||||
isObject,
|
||||
isUndefined,
|
||||
map,
|
||||
mapKeys,
|
||||
reject,
|
||||
} from 'lodash';
|
||||
|
||||
/* eslint-disable consistent-return */
|
||||
export function getValidationsFromForm(form, formValidations) {
|
||||
map(form, (value, key) => {
|
||||
// Check if the object
|
||||
if (isObject(value) && !isArray(value)) {
|
||||
forEach(value, subValue => {
|
||||
// Check if it has nestedInputs
|
||||
if (isArray(subValue) && value.type !== 'select') {
|
||||
return getValidationsFromForm(subValue, formValidations);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (isArray(value) && value.type !== 'select') {
|
||||
return getValidationsFromForm(form[key], formValidations);
|
||||
}
|
||||
|
||||
// Push the target and the validation
|
||||
if (value.name) {
|
||||
formValidations.push({
|
||||
name: value.name,
|
||||
validations: value.validations,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return formValidations;
|
||||
}
|
||||
|
||||
export function checkFormValidity(formData, formValidations) {
|
||||
const errors = [];
|
||||
|
||||
forEach(formData, (value, key) => {
|
||||
const validationValue =
|
||||
formValidations[findIndex(formValidations, ['name', key])];
|
||||
|
||||
if (!isUndefined(validationValue)) {
|
||||
const inputErrors = validate(value, validationValue.validations);
|
||||
|
||||
if (!isEmpty(inputErrors)) {
|
||||
errors.push({ name: key, errors: inputErrors });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return errors;
|
||||
}
|
||||
|
||||
function validate(value, validations) {
|
||||
let errors = [];
|
||||
// Handle i18n
|
||||
const requiredError = { id: 'content-manager.error.validation.required' };
|
||||
mapKeys(validations, (validationValue, validationKey) => {
|
||||
switch (validationKey) {
|
||||
case 'max':
|
||||
if (parseInt(value, 10) > validationValue) {
|
||||
errors.push({ id: 'content-manager.error.validation.max' });
|
||||
}
|
||||
break;
|
||||
case 'min':
|
||||
if (parseInt(value, 10) < validationValue) {
|
||||
errors.push({ id: 'content-manager.error.validation.min' });
|
||||
}
|
||||
break;
|
||||
case 'maxLength':
|
||||
if (value && value.length > validationValue) {
|
||||
errors.push({ id: 'content-manager.error.validation.maxLength' });
|
||||
}
|
||||
break;
|
||||
case 'minLength':
|
||||
if (value && value.length < validationValue) {
|
||||
errors.push({ id: 'content-manager.error.validation.minLength' });
|
||||
}
|
||||
break;
|
||||
case 'required':
|
||||
if (validationValue === true && value.length === 0) {
|
||||
errors.push({ id: 'content-manager.error.validation.required' });
|
||||
}
|
||||
break;
|
||||
case 'regex':
|
||||
if (!new RegExp(validationValue).test(value)) {
|
||||
errors.push({ id: 'content-manager.error.validation.regex' });
|
||||
}
|
||||
break;
|
||||
case 'type':
|
||||
if (validationValue === 'json') {
|
||||
try {
|
||||
if (
|
||||
isObject(value) ||
|
||||
isBoolean(value) ||
|
||||
isNumber(value) ||
|
||||
isArray(value) ||
|
||||
isNaN(value) ||
|
||||
isNull(value)
|
||||
) {
|
||||
value = JSON.parse(JSON.stringify(value));
|
||||
} else {
|
||||
errors.push({ id: 'content-manager.error.validation.json' });
|
||||
}
|
||||
} catch (err) {
|
||||
errors.push({ id: 'content-manager.error.validation.json' });
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
}
|
||||
});
|
||||
|
||||
if (includes(errors, requiredError)) {
|
||||
errors = reject(errors, error => error !== requiredError);
|
||||
}
|
||||
return errors;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user