Skip to content

Commit faa6b54

Browse files
tungshengopensearch-changeset-bot[bot]AMoo-Miki
authored
Fix toggle column action in the discover page (#8905)
* Update DocViewerTab if columns is changed * Add unit test for DocViewerTab prop 'columns' changed * Add changeset file * Changeset file for PR #8905 created/updated * Use the new license header --------- Signed-off-by: Tony Lee <tony.lee@dtexsystems.com> Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com> Co-authored-by: Miki <miki@amazon.com>
1 parent 85273e3 commit faa6b54

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

changelogs/fragments/8905.yml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
fix:
2+
- Fix toggle column action in the discover page ([#8905](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8905))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import React from 'react';
7+
import { mount } from 'enzyme';
8+
import { DocViewerTab, DocViewerTabProps } from './doc_viewer_tab';
9+
import { DocViewRenderProps } from '../../doc_views/doc_views_types';
10+
11+
test('DocViewerTab updated when getting new renderProps', () => {
12+
const MockComp = ({ columns }: DocViewRenderProps) => (
13+
<div data-test-subj="test-div">{columns![0]}</div>
14+
);
15+
16+
const mockProps: DocViewerTabProps = {
17+
id: 1,
18+
title: 'Test1',
19+
component: MockComp,
20+
renderProps: {
21+
hit: { _id: '1' },
22+
columns: ['test1'],
23+
},
24+
};
25+
26+
const wrapper = mount(<DocViewerTab {...mockProps} />);
27+
28+
const div = wrapper.find({ 'data-test-subj': 'test-div' });
29+
expect(div.text()).toEqual('test1');
30+
31+
mockProps.renderProps = { hit: { _id: '1' }, columns: ['test2'] };
32+
wrapper.setProps(mockProps);
33+
expect(div.text()).toEqual('test2');
34+
});

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

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export class DocViewerTab extends React.Component<Props, State> {
6565
shouldComponentUpdate(nextProps: Props, nextState: State) {
6666
return (
6767
nextProps.renderProps.hit._id !== this.props.renderProps.hit._id ||
68+
nextProps.renderProps.columns !== this.props.renderProps.columns ||
6869
nextProps.id !== this.props.id ||
6970
nextState.hasError
7071
);

0 commit comments

Comments
 (0)