Make SavedObjectFinder backward compatible (#162904)

## Summary

close https://github.com/elastic/kibana/issues/161545
close https://github.com/elastic/kibana/issues/153257

This PR makes `SavedObjectFinder` component backward compatible. It is
achieved by going through content- management layer, more technical
details
[here](https://docs.google.com/document/d/1ssYmqSEUPrsuCR4iz8DohkEWekoYrm2yL4QR_fVxXLg/edit)

### Testing

`SavedObjectFinder` is this component that allows to pick a saved object
(supports: `search` `index-pattern` `map` `visualization` `lens`
`event-annotation-group`:

![Screenshot 2023-08-07 at 16 53
32](5c283ea5-3682-4dc8-a8ff-422e6f4f3195)


It is used in the following places: 

- Dashboard 
  - Add panel
  - Replace panel 
- Discover - Open Search 
- Visualization - Select search as a source for new viz
- Graph - select source
- Cases - markdown editor add lens 
- ML (3 places) 
- Canvas - select embeddable panel 
- Transform 
- Lens > select event annotation 




### Risks / Follow up 

The `SavedObjectFinder` should stay mostly the same, the only notable
functional change is that now `SavedObjectFinder` doesn't support
`includeFields` which allowed partial saved object returns, this was
done to make the call backward-compatible without making the system even
more complicated as otherwise we'll need a way to abstract
`includeFields` from so attributes and allow to run migrations on it
before making a search. follow up issue to bring it back
https://github.com/elastic/kibana/issues/163043

The risk with that is that some client that have a lot of large objects
might run into performance issues when using `SavedObjectFinder`. This
can be mitigated by changing listing limit in advanced setting from
default 1000 to something lower
This commit is contained in:
Anton Dosov 2023-08-08 13:10:29 +02:00 committed by GitHub
parent 863ea15bde
commit 304cb256cf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
98 changed files with 636 additions and 938 deletions

View file

@ -12,6 +12,7 @@
"developerExamples",
"kibanaReact",
"savedObjectsTaggingOss"
]
],
"requiredBundles": ["savedObjectsFinder"]
}
}

View file

@ -0,0 +1,70 @@
/*
* 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 React from 'react';
import { ContentClientProvider, type ContentClient } from '@kbn/content-management-plugin/public';
import type { CoreStart } from '@kbn/core/public';
import { I18nProvider } from '@kbn/i18n-react';
import { SavedObjectTaggingOssPluginStart } from '@kbn/saved-objects-tagging-oss-plugin/public';
import { SavedObjectFinder } from '@kbn/saved-objects-finder-plugin/public';
export const FinderApp = (props: {
contentClient: ContentClient;
core: CoreStart;
savedObjectsTagging: SavedObjectTaggingOssPluginStart;
}) => {
return (
<ContentClientProvider contentClient={props.contentClient}>
<I18nProvider>
<SavedObjectFinder
showFilter={true}
services={{
savedObjectsTagging: props.savedObjectsTagging.getTaggingApi(),
contentClient: props.contentClient,
uiSettings: props.core.uiSettings,
}}
onChoose={(...args) => {
alert(JSON.stringify(args));
}}
savedObjectMetaData={[
{
type: `search`,
getIconForSavedObject: () => 'discoverApp',
name: 'Saved search',
},
{
type: 'index-pattern',
getIconForSavedObject: () => 'indexPatternApp',
name: 'Data view',
},
{
type: `visualization`,
getIconForSavedObject: () => 'visualizeApp',
name: 'Visualization',
},
{
type: 'lens',
getIconForSavedObject: () => 'lensApp',
name: 'Lens',
},
{
type: 'map',
getIconForSavedObject: () => 'logoMaps',
name: 'Map',
},
{
type: 'event-annotation-group',
getIconForSavedObject: () => 'annotation',
name: 'Annotation',
},
]}
/>
</I18nProvider>
</ContentClientProvider>
);
};

View file

@ -0,0 +1,9 @@
/*
* 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.
*/
export { FinderApp } from './finder_app';

View file

@ -16,6 +16,7 @@ import { AppMountParameters, CoreStart } from '@kbn/core/public';
import { StartDeps } from '../types';
import { TodoApp } from './todos';
import { MSearchApp } from './msearch';
import { FinderApp } from './finder';
export const renderApp = (
core: CoreStart,
@ -45,6 +46,12 @@ export const renderApp = (
'data-test-subj': 'msearchExample',
href: '/app/contentManagementExamples/msearch',
},
{
id: 'finder',
name: 'Finder',
'data-test-subj': 'finderExample',
href: '/app/contentManagementExamples/finder',
},
],
},
]}
@ -64,6 +71,13 @@ export const renderApp = (
savedObjectsTagging={savedObjectsTaggingOss}
/>
</Route>
<Route path="/finder">
<FinderApp
contentClient={contentManagement.client}
core={core}
savedObjectsTagging={savedObjectsTaggingOss}
/>
</Route>
</Routes>
</EuiPageTemplate.Section>
</EuiPageTemplate>

View file

@ -26,14 +26,20 @@ export const MSearchTable = () => {
const { hits, pagination } = await contentClient.mSearch<UserContentCommonSchema>({
query: {
text: searchQuery,
limit: LISTING_LIMIT,
cursor: '1',
tags: {
included: refs?.references?.map((ref) => ref.id),
excluded: refs?.referencesToExclude?.map((ref) => ref.id),
},
},
contentTypes: [{ contentTypeId: 'map' }], // TODO: improve types to not require objects here?
contentTypes: [
{ contentTypeId: 'map' },
{ contentTypeId: 'dashboard' },
{ contentTypeId: 'visualization' },
{ contentTypeId: 'lens' },
{ contentTypeId: 'search' },
{ contentTypeId: 'index-pattern' },
{ contentTypeId: 'event-annotation-group' },
], // TODO: improve types to not require objects here?
});
// TODO: needs to have logic of extracting common schema from an unknown mSearch hit: hits.map(hit => cm.convertToCommonSchema(hit))

View file

@ -29,5 +29,6 @@
"@kbn/content-management-table-list-view-table",
"@kbn/content-management-table-list-view",
"@kbn/shared-ux-router",
"@kbn/saved-objects-finder-plugin",
]
}