Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/dashboard/Data/Browser/Browser.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import { ActionTypes as ConfigActionTypes } from 'lib/stores/ConfigStore';
import { getStore } from 'lib/stores/StoreManager';
import stringCompare from 'lib/stringCompare';
import subscribeTo from 'lib/subscribeTo';
import unsetField from 'lib/unsetField';
import { withRouter } from 'lib/withRouter';
import FilterPreferencesManager from 'lib/FilterPreferencesManager';
import { prefersServerStorage } from 'lib/StoragePreferences';
Expand Down Expand Up @@ -1859,14 +1860,14 @@ class Browser extends DashboardView {
return;
}
if (value === undefined) {
obj.unset(attr);
obj = unsetField(obj, attr, isNewObject || isEditCloneObj);
} else {
obj.set(attr, value);
}

if (isNewObject) {
this.setState({
isNewObject: obj,
newObject: obj,
});
return;
}
Expand Down
27 changes: 27 additions & 0 deletions src/lib/tests/unsetField.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (c) 2016-present, Parse, LLC
* All rights reserved.
*
* This source code is licensed under the license found in the LICENSE file in
* the root directory of this source tree.
*/
jest.dontMock('../unsetField');

const unsetField = require('../unsetField').default;
const Parse = require('parse');

describe('unsetField', () => {
it('clears a field on an unsaved object without a Delete op', () => {
const obj = new Parse.Object('Test');
obj.set('username', 'bob');
obj.set('authData', {});
const json = unsetField(obj, 'username', true)._getSaveJSON();
expect(json.username).toBe(undefined);
expect(json.authData).toEqual({});
});

it('keeps the Delete op when unsetting a field on a saved object', () => {
const obj = Parse.Object.fromJSON({ className: 'Test', objectId: 'abc', username: 'bob' });
expect(unsetField(obj, 'username', false)._getSaveJSON().username).toEqual({ __op: 'Delete' });
});
});
11 changes: 11 additions & 0 deletions src/lib/unsetField.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright (c) 2016-present, Parse, LLC
* All rights reserved.
*
* This source code is licensed under the license found in the LICENSE file in
* the root directory of this source tree.
*/
export default function unsetField(obj, attr, isUnsaved) {
obj.unset(attr);
return isUnsaved ? obj.clone() : obj;
}
Loading