fix: preserve unknown fields value (#3314)
This commit is contained in:
parent
dd94a8426e
commit
908c42fb58
@ -203,7 +203,7 @@ describe('Editor', () => {
|
||||
<Editor
|
||||
{...props}
|
||||
entryDraft={fromJS({ entry: { mediaFiles: [{ id: '1' }] } })}
|
||||
entry={fromJS({ isFetching: false })}
|
||||
entry={fromJS({ isFetching: false, data: {} })}
|
||||
hasChanged={true}
|
||||
/>,
|
||||
);
|
||||
@ -232,7 +232,7 @@ describe('Editor', () => {
|
||||
entry: {},
|
||||
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) => {
|
||||
const idxA = sortedKeys.indexOf(a);
|
||||
const idxB = sortedKeys.indexOf(b);
|
||||
if (idxA === -1 || idxB === -1) {
|
||||
if (a > b) return 1;
|
||||
if (a < b) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (idxA === -1 || idxB === -1) return 0;
|
||||
if (idxA > idxB) return 1;
|
||||
if (idxA < idxB) return -1;
|
||||
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
|
||||
* for nested fields.
|
||||
*/
|
||||
return fields.reduce((acc, field) => {
|
||||
let serializedData = fields.reduce((acc, field) => {
|
||||
const fieldName = field.get('name');
|
||||
const value = values.get(fieldName);
|
||||
const serializer = getWidgetValueSerializer(field.get('widget'));
|
||||
@ -58,6 +58,11 @@ const runSerializer = (values, fields, method) => {
|
||||
|
||||
return acc;
|
||||
}, Map());
|
||||
|
||||
//preserve unknown fields value
|
||||
serializedData = values.mergeDeep(serializedData);
|
||||
|
||||
return serializedData;
|
||||
};
|
||||
|
||||
export const serializeValues = (values, fields) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user