Skip to content

Commit

Permalink
fix(legacy-table-chart): when data is empty (#397)
Browse files Browse the repository at this point in the history
  • Loading branch information
ktmud authored and zhaoyongjie committed Nov 26, 2021
1 parent d831f3f commit b51674e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default function ReactDataTable(props: DataTableProps) {
const metrics = (aggMetrics || [])
.concat(percentMetrics || [])
// actual records must be of numeric types as well
.filter(m => typeof data[0][m] === 'number');
.filter(m => data[0] && typeof data[0][m] === 'number');

// check whethere a key is a metric
const metricsSet = new Set(aggMetrics);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/
import React from 'react';
import { mount } from 'enzyme';
import { mount, CommonWrapper } from 'enzyme';
import ReactDataTable from '../src/ReactDataTable';
import transformProps from '../src/transformProps';
import testData from './testData';
Expand All @@ -27,7 +27,7 @@ describe('legacy-table', () => {
describe('transformProps', () => {});

describe('ReactDataTable', () => {
let wrap: any; // the ReactDataTable wraper
let wrap: CommonWrapper; // the ReactDataTable wraper

it('render basic data', () => {
wrap = mount(<ReactDataTable {...transformProps(testData.basic)} />);
Expand All @@ -53,5 +53,11 @@ describe('legacy-table', () => {
expect(cells.eq(2).text()).toEqual('12.346%');
expect(cells.eq(4).text()).toEqual('2.47k');
});

it('render empty data', () => {
wrap.setProps(transformProps(testData.empty));
const tree = wrap.render();
expect(tree.text()).toContain('No data available in table');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,19 @@ const advanced: ChartProps = {
},
};

const empty = {
...advanced,
queryData: {
...advanced.queryData,
data: {
...advanced.queryData.data,
records: [],
},
},
};

export default {
basic,
advanced,
empty,
};

0 comments on commit b51674e

Please sign in to comment.