Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: cannot save nullish values for required fields #2003

Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 2 additions & 2 deletions src/components/BrowserCell/BrowserCell.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 === '')) {
RaschidJFR marked this conversation as resolved.
Show resolved Hide resolved
classes.push(styles.required);
}

Expand Down Expand Up @@ -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);
}

Expand Down
4 changes: 2 additions & 2 deletions src/dashboard/Data/Browser/Browser.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
53 changes: 53 additions & 0 deletions src/lib/tests/BrowserCell.test.js
Original file line number Diff line number Diff line change
@@ -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(
<BrowserCell value={0} markRequiredField={true} isRequired={true}/>
).toJSON();
expect(component.props.className).not.toContain('required');
});

it('should not highlight false value', () => {
const component = renderer.create(
<BrowserCell value={false} markRequiredField={true} isRequired={true}/>
).toJSON();
expect(component.props.className).not.toContain('required');
});

it('should highlight empty string value', () => {
const component = renderer.create(
<BrowserCell value="" markRequiredField={true} isRequired={true}/>
).toJSON();
expect(component.props.className).toContain('required');
});

it('should highlight null value', () => {
const component = renderer.create(
<BrowserCell value={null} markRequiredField={true} isRequired={true}/>
).toJSON();
expect(component.props.className).toContain('required');
});

it('should highlight undefined value', () => {
const component = renderer.create(
<BrowserCell markRequiredField={true} isRequired={true}/>
).toJSON();
expect(component.props.className).toContain('required');
});
});
});