Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2.x] Fix toggle column action in the discover page #9053

Open
wants to merge 1 commit into
base: 2.x
Choose a base branch
from
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
2 changes: 2 additions & 0 deletions changelogs/fragments/8905.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fix:
- Fix toggle column action in the discover page ([#8905](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8905))
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import React from 'react';
import { mount } from 'enzyme';
import { DocViewerTab, DocViewerTabProps } from './doc_viewer_tab';
import { DocViewRenderProps } from '../../doc_views/doc_views_types';

test('DocViewerTab updated when getting new renderProps', () => {
const MockComp = ({ columns }: DocViewRenderProps) => (
<div data-test-subj="test-div">{columns![0]}</div>
);

const mockProps: DocViewerTabProps = {
id: 1,
title: 'Test1',
component: MockComp,
renderProps: {
hit: { _id: '1' },
columns: ['test1'],
},
};

const wrapper = mount(<DocViewerTab {...mockProps} />);

const div = wrapper.find({ 'data-test-subj': 'test-div' });
expect(div.text()).toEqual('test1');

mockProps.renderProps = { hit: { _id: '1' }, columns: ['test2'] };
wrapper.setProps(mockProps);
expect(div.text()).toEqual('test2');
});
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export class DocViewerTab extends React.Component<Props, State> {
shouldComponentUpdate(nextProps: Props, nextState: State) {
return (
nextProps.renderProps.hit._id !== this.props.renderProps.hit._id ||
nextProps.renderProps.columns !== this.props.renderProps.columns ||
nextProps.id !== this.props.id ||
nextState.hasError
);
Expand Down
Loading