fix: preserve unknown fields value (#3314)
This commit is contained in:
parent
dd94a8426e
commit
908c42fb58
@ -203,7 +203,7 @@ describe('Editor', () => {
|
|||||||
<Editor
|
<Editor
|
||||||
{...props}
|
{...props}
|
||||||
entryDraft={fromJS({ entry: { mediaFiles: [{ id: '1' }] } })}
|
entryDraft={fromJS({ entry: { mediaFiles: [{ id: '1' }] } })}
|
||||||
entry={fromJS({ isFetching: false })}
|
entry={fromJS({ isFetching: false, data: {} })}
|
||||||
hasChanged={true}
|
hasChanged={true}
|
||||||
/>,
|
/>,
|
||||||
);
|
);
|
||||||
@ -232,7 +232,7 @@ describe('Editor', () => {
|
|||||||
entry: {},
|
entry: {},
|
||||||
fieldsMetaData: {},
|
fieldsMetaData: {},
|
||||||
})}
|
})}
|
||||||
entry={fromJS({ isFetching: false, mediaFiles: [{ id: '1' }] })}
|
entry={fromJS({ isFetching: false, mediaFiles: [{ id: '1' }], data: {} })}
|
||||||
/>,
|
/>,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1,12 +1,7 @@
|
|||||||
export const sortKeys = (sortedKeys = []) => (a, b) => {
|
export const sortKeys = (sortedKeys = []) => (a, b) => {
|
||||||
const idxA = sortedKeys.indexOf(a);
|
const idxA = sortedKeys.indexOf(a);
|
||||||
const idxB = sortedKeys.indexOf(b);
|
const idxB = sortedKeys.indexOf(b);
|
||||||
if (idxA === -1 || idxB === -1) {
|
if (idxA === -1 || idxB === -1) return 0;
|
||||||
if (a > b) return 1;
|
|
||||||
if (a < b) return -1;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (idxA > idxB) return 1;
|
if (idxA > idxB) return 1;
|
||||||
if (idxA < idxB) return -1;
|
if (idxA < idxB) return -1;
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -0,0 +1,21 @@
|
|||||||
|
import { serializeValues, deserializeValues } from '../serializeEntryValues';
|
||||||
|
import { fromJS } from 'immutable';
|
||||||
|
|
||||||
|
const values = fromJS({ title: 'New Post', unknown: 'Unknown Field' });
|
||||||
|
const fields = fromJS([{ name: 'title', widget: 'string' }]);
|
||||||
|
|
||||||
|
describe('serializeValues', () => {
|
||||||
|
it('should retain unknown fields', () => {
|
||||||
|
expect(serializeValues(values, fields)).toEqual(
|
||||||
|
fromJS({ title: 'New Post', unknown: 'Unknown Field' }),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('deserializeValues', () => {
|
||||||
|
it('should retain unknown fields', () => {
|
||||||
|
expect(deserializeValues(values, fields)).toEqual(
|
||||||
|
fromJS({ title: 'New Post', unknown: 'Unknown Field' }),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
@ -27,7 +27,7 @@ const runSerializer = (values, fields, method) => {
|
|||||||
* registered serializers. If the field is a list or object, call recursively
|
* registered serializers. If the field is a list or object, call recursively
|
||||||
* for nested fields.
|
* for nested fields.
|
||||||
*/
|
*/
|
||||||
return fields.reduce((acc, field) => {
|
let serializedData = fields.reduce((acc, field) => {
|
||||||
const fieldName = field.get('name');
|
const fieldName = field.get('name');
|
||||||
const value = values.get(fieldName);
|
const value = values.get(fieldName);
|
||||||
const serializer = getWidgetValueSerializer(field.get('widget'));
|
const serializer = getWidgetValueSerializer(field.get('widget'));
|
||||||
@ -58,6 +58,11 @@ const runSerializer = (values, fields, method) => {
|
|||||||
|
|
||||||
return acc;
|
return acc;
|
||||||
}, Map());
|
}, Map());
|
||||||
|
|
||||||
|
//preserve unknown fields value
|
||||||
|
serializedData = values.mergeDeep(serializedData);
|
||||||
|
|
||||||
|
return serializedData;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const serializeValues = (values, fields) => {
|
export const serializeValues = (values, fields) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user