Skip to content

Commit

Permalink
[8.5] [Discover] Prevent agg based visualizations of Discover saved o…
Browse files Browse the repository at this point in the history
…bjects with adhoc data views (#145583) (#146412)

# Backport

This will backport the following commits from `main` to `8.5`:
- [[Discover] Prevent agg based visualizations of Discover saved objects
with adhoc data views
(#145583)](#145583)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Dmitry
Tomashevich","email":"[email protected]"},"sourceCommit":{"committedDate":"2022-11-25T13:16:34Z","message":"[Discover]
Prevent agg based visualizations of Discover saved objects with adhoc
data views (#145583)\n\n## Summary\r\n\r\nFixes #141812\r\n\r\nThis PR
preventing using Discover saved objects with adhoc data views
in\r\naggregation based visualisations.\r\n\r\n### Test notes \r\n-
Create Saved search based on adhoc data view in Discover\r\n- Open new
Agg based visualisations list and choose one\r\n- Created Saved search
shouldn't appear in the list. \r\n\r\n### Checklist\r\n\r\n\r\n- [ ]
[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","sha":"2c9043ab431cebbbdeb77c96aa2a5c0bc5b0ddf4","branchLabelMapping":{"^v8.7.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:Discover","release_note:fix","Feature:Vis
Editor","auto-backport","Team:DataDiscovery","v8.6.0","v8.7.0","v8.5.2"],"number":145583,"url":"https://github.com/elastic/kibana/pull/145583","mergeCommit":{"message":"[Discover]
Prevent agg based visualizations of Discover saved objects with adhoc
data views (#145583)\n\n## Summary\r\n\r\nFixes #141812\r\n\r\nThis PR
preventing using Discover saved objects with adhoc data views
in\r\naggregation based visualisations.\r\n\r\n### Test notes \r\n-
Create Saved search based on adhoc data view in Discover\r\n- Open new
Agg based visualisations list and choose one\r\n- Created Saved search
shouldn't appear in the list. \r\n\r\n### Checklist\r\n\r\n\r\n- [ ]
[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","sha":"2c9043ab431cebbbdeb77c96aa2a5c0bc5b0ddf4"}},"sourceBranch":"main","suggestedTargetBranches":["8.5"],"targetPullRequestStates":[{"branch":"8.6","label":"v8.6.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/146344","number":146344,"state":"MERGED","mergeCommit":{"sha":"461c04ec6cf855ba590b06d5be7ba121cefc00ba","message":"[8.6]
[Discover] Prevent agg based visualizations of Discover saved objects
with adhoc data views (#145583) (#146344)\n\n# Backport\n\nThis will
backport the following commits from `main` to `8.6`:\n- [[Discover]
Prevent agg based visualizations of Discover saved objects\nwith adhoc
data
views\n(#145583)](https://github.com/elastic/kibana/pull/145583)\n\n<!---
Backport version: 8.9.7 -->\n\n### Questions ?\nPlease refer to the
[Backport
tool\ndocumentation](https://github.com/sqren/backport)\n\n<!--BACKPORT
[{\"author\":{\"name\":\"Dmitry\nTomashevich\",\"email\":\"[email protected]\"},\"sourceCommit\":{\"committedDate\":\"2022-11-25T13:16:34Z\",\"message\":\"[Discover]\nPrevent
agg based visualizations of Discover saved objects with adhoc\ndata
views (#145583)\\n\\n## Summary\\r\\n\\r\\nFixes #141812\\r\\n\\r\\nThis
PR\npreventing using Discover saved objects with adhoc data
views\nin\\r\\naggregation based visualisations.\\r\\n\\r\\n### Test
notes \\r\\n-\nCreate Saved search based on adhoc data view in
Discover\\r\\n- Open new\nAgg based visualisations list and choose
one\\r\\n- Created Saved search\nshouldn't appear in the list.
\\r\\n\\r\\n### Checklist\\r\\n\\r\\n\\r\\n- [ ]\n[Unit
or\nfunctional\\r\\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\\r\\nwere\nupdated
or added to match the most
common\nscenarios\",\"sha\":\"2c9043ab431cebbbdeb77c96aa2a5c0bc5b0ddf4\",\"branchLabelMapping\":{\"^v8.7.0$\":\"main\",\"^v(\\\\d+).(\\\\d+).\\\\d+$\":\"$1.$2\"}},\"sourcePullRequest\":{\"labels\":[\"Feature:Discover\",\"release_note:fix\",\"Feature:Vis\nEditor\",\"auto-backport\",\"Team:DataDiscovery\",\"v8.6.0\",\"v8.7.0\",\"v8.5.2\"],\"number\":145583,\"url\":\"https://github.com/elastic/kibana/pull/145583\",\"mergeCommit\":{\"message\":\"[Discover]\nPrevent
agg based visualizations of Discover saved objects with adhoc\ndata
views (#145583)\\n\\n## Summary\\r\\n\\r\\nFixes #141812\\r\\n\\r\\nThis
PR\npreventing using Discover saved objects with adhoc data
views\nin\\r\\naggregation based visualisations.\\r\\n\\r\\n### Test
notes \\r\\n-\nCreate Saved search based on adhoc data view in
Discover\\r\\n- Open new\nAgg based visualisations list and choose
one\\r\\n- Created Saved search\nshouldn't appear in the list.
\\r\\n\\r\\n### Checklist\\r\\n\\r\\n\\r\\n- [ ]\n[Unit
or\nfunctional\\r\\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\\r\\nwere\nupdated
or added to match the most
common\nscenarios\",\"sha\":\"2c9043ab431cebbbdeb77c96aa2a5c0bc5b0ddf4\"}},\"sourceBranch\":\"main\",\"suggestedTargetBranches\":[\"8.6\",\"8.5\"],\"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/145583\",\"number\":145583,\"mergeCommit\":{\"message\":\"[Discover]\nPrevent
agg based visualizations of Discover saved objects with adhoc\ndata
views (#145583)\\n\\n## Summary\\r\\n\\r\\nFixes #141812\\r\\n\\r\\nThis
PR\npreventing using Discover saved objects with adhoc data
views\nin\\r\\naggregation based visualisations.\\r\\n\\r\\n### Test
notes \\r\\n-\nCreate Saved search based on adhoc data view in
Discover\\r\\n- Open new\nAgg based visualisations list and choose
one\\r\\n- Created Saved search\nshouldn't appear in the list.
\\r\\n\\r\\n### Checklist\\r\\n\\r\\n\\r\\n- [ ]\n[Unit
or\nfunctional\\r\\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\\r\\nwere\nupdated
or added to match the most
common\nscenarios\",\"sha\":\"2c9043ab431cebbbdeb77c96aa2a5c0bc5b0ddf4\"}},{\"branch\":\"8.5\",\"label\":\"v8.5.2\",\"labelRegex\":\"^v(\\\\d+).(\\\\d+).\\\\d+$\",\"isSourceBranch\":false,\"state\":\"NOT_CREATED\"}]}]\nBACKPORT-->\n\nCo-authored-by:
Dmitry Tomashevich
<[email protected]>"}},{"branch":"main","label":"v8.7.0","labelRegex":"^v8.7.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/145583","number":145583,"mergeCommit":{"message":"[Discover]
Prevent agg based visualizations of Discover saved objects with adhoc
data views (#145583)\n\n## Summary\r\n\r\nFixes #141812\r\n\r\nThis PR
preventing using Discover saved objects with adhoc data views
in\r\naggregation based visualisations.\r\n\r\n### Test notes \r\n-
Create Saved search based on adhoc data view in Discover\r\n- Open new
Agg based visualisations list and choose one\r\n- Created Saved search
shouldn't appear in the list. \r\n\r\n### Checklist\r\n\r\n\r\n- [ ]
[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","sha":"2c9043ab431cebbbdeb77c96aa2a5c0bc5b0ddf4"}},{"branch":"8.5","label":"v8.5.2","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
dimaanj and kibanamachine authored Nov 28, 2022
1 parent 98ad8a4 commit 8af4e2e
Show file tree
Hide file tree
Showing 12 changed files with 93 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ export async function persistSavedSearch(
savedSearch.isTextBasedQuery = isTextBasedQuery;
}

savedSearch.usesAdHocDataView = !dataView.isPersisted();

const { from, to } = services.timefilter.getTime();
const refreshInterval = services.timefilter.getRefreshInterval();
savedSearch.timeRange =
Expand Down
6 changes: 5 additions & 1 deletion src/plugins/saved_objects/public/finder/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@
* Side Public License, v 1.
*/

export type { SavedObjectMetaData, SavedObjectFinderUiProps } from './saved_object_finder';
export type {
SavedObjectMetaData,
SavedObjectFinderUiProps,
FinderAttributes,
} from './saved_object_finder';
export { SavedObjectFinderUi, getSavedObjectFinder } from './saved_object_finder';
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export interface SavedObjectMetaData<T = unknown> {
defaultSearchField?: string;
}

interface FinderAttributes {
export interface FinderAttributes {
title?: string;
name?: string;
type: string;
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/saved_objects/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { SavedObjectsPublicPlugin } from './plugin';

export type { OnSaveProps, OriginSaveModalProps, SaveModalState, SaveResult } from './save_modal';
export { SavedObjectSaveModal, SavedObjectSaveModalOrigin, showSaveModal } from './save_modal';
export type { SavedObjectFinderUiProps, SavedObjectMetaData } from './finder';
export type { SavedObjectFinderUiProps, SavedObjectMetaData, FinderAttributes } from './finder';
export { getSavedObjectFinder, SavedObjectFinderUi } from './finder';
export type {
SavedObjectDecorator,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ describe('getSavedSearch', () => {
"timeRange": undefined,
"timeRestore": undefined,
"title": "test1",
"usesAdHocDataView": undefined,
"viewMode": undefined,
}
`);
Expand Down Expand Up @@ -251,6 +252,7 @@ describe('getSavedSearch', () => {
"timeRange": undefined,
"timeRestore": undefined,
"title": "test2",
"usesAdHocDataView": undefined,
"viewMode": undefined,
}
`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ describe('saved_searches_utils', () => {
grid: {},
hideChart: true,
isTextBasedQuery: false,
usesAdHocDataView: false,
};

expect(
Expand Down Expand Up @@ -81,6 +82,7 @@ describe('saved_searches_utils', () => {
"timeRange": undefined,
"timeRestore": undefined,
"title": "saved search",
"usesAdHocDataView": false,
"viewMode": undefined,
}
`);
Expand Down Expand Up @@ -121,6 +123,7 @@ describe('saved_searches_utils', () => {
grid: {},
hideChart: true,
isTextBasedQuery: true,
usesAdHocDataView: false,
};

expect(toSavedSearchAttributes(savedSearch, '{}')).toMatchInlineSnapshot(`
Expand Down Expand Up @@ -149,6 +152,7 @@ describe('saved_searches_utils', () => {
"timeRange": undefined,
"timeRestore": false,
"title": "title",
"usesAdHocDataView": false,
"viewMode": undefined,
}
`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const fromSavedSearchAttributes = (
hideAggregatedPreview: attributes.hideAggregatedPreview,
rowHeight: attributes.rowHeight,
isTextBasedQuery: attributes.isTextBasedQuery,
usesAdHocDataView: attributes.usesAdHocDataView,
timeRestore: attributes.timeRestore,
timeRange: attributes.timeRange,
refreshInterval: attributes.refreshInterval,
Expand All @@ -66,6 +67,7 @@ export const toSavedSearchAttributes = (
hideAggregatedPreview: savedSearch.hideAggregatedPreview,
rowHeight: savedSearch.rowHeight,
isTextBasedQuery: savedSearch.isTextBasedQuery ?? false,
usesAdHocDataView: savedSearch.usesAdHocDataView,
timeRestore: savedSearch.timeRestore ?? false,
timeRange: savedSearch.timeRange,
refreshInterval: savedSearch.refreshInterval,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface SavedSearchAttributes {
};
hideChart: boolean;
isTextBasedQuery: boolean;
usesAdHocDataView?: boolean;
kibanaSavedObjectMeta: {
searchSourceJSON: string;
};
Expand Down Expand Up @@ -73,6 +74,7 @@ export interface SavedSearch {
hideAggregatedPreview?: boolean;
rowHeight?: number;
isTextBasedQuery?: boolean;
usesAdHocDataView?: boolean;

// for restoring time range with a saved search
timeRestore?: boolean;
Expand Down
1 change: 1 addition & 0 deletions src/plugins/saved_search/server/saved_objects/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export function getSavedSearchObjectType(
viewMode: { type: 'keyword', index: false, doc_values: false },
hideChart: { type: 'boolean', index: false, doc_values: false },
isTextBasedQuery: { type: 'boolean', index: false, doc_values: false },
usesAdHocDataView: { type: 'boolean', index: false, doc_values: false },
hideAggregatedPreview: { type: 'boolean', index: false, doc_values: false },
hits: { type: 'integer', index: false, doc_values: false },
kibanaSavedObjectMeta: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
* Side Public License, v 1.
*/

import React from 'react';
import { EuiModalBody, EuiModalHeader, EuiModalHeaderTitle } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
import type { SimpleSavedObject, SavedObjectAttributes } from '@kbn/core/public';
import React from 'react';
import { IUiSettingsClient, SavedObjectsStart } from '@kbn/core/public';

import { SavedObjectFinderUi } from '@kbn/saved-objects-plugin/public';
import type { BaseVisType } from '../../vis_types';
import { DialogNavigation } from '../dialog_navigation';
import { showSavedObject } from './show_saved_object';

interface SearchSelectionProps {
onSearchSelected: (searchId: string, searchType: string) => void;
Expand All @@ -24,9 +24,6 @@ interface SearchSelectionProps {
savedObjects: SavedObjectsStart;
goBack: () => void;
}
interface SavedSearchesAttributes extends SavedObjectAttributes {
isTextBasedQuery: boolean;
}

export class SearchSelection extends React.Component<SearchSelectionProps> {
private fixedPageSize: number = 8;
Expand Down Expand Up @@ -71,11 +68,8 @@ export class SearchSelection extends React.Component<SearchSelectionProps> {
}
),
// ignore the saved searches that have text-based languages queries
includeFields: ['isTextBasedQuery'],
showSavedObject: (savedObject) => {
const so = savedObject as unknown as SimpleSavedObject<SavedSearchesAttributes>;
return !so.attributes.isTextBasedQuery;
},
includeFields: ['isTextBasedQuery', 'usesAdHocDataView'],
showSavedObject,
},
{
type: 'index-pattern',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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 type { SimpleSavedObject } from '@kbn/core/public';
import type { FinderAttributes } from '@kbn/saved-objects-plugin/public';
import { showSavedObject } from './show_saved_object';

describe('showSavedObject', () => {
it('should return true if the saved object is not a text based query', () => {
const savedObject = {
attributes: { isTextBasedQuery: false },
};
expect(showSavedObject(savedObject as unknown as SimpleSavedObject<FinderAttributes>)).toBe(
true
);
});

it('should return false if the saved object is a text based query', () => {
const savedObject = {
attributes: { isTextBasedQuery: true },
};
expect(showSavedObject(savedObject as unknown as SimpleSavedObject<FinderAttributes>)).toBe(
false
);
});

it('should return true if the saved object is not of an adhoc data view', () => {
const savedObject = {
attributes: { usesAdHocDataView: false },
};
expect(showSavedObject(savedObject as unknown as SimpleSavedObject<FinderAttributes>)).toBe(
true
);
});

it('should return false if the saved object is of an adhoc data view', () => {
const savedObject = {
attributes: { usesAdHocDataView: true },
};
expect(showSavedObject(savedObject as unknown as SimpleSavedObject<FinderAttributes>)).toBe(
false
);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* 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 type { SimpleSavedObject, SavedObjectAttributes } from '@kbn/core/public';
import type { FinderAttributes } from '@kbn/saved-objects-plugin/public';

export interface SavedSearchesAttributes extends SavedObjectAttributes {
isTextBasedQuery: boolean;
usesAdHocDataView?: boolean;
}

export const showSavedObject = (savedObject: SimpleSavedObject<FinderAttributes>) => {
const so = savedObject as unknown as SimpleSavedObject<SavedSearchesAttributes>;
return !so.attributes.isTextBasedQuery && !so.attributes.usesAdHocDataView;
};

0 comments on commit 8af4e2e

Please sign in to comment.