[Discover] Switch documents correctly in Document Explorer (#134163)

* [Discover] switch documents correctly

* [Discover] add functional test

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Dmitry Tomashevich 2022-06-15 12:56:26 +03:00 committed by GitHub
parent 6347737a93
commit bd485d5d23
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 113 additions and 7 deletions

View file

@ -43,7 +43,7 @@ export const SelectButton = ({ rowIndex, setCellProps }: EuiDataGridCellValueEle
});
useEffect(() => {
if (expanded && doc && expanded._id === doc._id) {
if (expanded && doc && expanded._id === doc._id && expanded._index === doc._index) {
setCellProps({
style: {
backgroundColor: isDarkMode ? themeDark.euiColorHighlight : themeLight.euiColorHighlight,

View file

@ -25,7 +25,12 @@ export const ExpandButton = ({ rowIndex, setCellProps }: EuiDataGridCellValueEle
setCellProps({
className: 'dscDocsGrid__cell--highlight',
});
} else if (expanded && current && expanded._id === current._id) {
} else if (
expanded &&
current &&
expanded._id === current._id &&
expanded._index === current._index
) {
setCellProps({
style: {
backgroundColor: isDarkMode ? themeDark.euiColorHighlight : themeLight.euiColorHighlight,

View file

@ -71,7 +71,10 @@ export function DiscoverGridFlyout({
}: DiscoverGridFlyoutProps) {
const services = useDiscoverServices();
// Get actual hit with updated highlighted searches
const actualHit = useMemo(() => hits?.find(({ _id }) => _id === hit?._id) || hit, [hit, hits]);
const actualHit = useMemo(
() => hits?.find(({ _id, _index }) => hit._index === _index && _id === hit?._id) || hit,
[hit, hits]
);
const pageCount = useMemo<number>(() => (hits ? hits.length : 0), [hits]);
const activePage = useMemo<number>(() => {
const id = getDocFingerprintId(hit);
@ -83,9 +86,9 @@ export function DiscoverGridFlyout({
}, [hits, hit, pageCount]);
const setPage = useCallback(
(pageIdx: number) => {
if (hits && hits[pageIdx]) {
setExpandedDoc(hits[pageIdx]);
(index: number) => {
if (hits && hits[index]) {
setExpandedDoc(hits[index]);
}
},
[hits, setExpandedDoc]

View file

@ -61,7 +61,12 @@ export const getRenderCellValueFn =
setCellProps({
className: 'dscDocsGrid__cell--highlight',
});
} else if (ctx.expanded && row && ctx.expanded._id === row._id) {
} else if (
ctx.expanded &&
row &&
ctx.expanded._id === row._id &&
ctx.expanded._index === row._index
) {
setCellProps({
style: {
backgroundColor: ctx.isDarkMode

View file

@ -43,6 +43,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.hit._index !== this.props.renderProps.hit._index ||
!isEqual(nextProps.renderProps.hit.highlight, this.props.renderProps.hit.highlight) ||
nextProps.id !== this.props.id ||
!isEqual(nextProps.renderProps.columns, this.props.renderProps.columns) ||

View file

@ -0,0 +1,61 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import expect from '@kbn/expect';
import { FtrProviderContext } from '../../ftr_provider_context';
export default function ({ getService, getPageObjects }: FtrProviderContext) {
const dataGrid = getService('dataGrid');
const testSubjects = getService('testSubjects');
const PageObjects = getPageObjects(['common', 'discover', 'timePicker', 'settings']);
const es = getService('es');
const security = getService('security');
const createIndex = (indexName: string) => {
return es.transport.request({
path: `/${indexName}/_doc/1`,
method: 'PUT',
body: {
username: 'Dmitry',
'@timestamp': '2015-09-21T09:30:23',
message: 'hello',
},
});
};
describe('discover data grid row navigation', function () {
before(async () => {
await security.testUser.setRoles(['kibana_admin', 'similar-index']);
await security.testUser.setRoles(['kibana_admin', 'similar-index-two']);
await PageObjects.common.navigateToApp('settings');
await createIndex('similar-index');
await createIndex('similar-index-two');
await PageObjects.settings.createIndexPattern('similar-index*', '@timestamp', true);
await PageObjects.timePicker.setDefaultAbsoluteRangeViaUiSettings();
await PageObjects.common.navigateToApp('discover');
});
it('should navigate through rows with the same id but different indices correctly', async () => {
await PageObjects.discover.selectIndexPattern('similar-index*');
await dataGrid.clickRowToggle();
const indexBeforePaginating = await testSubjects.getVisibleText(
'tableDocViewRow-_index-value'
);
expect(indexBeforePaginating).to.be('similar-index');
await testSubjects.click('pagination-button-next');
const indexAfterPaginating = await testSubjects.getVisibleText(
'tableDocViewRow-_index-value'
);
expect(indexAfterPaginating).to.be('similar-index-two');
});
});
}

View file

@ -49,6 +49,7 @@ export default function ({ getService, loadTestFile }: FtrProviderContext) {
loadTestFile(require.resolve('./_data_grid_context'));
loadTestFile(require.resolve('./_data_grid_field_data'));
loadTestFile(require.resolve('./_data_grid_doc_navigation'));
loadTestFile(require.resolve('./_data_grid_row_navigation'));
loadTestFile(require.resolve('./_data_grid_doc_table'));
loadTestFile(require.resolve('./_data_grid_copy_to_clipboard'));
loadTestFile(require.resolve('./_indexpattern_with_unmapped_fields'));

View file

@ -216,6 +216,36 @@ export default async function ({ readConfigFile }) {
kibana: [],
},
similar_index: {
elasticsearch: {
cluster: [],
indices: [
{
names: ['similar-index'],
privileges: ['read', 'view_index_metadata', 'manage', 'create_index', 'index'],
field_security: { grant: ['*'], except: [] },
},
],
run_as: [],
},
kibana: [],
},
similar_index_two: {
elasticsearch: {
cluster: [],
indices: [
{
names: ['similar-index-two'],
privileges: ['read', 'view_index_metadata', 'manage', 'create_index', 'index'],
field_security: { grant: ['*'], except: [] },
},
],
run_as: [],
},
kibana: [],
},
kibana_sample_read: {
elasticsearch: {
cluster: [],