From f3fac33745b7b1ebf775b4f77b37abcfa2dcdf44 Mon Sep 17 00:00:00 2001 From: Raschid JF Rafaelly Date: Sun, 16 Jan 2022 12:23:35 -0600 Subject: [PATCH 1/3] fix(Browser): should allow saving nullish values Fixes #1980 --- src/components/BrowserCell/BrowserCell.react.js | 4 ++-- src/dashboard/Data/Browser/Browser.react.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/BrowserCell/BrowserCell.react.js b/src/components/BrowserCell/BrowserCell.react.js index f5c0d3aa0e..90462337e9 100644 --- a/src/components/BrowserCell/BrowserCell.react.js +++ b/src/components/BrowserCell/BrowserCell.react.js @@ -168,7 +168,7 @@ export default class BrowserCell extends Component { } this.onContextMenu = this.onContextMenu.bind(this); - if (this.props.markRequiredField && this.props.isRequired && !this.props.value) { + if (this.props.markRequiredField && this.props.isRequired && (this.props.value == null || this.props.value === '')) { classes.push(styles.required); } @@ -396,7 +396,7 @@ export default class BrowserCell extends Component { if ( current ) { classes.push(styles.current); } - if (markRequiredFieldRow === row && isRequired && !value) { + if (markRequiredFieldRow === row && isRequired && (value == null || value === '')) { classes.push(styles.required); } diff --git a/src/dashboard/Data/Browser/Browser.react.js b/src/dashboard/Data/Browser/Browser.react.js index 2b4d9beb11..19a29f0c47 100644 --- a/src/dashboard/Data/Browser/Browser.react.js +++ b/src/dashboard/Data/Browser/Browser.react.js @@ -417,7 +417,7 @@ class Browser extends DashboardView { if (requiredCols.length) { for (let idx = 0; idx < requiredCols.length; idx++) { const name = requiredCols[idx]; - if (!obj.get(name)) { + if (obj.get(name) == null || obj.get(name) === '') { this.showNote("Please enter all required fields", true); this.setState({ markRequiredFieldRow: -1 @@ -521,7 +521,7 @@ class Browser extends DashboardView { if (requiredCols.length) { for (let idx = 0; idx < requiredCols.length; idx++) { const name = requiredCols[idx]; - if (!obj.get(name)) { + if (obj.get(name) == null || obj.get(name) === '') { this.showNote("Please enter all required fields", true); this.setState({ markRequiredFieldRow: rowIndex From 8b52899485efe669a86b8e9fd92775eeef367ffb Mon Sep 17 00:00:00 2001 From: Raschid JF Rafaelly Date: Sun, 16 Jan 2022 14:05:59 -0600 Subject: [PATCH 2/3] test(BrowserCell): add tests for highlighting required fields --- src/lib/tests/BrowserCell.test.js | 53 +++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/lib/tests/BrowserCell.test.js diff --git a/src/lib/tests/BrowserCell.test.js b/src/lib/tests/BrowserCell.test.js new file mode 100644 index 0000000000..6fab7c5592 --- /dev/null +++ b/src/lib/tests/BrowserCell.test.js @@ -0,0 +1,53 @@ +/* + * 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('../../components/BrowserCell/BrowserCell.react'); + +import React from 'react'; +import renderer from 'react-test-renderer'; +const BrowserCell = require('../../components/BrowserCell/BrowserCell.react').default; + +describe('BrowserCell', () => { + + describe('Required fields', () => { + + it('should not highlight 0 value', () => { + const component = renderer.create( + + ).toJSON(); + expect(component.props.className).not.toContain('required'); + }); + + it('should not highlight false value', () => { + const component = renderer.create( + + ).toJSON(); + expect(component.props.className).not.toContain('required'); + }); + + it('should highlight empty string value', () => { + const component = renderer.create( + + ).toJSON(); + expect(component.props.className).toContain('required'); + }); + + it('should highlight null value', () => { + const component = renderer.create( + + ).toJSON(); + expect(component.props.className).toContain('required'); + }); + + it('should highlight undefined value', () => { + const component = renderer.create( + + ).toJSON(); + expect(component.props.className).toContain('required'); + }); + }); +}); From e8b6a5932d93b7bbbe4364ca65cb1099a1531c9d Mon Sep 17 00:00:00 2001 From: Raschid JF Rafaelly Date: Mon, 17 Jan 2022 19:19:34 -0600 Subject: [PATCH 3/3] refactor: allow empty string in required fields --- src/components/BrowserCell/BrowserCell.react.js | 4 ++-- src/dashboard/Data/Browser/Browser.react.js | 4 ++-- src/lib/tests/BrowserCell.test.js | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/components/BrowserCell/BrowserCell.react.js b/src/components/BrowserCell/BrowserCell.react.js index 90462337e9..f038ba03f6 100644 --- a/src/components/BrowserCell/BrowserCell.react.js +++ b/src/components/BrowserCell/BrowserCell.react.js @@ -168,7 +168,7 @@ export default class BrowserCell extends Component { } this.onContextMenu = this.onContextMenu.bind(this); - if (this.props.markRequiredField && this.props.isRequired && (this.props.value == null || this.props.value === '')) { + if (this.props.markRequiredField && this.props.isRequired && this.props.value == null) { classes.push(styles.required); } @@ -396,7 +396,7 @@ export default class BrowserCell extends Component { if ( current ) { classes.push(styles.current); } - if (markRequiredFieldRow === row && isRequired && (value == null || value === '')) { + if (markRequiredFieldRow === row && isRequired && value == null) { classes.push(styles.required); } diff --git a/src/dashboard/Data/Browser/Browser.react.js b/src/dashboard/Data/Browser/Browser.react.js index 19a29f0c47..9713d49464 100644 --- a/src/dashboard/Data/Browser/Browser.react.js +++ b/src/dashboard/Data/Browser/Browser.react.js @@ -417,7 +417,7 @@ class Browser extends DashboardView { if (requiredCols.length) { for (let idx = 0; idx < requiredCols.length; idx++) { const name = requiredCols[idx]; - if (obj.get(name) == null || obj.get(name) === '') { + if (obj.get(name) == null) { this.showNote("Please enter all required fields", true); this.setState({ markRequiredFieldRow: -1 @@ -521,7 +521,7 @@ class Browser extends DashboardView { if (requiredCols.length) { for (let idx = 0; idx < requiredCols.length; idx++) { const name = requiredCols[idx]; - if (obj.get(name) == null || obj.get(name) === '') { + if (obj.get(name) == null) { this.showNote("Please enter all required fields", true); this.setState({ markRequiredFieldRow: rowIndex diff --git a/src/lib/tests/BrowserCell.test.js b/src/lib/tests/BrowserCell.test.js index 6fab7c5592..6b3e1e2c40 100644 --- a/src/lib/tests/BrowserCell.test.js +++ b/src/lib/tests/BrowserCell.test.js @@ -29,11 +29,11 @@ describe('BrowserCell', () => { expect(component.props.className).not.toContain('required'); }); - it('should highlight empty string value', () => { + it('should not highlight empty string value', () => { const component = renderer.create( ).toJSON(); - expect(component.props.className).toContain('required'); + expect(component.props.className).not.toContain('required'); }); it('should highlight null value', () => {