[8.6] [Discover] Prevent agg based visualizations of Discover saved objects with adhoc data views (#145583) (#146344)

# Backport

This will backport the following commits from `main` to `8.6`:
- [[Discover] Prevent agg based visualizations of Discover saved objects
with adhoc data views
(#145583)](https://github.com/elastic/kibana/pull/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":"39378793+dimaanj@users.noreply.github.com"},"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.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]
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: Dmitry Tomashevich <39378793+dimaanj@users.noreply.github.com>
This commit is contained in:
Kibana Machine 2022-11-25 09:23:13 -05:00 committed by GitHub
parent 0a3b9e44eb
commit 461c04ec6c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 94 additions and 14 deletions

View file

@ -119,7 +119,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
"osquery-saved-query": "7b213b4b7a3e59350e99c50e8df9948662ed493a",
"query": "4640ef356321500a678869f24117b7091a911cb6",
"sample-data-telemetry": "8b10336d9efae6f3d5593c4cc89fb4abcdf84e04",
"search": "e7ba25ea37cb36b622db42c9590c6d8dfc838801",
"search": "d26771bcf7cd271162aab3a610b75249631ef6b1",
"search-session": "ba383309da68a15be3765977f7a44c84f0ec7964",
"search-telemetry": "beb3fc25488c753f2a6dcff1845d667558712b66",
"security-rule": "e0dfdba5d66139d0300723b2e6672993cd4a11f3",

View file

@ -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 =

View file

@ -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';

View file

@ -51,7 +51,7 @@ export interface SavedObjectMetaData<T = unknown> {
defaultSearchField?: string;
}
interface FinderAttributes {
export interface FinderAttributes {
title?: string;
name?: string;
type: string;

View file

@ -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,

View file

@ -154,6 +154,7 @@ describe('getSavedSearch', () => {
"timeRange": undefined,
"timeRestore": undefined,
"title": "test1",
"usesAdHocDataView": undefined,
"viewMode": undefined,
}
`);
@ -251,6 +252,7 @@ describe('getSavedSearch', () => {
"timeRange": undefined,
"timeRestore": undefined,
"title": "test2",
"usesAdHocDataView": undefined,
"viewMode": undefined,
}
`);

View file

@ -28,6 +28,7 @@ describe('saved_searches_utils', () => {
grid: {},
hideChart: true,
isTextBasedQuery: false,
usesAdHocDataView: false,
};
expect(
@ -81,6 +82,7 @@ describe('saved_searches_utils', () => {
"timeRange": undefined,
"timeRestore": undefined,
"title": "saved search",
"usesAdHocDataView": false,
"viewMode": undefined,
}
`);
@ -121,6 +123,7 @@ describe('saved_searches_utils', () => {
grid: {},
hideChart: true,
isTextBasedQuery: true,
usesAdHocDataView: false,
};
expect(toSavedSearchAttributes(savedSearch, '{}')).toMatchInlineSnapshot(`
@ -149,6 +152,7 @@ describe('saved_searches_utils', () => {
"timeRange": undefined,
"timeRestore": false,
"title": "title",
"usesAdHocDataView": false,
"viewMode": undefined,
}
`);

View file

@ -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,
@ -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,

View file

@ -33,6 +33,7 @@ export interface SavedSearchAttributes {
};
hideChart: boolean;
isTextBasedQuery: boolean;
usesAdHocDataView?: boolean;
kibanaSavedObjectMeta: {
searchSourceJSON: string;
};
@ -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;

View file

@ -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: {

View file

@ -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;
@ -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;
@ -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',

View file

@ -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
);
});
});

View file

@ -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;
};