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
13 changes: 8 additions & 5 deletions src/components/BrowserCell/BrowserCell.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,13 @@ export default class BrowserCell extends Component {
this.copyableValue = content = JSON.stringify(this.props.value);
}
} else if (this.props.type === 'Date') {
if (typeof value === 'object' && this.props.value.__type) {
this.props.value = new Date(this.props.value.iso);
} else if (typeof value === 'string') {
this.props.value = new Date(this.props.value);
let dateValue = this.props.value;
if (typeof dateValue === 'object' && dateValue.__type) {
dateValue = new Date(dateValue.iso);
} else if (typeof dateValue === 'string') {
dateValue = new Date(dateValue);
}
this.copyableValue = content = dateStringUTC(this.props.value);
this.copyableValue = content = dateStringUTC(dateValue);
} else if (this.props.type === 'Boolean') {
this.copyableValue = content = this.props.value ? 'True' : 'False';
} else if (this.props.type === 'Object' || this.props.type === 'Bytes') {
Expand Down Expand Up @@ -206,6 +207,8 @@ export default class BrowserCell extends Component {
'Relation'
);
this.copyableValue = undefined;
} else if (this.props.value instanceof Date) {
this.copyableValue = content = dateStringUTC(this.props.value);
}
this.onContextMenu = this.onContextMenu.bind(this);

Expand Down
22 changes: 22 additions & 0 deletions src/lib/tests/BrowserCell.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,26 @@ describe('BrowserCell', () => {
expect(component.props.className).toContain('required');
});
});

describe('Date value in a non-Date column (issue #1927)', () => {
it('should render a Date value as a string instead of crashing', () => {
let component;
expect(() => {
component = renderer
.create(<BrowserCell type="String" value={new Date('2001-01-01T00:00:00Z')} row={0} />)
.toJSON();
}).not.toThrow();
expect(typeof component.children[0]).toBe('string');
});

it('should render a Date-typed column given a date string without crashing', () => {
let component;
expect(() => {
component = renderer
.create(<BrowserCell type="Date" value="2001-01-01" row={0} />)
.toJSON();
}).not.toThrow();
expect(typeof component.children[0]).toBe('string');
});
});
});
Loading