mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 01:13:23 -04:00
[8.6] [Discover] Fix crash when navigating from saved search with time field to saved search without time field (#146478) (#146488)
# Backport This will backport the following commits from `main` to `8.6`: - [[Discover] Fix crash when navigating from saved search with time field to saved search without time field (#146478)](https://github.com/elastic/kibana/pull/146478) <!--- Backport version: 8.9.7 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Davis McPhee","email":"davis.mcphee@elastic.co"},"sourceCommit":{"committedDate":"2022-11-29T00:29:19Z","message":"[Discover] Fix crash when navigating from saved search with time field to saved search without time field (#146478)\n\n## Summary\r\n\r\nThis PR fixes an issue where loading a saved search with a time field\r\nand then loading a saved search without a time field would cause\r\nDiscover to crash.\r\n\r\nFixes #146464.\r\n\r\n### Checklist\r\n\r\n- [ ] ~Any text added follows [EUI's writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing), uses\r\nsentence case text and includes [i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)~\r\n- [ ]\r\n~[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas added for features that require explanation or tutorials~\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n- [ ] ~Any UI touched in this PR is usable by keyboard only (learn more\r\nabout [keyboard\r\naccessibility](https://webaim.org/techniques/keyboard/))~\r\n- [ ] ~Any UI touched in this PR does not create any new axe failures\r\n(run axe in browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))~\r\n- [ ] ~If a plugin configuration key changed, check if it needs to be\r\nallowlisted in the cloud and added to the [docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)~\r\n- [ ] ~This renders correctly on smaller devices using a responsive\r\nlayout. (You can test this [in your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))~\r\n- [ ] ~This was checked for [cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)~\r\n\r\n### For maintainers\r\n\r\n- [ ] This was checked for breaking API changes and was [labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"8b0490e1e3858b27813a3431729589f0946f5156","branchLabelMapping":{"^v8.7.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:Discover","release_note:skip","Team:DataDiscovery","v8.6.0","v8.7.0","v8.6.1"],"number":146478,"url":"https://github.com/elastic/kibana/pull/146478","mergeCommit":{"message":"[Discover] Fix crash when navigating from saved search with time field to saved search without time field (#146478)\n\n## Summary\r\n\r\nThis PR fixes an issue where loading a saved search with a time field\r\nand then loading a saved search without a time field would cause\r\nDiscover to crash.\r\n\r\nFixes #146464.\r\n\r\n### Checklist\r\n\r\n- [ ] ~Any text added follows [EUI's writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing), uses\r\nsentence case text and includes [i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)~\r\n- [ ]\r\n~[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas added for features that require explanation or tutorials~\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n- [ ] ~Any UI touched in this PR is usable by keyboard only (learn more\r\nabout [keyboard\r\naccessibility](https://webaim.org/techniques/keyboard/))~\r\n- [ ] ~Any UI touched in this PR does not create any new axe failures\r\n(run axe in browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))~\r\n- [ ] ~If a plugin configuration key changed, check if it needs to be\r\nallowlisted in the cloud and added to the [docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)~\r\n- [ ] ~This renders correctly on smaller devices using a responsive\r\nlayout. (You can test this [in your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))~\r\n- [ ] ~This was checked for [cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)~\r\n\r\n### For maintainers\r\n\r\n- [ ] This was checked for breaking API changes and was [labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"8b0490e1e3858b27813a3431729589f0946f5156"}},"sourceBranch":"main","suggestedTargetBranches":["8.6"],"targetPullRequestStates":[{"branch":"8.6","label":"v8.6.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.7.0","labelRegex":"^v8.7.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/146478","number":146478,"mergeCommit":{"message":"[Discover] Fix crash when navigating from saved search with time field to saved search without time field (#146478)\n\n## Summary\r\n\r\nThis PR fixes an issue where loading a saved search with a time field\r\nand then loading a saved search without a time field would cause\r\nDiscover to crash.\r\n\r\nFixes #146464.\r\n\r\n### Checklist\r\n\r\n- [ ] ~Any text added follows [EUI's writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing), uses\r\nsentence case text and includes [i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)~\r\n- [ ]\r\n~[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas added for features that require explanation or tutorials~\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n- [ ] ~Any UI touched in this PR is usable by keyboard only (learn more\r\nabout [keyboard\r\naccessibility](https://webaim.org/techniques/keyboard/))~\r\n- [ ] ~Any UI touched in this PR does not create any new axe failures\r\n(run axe in browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))~\r\n- [ ] ~If a plugin configuration key changed, check if it needs to be\r\nallowlisted in the cloud and added to the [docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)~\r\n- [ ] ~This renders correctly on smaller devices using a responsive\r\nlayout. (You can test this [in your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))~\r\n- [ ] ~This was checked for [cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)~\r\n\r\n### For maintainers\r\n\r\n- [ ] This was checked for breaking API changes and was [labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"8b0490e1e3858b27813a3431729589f0946f5156"}}]}] BACKPORT--> Co-authored-by: Davis McPhee <davis.mcphee@elastic.co>
This commit is contained in:
parent
5f8b171ee3
commit
6c144c2e1c
3 changed files with 56 additions and 8 deletions
|
@ -33,6 +33,7 @@ import {
|
|||
} from './use_discover_histogram';
|
||||
import { setTimeout } from 'timers/promises';
|
||||
import { calculateBounds } from '@kbn/data-plugin/public';
|
||||
import { buildChartData } from '@kbn/unified-histogram-plugin/public';
|
||||
|
||||
const mockData = dataPluginMock.createStartContract();
|
||||
|
||||
|
@ -62,6 +63,16 @@ jest.mock('@kbn/unified-field-list-plugin/public', () => {
|
|||
};
|
||||
});
|
||||
|
||||
const mockBuildChartData = buildChartData as jest.MockedFunction<typeof buildChartData>;
|
||||
|
||||
jest.mock('@kbn/unified-histogram-plugin/public', () => {
|
||||
const originalModule = jest.requireActual('@kbn/unified-histogram-plugin/public');
|
||||
return {
|
||||
...originalModule,
|
||||
buildChartData: jest.fn(originalModule.buildChartData),
|
||||
};
|
||||
});
|
||||
|
||||
describe('useDiscoverHistogram', () => {
|
||||
const renderUseDiscoverHistogram = async ({
|
||||
isPlainRecord = false,
|
||||
|
@ -294,4 +305,24 @@ describe('useDiscoverHistogram', () => {
|
|||
expect(stateContainer.setAppState).toHaveBeenCalledWith({ interval: 'auto' });
|
||||
});
|
||||
});
|
||||
|
||||
describe('buildChartData', () => {
|
||||
it('should call buildChartData when isPlainRecord is false and isTimeBased is true', async () => {
|
||||
mockBuildChartData.mockClear();
|
||||
await renderUseDiscoverHistogram();
|
||||
expect(mockBuildChartData).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should not call buildChartData when isPlainRecord is true', async () => {
|
||||
mockBuildChartData.mockClear();
|
||||
await renderUseDiscoverHistogram({ isPlainRecord: true });
|
||||
expect(mockBuildChartData).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should not call buildChartData when isTimeBased is false', async () => {
|
||||
mockBuildChartData.mockClear();
|
||||
await renderUseDiscoverHistogram({ isTimeBased: false });
|
||||
expect(mockBuildChartData).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -137,13 +137,15 @@ export const useDiscoverHistogram = ({
|
|||
|
||||
const { bucketInterval, chartData } = useMemo(
|
||||
() =>
|
||||
buildChartData({
|
||||
data,
|
||||
dataView,
|
||||
timeInterval: state.interval,
|
||||
response,
|
||||
}),
|
||||
[data, dataView, response, state.interval]
|
||||
isPlainRecord || !isTimeBased
|
||||
? { bucketInterval: undefined, chartData: undefined }
|
||||
: buildChartData({
|
||||
data,
|
||||
dataView,
|
||||
timeInterval: state.interval,
|
||||
response,
|
||||
}),
|
||||
[data, dataView, isPlainRecord, isTimeBased, response, state.interval]
|
||||
);
|
||||
|
||||
const chart = useMemo(
|
||||
|
|
|
@ -15,7 +15,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
|
|||
const kibanaServer = getService('kibanaServer');
|
||||
const security = getService('security');
|
||||
const testSubjects = getService('testSubjects');
|
||||
const PageObjects = getPageObjects(['common', 'timePicker', 'discover']);
|
||||
const PageObjects = getPageObjects(['common', 'timePicker', 'discover', 'header']);
|
||||
|
||||
describe('indexpattern without timefield', () => {
|
||||
before(async () => {
|
||||
|
@ -114,5 +114,20 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
|
|||
url = await browser.getCurrentUrl();
|
||||
expect(url).to.contain(`refreshInterval:(pause:!t,value:${autoRefreshInterval * 1000})`);
|
||||
});
|
||||
|
||||
it('should allow switching from a saved search with a time field to a saved search without a time field', async () => {
|
||||
await PageObjects.common.navigateToApp('discover');
|
||||
await PageObjects.discover.selectIndexPattern('with-timefield');
|
||||
await PageObjects.header.waitUntilLoadingHasFinished();
|
||||
await PageObjects.discover.saveSearch('with-timefield');
|
||||
await PageObjects.discover.selectIndexPattern('without-timefield');
|
||||
await PageObjects.header.waitUntilLoadingHasFinished();
|
||||
await PageObjects.discover.saveSearch('without-timefield', true);
|
||||
await PageObjects.discover.loadSavedSearch('with-timefield');
|
||||
await PageObjects.header.waitUntilLoadingHasFinished();
|
||||
await PageObjects.discover.loadSavedSearch('without-timefield');
|
||||
await PageObjects.header.waitUntilLoadingHasFinished();
|
||||
await PageObjects.discover.assertHitCount('1');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue