Skip to content

Commit

Permalink
[SavedObjectsFinder] Replace the component in Visualizations plugin (#…
Browse files Browse the repository at this point in the history
…152705)

## Summary

This PR replaces the SavedObjectsFinder component from saved_objects
plugin with the one in saved_objects_finder plugin. This is a part of
making the component BWCA compliant
[effort](#150604).


### Checklist

Delete any items that are not applicable to this PR.

~- [] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)~
~- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials~
- [X] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
~- [ ] Any UI touched in this PR is usable by keyboard only (learn more
about [keyboard
accessibility](https://webaim.org/techniques/keyboard/))~
~- [ ] Any UI touched in this PR does not create any new axe failures
(run axe in browser:
[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),
[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))~
~- [ ] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)~
~- [ ] This renders correctly on smaller devices using a responsive
layout. (You can test this [in your
browser](https://www.browserstack.com/guide/responsive-testing-on-local-server))~
~- [ ] This was checked for [cross-browser
compatibility](https://www.elastic.co/support/matrix#matrix_browsers)~


### For maintainers

- [ ] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

---------

Co-authored-by: kibanamachine <[email protected]>
  • Loading branch information
Maja Grubic and kibanamachine authored Mar 8, 2023
1 parent 662689b commit 6b3d894
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 11 deletions.
4 changes: 3 additions & 1 deletion src/plugins/visualizations/kibana.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
"dataViews",
"dataViewEditor",
"unifiedSearch",
"usageCollection"
"usageCollection",
"savedObjectsFinder",
"savedObjectsManagement",
],
"optionalPlugins": [
"home",
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/visualizations/public/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { savedObjectTaggingOssPluginMock } from '@kbn/saved-objects-tagging-oss-
import { screenshotModePluginMock } from '@kbn/screenshot-mode-plugin/public/mocks';
import { fieldFormatsServiceMock } from '@kbn/field-formats-plugin/public/mocks';
import { unifiedSearchPluginMock } from '@kbn/unified-search-plugin/public/mocks';
import { savedObjectsManagementPluginMock } from '@kbn/saved-objects-management-plugin/public/mocks';
import { VisualizationsPlugin } from './plugin';
import { Schemas } from './vis_types';
import { Schema, VisualizationsSetup, VisualizationsStart } from '.';
Expand Down Expand Up @@ -80,6 +81,7 @@ const createInstance = async () => {
usageCollection: {
reportUiCounter: jest.fn(),
},
savedObjectsManagement: savedObjectsManagementPluginMock.createStartContract(),
});

return {
Expand Down
5 changes: 5 additions & 0 deletions src/plugins/visualizations/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import type { ScreenshotModePluginStart } from '@kbn/screenshot-mode-plugin/publ
import type { HomePublicPluginSetup } from '@kbn/home-plugin/public';
import type { SpacesPluginStart } from '@kbn/spaces-plugin/public';
import type { DataViewEditorStart } from '@kbn/data-view-editor-plugin/public';
import { SavedObjectsManagementPluginStart } from '@kbn/saved-objects-management-plugin/public';
import type { TypesSetup, TypesStart } from './vis_types';
import type { VisualizeServices } from './visualize_app/types';
import {
Expand Down Expand Up @@ -98,6 +99,7 @@ import {
setFieldFormats,
setSavedObjectTagging,
setUsageCollection,
setSavedObjectsManagement,
} from './services';
import { VisualizeConstants } from '../common/constants';
import { EditInLensAction } from './actions/edit_in_lens_action';
Expand Down Expand Up @@ -147,6 +149,7 @@ export interface VisualizationsStartDeps {
fieldFormats: FieldFormatsStart;
unifiedSearch: UnifiedSearchPublicPluginStart;
usageCollection: UsageCollectionStart;
savedObjectsManagement: SavedObjectsManagementPluginStart;
}

/**
Expand Down Expand Up @@ -379,6 +382,7 @@ export class VisualizationsPlugin
savedObjectsTaggingOss,
fieldFormats,
usageCollection,
savedObjectsManagement,
}: VisualizationsStartDeps
): VisualizationsStart {
const types = this.types.start();
Expand All @@ -399,6 +403,7 @@ export class VisualizationsPlugin
setChrome(core.chrome);
setFieldFormats(fieldFormats);
setUsageCollection(usageCollection);
setSavedObjectsManagement(savedObjectsManagement);

if (spaces) {
setSpaces(spaces);
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/visualizations/public/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import type { EmbeddableStart } from '@kbn/embeddable-plugin/public';
import type { SpacesPluginStart } from '@kbn/spaces-plugin/public';
import type { SavedObjectTaggingOssPluginStart } from '@kbn/saved-objects-tagging-oss-plugin/public';
import type { UsageCollectionStart } from '@kbn/usage-collection-plugin/public';
import { SavedObjectsManagementPluginStart } from '@kbn/saved-objects-management-plugin/public';
import type { TypesStart } from './vis_types';

export const [getUISettings, setUISettings] = createGetterSetter<IUiSettingsClient>('UISettings');
Expand Down Expand Up @@ -76,3 +77,6 @@ export const [getSavedObjectTagging, setSavedObjectTagging] =

export const [getUsageCollection, setUsageCollection] =
createGetterSetter<UsageCollectionStart>('UsageCollection');

export const [getSavedObjectsManagement, setSavedObjectsManagement] =
createGetterSetter<SavedObjectsManagementPluginStart>('SavedObjectsManagement');
10 changes: 10 additions & 0 deletions src/plugins/visualizations/public/wizard/new_vis_modal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import NewVisModal from './new_vis_modal';
import { ApplicationStart, DocLinksStart } from '@kbn/core/public';
import { embeddablePluginMock } from '@kbn/embeddable-plugin/public/mocks';
import { httpServiceMock } from '@kbn/core-http-browser-mocks';
import { savedObjectsManagementPluginMock } from '@kbn/saved-objects-management-plugin/public/mocks';

describe('NewVisModal', () => {
const defaultVisTypeParams = {
Expand Down Expand Up @@ -77,6 +78,7 @@ describe('NewVisModal', () => {
},
};
const http = httpServiceMock.createStartContract({ basePath: '' });
const savedObjectsManagement = savedObjectsManagementPluginMock.createStartContract();

beforeAll(() => {
Object.defineProperty(window, 'location', {
Expand All @@ -101,6 +103,7 @@ describe('NewVisModal', () => {
application={{} as ApplicationStart}
docLinks={docLinks as DocLinksStart}
http={http}
savedObjectsManagement={savedObjectsManagement}
/>
);
expect(wrapper.find('[data-test-subj="visGroup-aggbased"]').exists()).toBe(true);
Expand All @@ -118,6 +121,7 @@ describe('NewVisModal', () => {
application={{} as ApplicationStart}
docLinks={docLinks as DocLinksStart}
http={http}
savedObjectsManagement={savedObjectsManagement}
/>
);
expect(wrapper.find('[data-test-subj="visGroup-tools"]').exists()).toBe(true);
Expand All @@ -134,6 +138,7 @@ describe('NewVisModal', () => {
application={{} as ApplicationStart}
docLinks={docLinks as DocLinksStart}
http={http}
savedObjectsManagement={savedObjectsManagement}
/>
);
expect(wrapper.find('[data-test-subj="visType-vis2"]').exists()).toBe(true);
Expand All @@ -151,6 +156,7 @@ describe('NewVisModal', () => {
application={{} as ApplicationStart}
docLinks={docLinks as DocLinksStart}
http={http}
savedObjectsManagement={savedObjectsManagement}
/>
);
const visCard = wrapper.find('[data-test-subj="visType-vis"]').last();
Expand All @@ -170,6 +176,7 @@ describe('NewVisModal', () => {
application={{} as ApplicationStart}
docLinks={docLinks as DocLinksStart}
http={http}
savedObjectsManagement={savedObjectsManagement}
/>
);
const visCard = wrapper.find('[data-test-subj="visType-vis"]').last();
Expand All @@ -196,6 +203,7 @@ describe('NewVisModal', () => {
docLinks={docLinks as DocLinksStart}
stateTransfer={stateTransfer}
http={http}
savedObjectsManagement={savedObjectsManagement}
/>
);
const visCard = wrapper.find('[data-test-subj="visType-visWithAliasUrl"]').last();
Expand All @@ -221,6 +229,7 @@ describe('NewVisModal', () => {
application={{ navigateToApp } as unknown as ApplicationStart}
docLinks={docLinks as DocLinksStart}
http={http}
savedObjectsManagement={savedObjectsManagement}
/>
);
const visCard = wrapper.find('[data-test-subj="visType-visWithAliasUrl"]').last();
Expand All @@ -242,6 +251,7 @@ describe('NewVisModal', () => {
application={{} as ApplicationStart}
docLinks={docLinks as DocLinksStart}
http={http}
savedObjectsManagement={savedObjectsManagement}
/>
);
const aggBasedGroupCard = wrapper
Expand Down
3 changes: 3 additions & 0 deletions src/plugins/visualizations/public/wizard/new_vis_modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { i18n } from '@kbn/i18n';
import { METRIC_TYPE, UiCounterMetricType } from '@kbn/analytics';
import { ApplicationStart, IUiSettingsClient, DocLinksStart, HttpStart } from '@kbn/core/public';
import { EmbeddableStateTransfer } from '@kbn/embeddable-plugin/public';
import { SavedObjectsManagementPluginStart } from '@kbn/saved-objects-management-plugin/public';
import { SearchSelection } from './search_selection';
import { GroupSelection } from './group_selection';
import { AggBasedSelection } from './agg_based_selection';
Expand All @@ -36,6 +37,7 @@ interface TypeSelectionProps {
originatingApp?: string;
showAggsSelection?: boolean;
selectedVisType?: BaseVisType;
savedObjectsManagement: SavedObjectsManagementPluginStart;
}

interface TypeSelectionState {
Expand Down Expand Up @@ -93,6 +95,7 @@ class NewVisModal extends React.Component<TypeSelectionProps, TypeSelectionState
visType={this.state.visType}
uiSettings={this.props.uiSettings}
http={this.props.http}
savedObjectsManagement={this.props.savedObjectsManagement}
goBack={() => this.setState({ showSearchVisModal: false })}
/>
</EuiModal>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
import { IUiSettingsClient, HttpStart } from '@kbn/core/public';

import { SavedObjectFinderUi } from '@kbn/saved-objects-plugin/public';
import { SavedObjectsManagementPluginStart } from '@kbn/saved-objects-management-plugin/public';
import { SavedObjectFinder } from '@kbn/saved-objects-finder-plugin/public';
import type { BaseVisType } from '../../vis_types';
import { DialogNavigation } from '../dialog_navigation';
import { showSavedObject } from './show_saved_object';
Expand All @@ -22,12 +23,12 @@ interface SearchSelectionProps {
visType: BaseVisType;
uiSettings: IUiSettingsClient;
http: HttpStart;
savedObjectsManagement: SavedObjectsManagementPluginStart;
goBack: () => void;
}

export class SearchSelection extends React.Component<SearchSelectionProps> {
private fixedPageSize: number = 8;

public render() {
return (
<React.Fragment>
Expand All @@ -47,7 +48,7 @@ export class SearchSelection extends React.Component<SearchSelectionProps> {
</EuiModalHeader>
<EuiModalBody>
<DialogNavigation goBack={this.props.goBack} />
<SavedObjectFinderUi
<SavedObjectFinder
key="searchSavedObjectFinder"
onChoose={this.props.onSearchSelected}
showFilter
Expand Down Expand Up @@ -84,8 +85,11 @@ export class SearchSelection extends React.Component<SearchSelectionProps> {
},
]}
fixedPageSize={this.fixedPageSize}
uiSettings={this.props.uiSettings}
http={this.props.http}
services={{
uiSettings: this.props.uiSettings,
http: this.props.http,
savedObjectsManagement: this.props.savedObjectsManagement,
}}
/>
</EuiModalBody>
</React.Fragment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
* Side Public License, v 1.
*/

import type { SimpleSavedObject, SavedObjectAttributes } from '@kbn/core/public';
import type { FinderAttributes } from '@kbn/saved-objects-plugin/public';
import type { SavedObjectCommon, FinderAttributes } from '@kbn/saved-objects-finder-plugin/common';

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

export const showSavedObject = (savedObject: SimpleSavedObject<FinderAttributes>) => {
const so = savedObject as unknown as SimpleSavedObject<SavedSearchesAttributes>;
export const showSavedObject = (savedObject: SavedObjectCommon<FinderAttributes>) => {
const so = savedObject as unknown as SavedObjectCommon<SavedSearchesAttributes>;
return !so.attributes.isTextBasedQuery && !so.attributes.usesAdHocDataView;
};
2 changes: 2 additions & 0 deletions src/plugins/visualizations/public/wizard/show_new_vis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
getEmbeddable,
getDocLinks,
getTheme,
getSavedObjectsManagement,
} from '../services';
import type { BaseVisType } from '../vis_types';

Expand Down Expand Up @@ -81,6 +82,7 @@ export function showNewVisModal({
addBasePath={getHttp().basePath.prepend}
uiSettings={getUISettings()}
http={getHttp()}
savedObjectsManagement={getSavedObjectsManagement()}
application={getApplication()}
docLinks={getDocLinks()}
showAggsSelection={showAggsSelection}
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/visualizations/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
"@kbn/usage-collection-plugin",
"@kbn/core-http-browser-mocks",
"@kbn/shared-ux-router",
"@kbn/saved-objects-management-plugin",
"@kbn/saved-objects-finder-plugin",
],
"exclude": [
"target/**/*",
Expand Down

0 comments on commit 6b3d894

Please sign in to comment.