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

[Discover] Fix Field Statistics when discover:searchFieldsFromSource is enabled #187250

Merged
merged 8 commits into from
Jul 11, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ export const FieldStatisticsTable = React.memo((props: FieldStatisticsTableProps
} = props;

const visibleFields = useMemo(
() => convertFieldsToFallbackFields({ fields: columns, additionalFieldGroups }),
() =>
convertFieldsToFallbackFields({
// `discover:searchFieldsFromSource` adds `_source` to the columns, but we should exclude it for Field Statistics
fields: columns.filter((col) => col !== '_source'),
additionalFieldGroups,
}),
[additionalFieldGroups, columns]
);
const allFallbackFields = useMemo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,8 @@ function DiscoverDocumentsComponent({
<>
<SelectedVSAvailableCallout
esqlQueryColumns={documents?.esqlQueryColumns}
selectedColumns={currentColumns}
// `discover:searchFieldsFromSource` adds `_source` to the columns, but we should exclude it from the callout
selectedColumns={currentColumns.filter((col) => col !== '_source')}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind adding a comment here explaining why we're filtering out _source (similar to the one above)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, thanks for the review!

/>
<SearchResponseWarningsCallout warnings={documentState.interceptedWarnings ?? []} />
</>
Expand Down
72 changes: 72 additions & 0 deletions test/functional/apps/discover/group6/_field_stats_table.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* 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 { FtrProviderContext } from '../ftr_provider_context';

export default function ({ getService, getPageObjects }: FtrProviderContext) {
const PageObjects = getPageObjects(['common', 'discover', 'timePicker', 'header']);
const esArchiver = getService('esArchiver');
const testSubjects = getService('testSubjects');
const kibanaServer = getService('kibanaServer');
const security = getService('security');
const defaultSettings = {
defaultIndex: 'logstash-*',
};

describe('discover field statistics table', function () {
before(async () => {
await security.testUser.setRoles(['kibana_admin', 'test_logstash_reader']);
await esArchiver.loadIfNeeded('test/functional/fixtures/es_archiver/logstash_functional');
await kibanaServer.importExport.load('test/functional/fixtures/kbn_archiver/discover');
});

after(async () => {
await kibanaServer.importExport.unload('test/functional/fixtures/kbn_archiver/discover');
await esArchiver.unload('test/functional/fixtures/es_archiver/logstash_functional');
await kibanaServer.savedObjects.cleanStandardList();
});

[true, false].forEach((shouldSearchFieldsFromSource) => {
describe(`discover:searchFieldsFromSource: ${shouldSearchFieldsFromSource}`, function () {
before(async function () {
await PageObjects.timePicker.setDefaultAbsoluteRangeViaUiSettings();
await kibanaServer.uiSettings.update({
...defaultSettings,
'discover:searchFieldsFromSource': shouldSearchFieldsFromSource,
});
await PageObjects.common.navigateToApp('discover');
await PageObjects.header.waitUntilLoadingHasFinished();
await PageObjects.discover.waitUntilSearchingHasFinished();
});

after(async () => {
await kibanaServer.uiSettings.replace({});
});

it('should show Field Statistics data in data view mode', async () => {
await testSubjects.click('dscViewModeFieldStatsButton');
await PageObjects.header.waitUntilLoadingHasFinished();
await testSubjects.existOrFail('dataVisualizerTableContainer');

await testSubjects.click('dscViewModeDocumentButton');
await PageObjects.header.waitUntilLoadingHasFinished();
await testSubjects.existOrFail('discoverDocTable');
});

it('should show Field Statistics data in ES|QL mode', async () => {
await PageObjects.discover.selectTextBaseLang();
await PageObjects.discover.waitUntilSearchingHasFinished();

await testSubjects.click('dscViewModeFieldStatsButton');
await PageObjects.header.waitUntilLoadingHasFinished();
await testSubjects.existOrFail('dataVisualizerTableContainer');
});
});
});
});
}
1 change: 1 addition & 0 deletions test/functional/apps/discover/group6/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ export default function ({ getService, loadTestFile }: FtrProviderContext) {
loadTestFile(require.resolve('./_time_field_column'));
loadTestFile(require.resolve('./_unsaved_changes_badge'));
loadTestFile(require.resolve('./_view_mode_toggle'));
loadTestFile(require.resolve('./_field_stats_table'));
});
}