Skip to content

Commit

Permalink
fix(datagrid/TDC-1534): handle bytes value (#2121)
Browse files Browse the repository at this point in the history
  • Loading branch information
jare-talend authored and jsomsanith-tlnd committed Mar 29, 2019
1 parent a348f88 commit 894fc7a
Show file tree
Hide file tree
Showing 5 changed files with 913 additions and 2,306 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React from 'react';
import PropTypes from 'prop-types';

import DefaultValueRenderer from './DefaultValueRenderer.component';
import DefaultValueRenderer, { DEFAULT_VALUE_PROP_TYPES } from './DefaultValueRenderer.component';

export default function DefaultRenderer({ data }) {
return <DefaultValueRenderer value={data.value} />;
}

DefaultRenderer.propTypes = {
data: PropTypes.shape({
value: PropTypes.oneOfType([PropTypes.string, PropTypes.bool, PropTypes.number]),
value: DEFAULT_VALUE_PROP_TYPES,
}),
};
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import has from 'lodash/has';
import { TooltipTrigger } from '@talend/react-components';
import FormatValue, { hasWhiteSpaceCharacters } from './FormatValue.component';

import theme from './DefaultValueRenderer.scss';

export const DEFAULT_VALUE_PROP_TYPES = PropTypes.oneOfType([
PropTypes.string,
PropTypes.bool,
PropTypes.number,
PropTypes.shape({
bytes: PropTypes.string,
}),
]);

export default class DefaultValueRenderer extends React.Component {
static propTypes = {
className: PropTypes.string,
value: PropTypes.oneOfType([PropTypes.string, PropTypes.bool, PropTypes.number]),
value: DEFAULT_VALUE_PROP_TYPES,
};

constructor(props) {
Expand Down Expand Up @@ -43,6 +53,8 @@ export default class DefaultValueRenderer extends React.Component {

if (this.props.value === null) {
stringValue = '';
} else if (has(this.props.value, 'bytes')) {
stringValue = this.props.value.bytes;
} else {
stringValue = String(this.props.value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ describe('#DefaultValueRenderer', () => {
expect(wrapper.getElement()).toMatchSnapshot();
});

it('should render a bytes', () => {
const wrapper = shallow(<DefaultValueRenderer value={{ bytes: 'ejfiejifje' }} />);

expect(wrapper.getElement()).toMatchSnapshot();
});

it('should render empty when the value is null', () => {
const wrapper = shallow(<DefaultValueRenderer value={null} />);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ exports[`#DefaultValueRenderer should render a boolean 1`] = `
</div>
`;

exports[`#DefaultValueRenderer should render a bytes 1`] = `
<div
className="theme-td-default-cell td-default-cell"
onMouseOver={[Function]}
>
ejfiejifje
</div>
`;

exports[`#DefaultValueRenderer should render empty when the value is null 1`] = `
<div
className="theme-td-default-cell td-default-cell"
Expand Down
Loading

0 comments on commit 894fc7a

Please sign in to comment.