implements a safer way to revert to original data if update policies fail

This commit is contained in:
James
2020-07-02 00:46:03 -04:00
parent d04babe933
commit a34698371e
8 changed files with 31 additions and 28 deletions

View File

@@ -1,10 +0,0 @@
const flattenFilters = [{
test: (_, value) => {
const hasValidProperty = Object.prototype.hasOwnProperty.call(value, 'valid');
const hasValueProperty = Object.prototype.hasOwnProperty.call(value, 'value');
return (hasValidProperty && hasValueProperty);
},
}];
export default flattenFilters;

View File

@@ -254,6 +254,9 @@ const Form = (props) => {
contextValue.validateForm = () => {
return !Object.values(fields).some((field) => {
if (field.valid === false) {
console.log(field, ' is not valid');
}
return field.valid === false;
});
};

View File

@@ -8,7 +8,7 @@ import { v4 as uuidv4 } from 'uuid';
import withCondition from '../../withCondition';
import Button from '../../../elements/Button';
import reducer from '../rowReducer';
import useForm from '../../Form/useForm';
import useFormFields from '../../Form/useFormFields';
import DraggableSection from '../../DraggableSection';
import { useRenderedFields } from '../../RenderFields';
import Error from '../../Error';
@@ -67,7 +67,7 @@ const Flexible = (props) => {
const dataToInitialize = initialData || defaultValue;
const [rows, dispatchRows] = useReducer(reducer, []);
const { customComponentsPath } = useRenderedFields();
const { getDataByPath } = useForm();
const { getDataByPath } = useFormFields();
const addRow = (index, blockType) => {
const data = getDataByPath(path);

View File

@@ -8,7 +8,7 @@ import Button from '../../../elements/Button';
import DraggableSection from '../../DraggableSection';
import reducer from '../rowReducer';
import { useRenderedFields } from '../../RenderFields';
import useForm from '../../Form/useForm';
import useFormFields from '../../Form/useFormFields';
import useFieldType from '../../useFieldType';
import Error from '../../Error';
import { repeater } from '../../../../../fields/validations';
@@ -39,7 +39,7 @@ const Repeater = (props) => {
const dataToInitialize = initialData || defaultValue;
const [rows, dispatchRows] = useReducer(reducer, []);
const { customComponentsPath } = useRenderedFields();
const { getDataByPath } = useForm();
const { getDataByPath } = useFormFields();
const path = pathFromProps || name;

View File

@@ -46,7 +46,7 @@ const Upload = (props) => {
const fieldType = useFieldType({
path,
required,
initialData,
initialData: initialData?.id,
defaultValue,
validate,
});
@@ -166,7 +166,9 @@ Upload.propTypes = {
required: PropTypes.bool,
readOnly: PropTypes.bool,
defaultValue: PropTypes.string,
initialData: PropTypes.shape({}),
initialData: PropTypes.shape({
id: PropTypes.string,
}),
validate: PropTypes.func,
width: PropTypes.string,
style: PropTypes.shape({}),