Skip to content

Commit 57cdeb2

Browse files
authored
[Discover][DocViewer] Fix toggle columns from doc viewer table tab (#95748) (#111081)
1 parent a6a1b5d commit 57cdeb2

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
import React from 'react';
10+
import { shallow } from 'enzyme';
11+
import { DocViewerTab } from './doc_viewer_tab';
12+
import { ElasticSearchHit } from '../../doc_views/doc_views_types';
13+
14+
describe('DocViewerTab', () => {
15+
test('changing columns triggers an update', () => {
16+
const props = {
17+
title: 'test',
18+
component: jest.fn(),
19+
id: 1,
20+
render: jest.fn(),
21+
renderProps: {
22+
hit: {} as ElasticSearchHit,
23+
columns: ['test'],
24+
},
25+
};
26+
27+
const wrapper = shallow(<DocViewerTab {...props} />);
28+
29+
const nextProps = {
30+
...props,
31+
renderProps: {
32+
hit: {} as ElasticSearchHit,
33+
columns: ['test2'],
34+
},
35+
};
36+
37+
const shouldUpdate = (wrapper!.instance() as DocViewerTab).shouldComponentUpdate(nextProps, {
38+
hasError: false,
39+
error: '',
40+
});
41+
expect(shouldUpdate).toBe(true);
42+
});
43+
});

src/plugins/discover/public/application/components/doc_viewer/doc_viewer_tab.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
import React from 'react';
10+
import { isEqual } from 'lodash';
1011
import { I18nProvider } from '@kbn/i18n/react';
1112
import { DocViewRenderTab } from './doc_viewer_render_tab';
1213
import { DocViewerError } from './doc_viewer_render_error';
@@ -46,6 +47,7 @@ export class DocViewerTab extends React.Component<Props, State> {
4647
return (
4748
nextProps.renderProps.hit._id !== this.props.renderProps.hit._id ||
4849
nextProps.id !== this.props.id ||
50+
!isEqual(nextProps.renderProps.columns, this.props.renderProps.columns) ||
4951
nextState.hasError
5052
);
5153
}

0 commit comments

Comments
 (0)