Skip to content

Commit

Permalink
Removing stateful saved object finder (elastic#52166)
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 authored and timductive committed Dec 16, 2019
1 parent 21cd68f commit 9102d82
Show file tree
Hide file tree
Showing 28 changed files with 196 additions and 202 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import {
AppStateClass as TAppStateClass,
KbnUrl,
SaveOptions,
SavedObjectFinder,
unhashUrl,
} from './legacy_imports';
import { FilterStateManager, IndexPattern } from '../../../data/public';
Expand Down Expand Up @@ -70,6 +69,10 @@ import { DashboardAppScope } from './dashboard_app';
import { VISUALIZE_EMBEDDABLE_TYPE } from '../visualize/embeddable';
import { convertSavedDashboardPanelToPanelState } from './lib/embeddable_saved_object_converters';
import { RenderDeps } from './application';
import {
SavedObjectFinderProps,
SavedObjectFinderUi,
} from '../../../../../plugins/kibana_react/public';

export interface DashboardAppControllerDependencies extends RenderDeps {
$scope: DashboardAppScope;
Expand Down Expand Up @@ -114,7 +117,7 @@ export class DashboardAppController {
timefilter: { timefilter },
},
},
core: { notifications, overlays, chrome, injectedMetadata },
core: { notifications, overlays, chrome, injectedMetadata, uiSettings, savedObjects },
}: DashboardAppControllerDependencies) {
new FilterStateManager(globalState, getAppState, filterManager);
const queryFilter = filterManager;
Expand Down Expand Up @@ -741,6 +744,10 @@ export class DashboardAppController {
};
navActions[TopNavIds.ADD] = () => {
if (dashboardContainer && !isErrorEmbeddable(dashboardContainer)) {
const SavedObjectFinder = (props: SavedObjectFinderProps) => (
<SavedObjectFinderUi {...props} savedObjects={savedObjects} uiSettings={uiSettings} />
);

openAddPanelFlyout({
embeddable: dashboardContainer,
getAllFactories: embeddables.getEmbeddableFactories,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,3 @@ export { stateMonitorFactory, StateMonitor } from 'ui/state_management/state_mon
export { ensureDefaultIndexPattern } from 'ui/legacy_compat';
export { unhashUrl } from '../../../../../plugins/kibana_utils/public';
export { IInjector } from 'ui/chrome';
export { SavedObjectFinder } from 'ui/saved_objects/components/saved_object_finder';

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,16 @@ import {
EuiFlyoutBody,
EuiTitle,
} from '@elastic/eui';
import { SavedObjectFinder } from 'ui/saved_objects/components/saved_object_finder';
import { SavedObjectFinderUi } from '../../../../../../../plugins/kibana_react/public';
import { getServices } from '../../kibana_services';

const SEARCH_OBJECT_TYPE = 'search';

export function OpenSearchPanel(props) {
const {
core: { uiSettings, savedObjects },
} = getServices();

return (
<EuiFlyout ownFocus onClose={props.onClose} data-test-subj="loadSearchForm">
<EuiFlyoutHeader hasBorder>
Expand All @@ -50,7 +55,7 @@ export function OpenSearchPanel(props) {
</EuiTitle>
</EuiFlyoutHeader>
<EuiFlyoutBody>
<SavedObjectFinder
<SavedObjectFinderUi
noItemsMessage={
<FormattedMessage
id="kbn.discover.topNav.openSearchPanel.noSearchesFoundDescription"
Expand All @@ -70,6 +75,8 @@ export function OpenSearchPanel(props) {
window.location.assign(props.makeUrl(id));
props.onClose();
}}
uiSettings={uiSettings}
savedObjects={savedObjects}
/>
</EuiFlyoutBody>
<EuiFlyoutFooter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { shallow } from 'enzyme';
jest.mock('../../kibana_services', () => {
return {
getServices: () => ({
SavedObjectFinder: jest.fn()
core: { uiSettings: {}, savedObjects: {} },
}),
};
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ export class VisualizeEmbeddableFactory extends EmbeddableFactory<
editorParams: ['addToDashboard'],
},
npStart.core.http.basePath.prepend,
npStart.core.uiSettings
npStart.core.uiSettings,
npStart.core.savedObjects
);
}
return undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export { PrivateProvider } from 'ui/private/private';

export { SavedObjectRegistryProvider } from 'ui/saved_objects';
export { SavedObjectSaveModal } from 'ui/saved_objects/components/saved_object_save_modal';
export { SavedObjectFinder } from 'ui/saved_objects/components/saved_object_finder';
export { showSaveModal } from 'ui/saved_objects/show_saved_object_save_modal';

export { subscribeWithScope } from 'ui/utils/subscribe_with_scope';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
vis-types-registry="listingController.visTypeRegistry"
add-base-path="listingController.addBasePath"
ui-settings="listingController.uiSettings"
saved-objects="listingController.savedObjects"
></new-vis-modal>

</div>
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export function initListingDirective(app) {
['onClose', { watchDepth: 'reference' }],
['addBasePath', { watchDepth: 'reference' }],
['uiSettings', { watchDepth: 'reference' }],
['savedObjects', { watchDepth: 'reference' }],
'isOpen',
])
);
Expand All @@ -54,7 +55,7 @@ export function VisualizeListingController($injector, createNewVis) {
toastNotifications,
uiSettings,
visualizations,
core: { docLinks },
core: { docLinks, savedObjects },
} = getServices();
const kbnUrl = $injector.get('kbnUrl');

Expand All @@ -64,6 +65,7 @@ export function VisualizeListingController($injector, createNewVis) {
this.showNewVisModal = false;
this.addBasePath = addBasePath;
this.uiSettings = uiSettings;
this.savedObjects = savedObjects;

this.createNewVis = () => {
this.showNewVisModal = true;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jest.mock('../legacy_imports', () => ({
}));

import { NewVisModal } from './new_vis_modal';
import { SavedObjectsStart } from 'kibana/public';

describe('NewVisModal', () => {
const defaultVisTypeParams = {
Expand Down Expand Up @@ -76,6 +77,7 @@ describe('NewVisModal', () => {
visTypesRegistry={visTypes}
addBasePath={addBasePath}
uiSettings={uiSettings}
savedObjects={{} as SavedObjectsStart}
/>
);
expect(wrapper).toMatchSnapshot();
Expand All @@ -89,6 +91,7 @@ describe('NewVisModal', () => {
visTypesRegistry={visTypes}
addBasePath={addBasePath}
uiSettings={uiSettings}
savedObjects={{} as SavedObjectsStart}
/>
);
expect(wrapper.find('[data-test-subj="visType-vis"]').exists()).toBe(true);
Expand All @@ -104,6 +107,7 @@ describe('NewVisModal', () => {
visTypesRegistry={visTypes}
addBasePath={addBasePath}
uiSettings={uiSettings}
savedObjects={{} as SavedObjectsStart}
/>
);
const visButton = wrapper.find('button[data-test-subj="visType-vis"]');
Expand All @@ -121,6 +125,7 @@ describe('NewVisModal', () => {
editorParams={['foo=true', 'bar=42']}
addBasePath={addBasePath}
uiSettings={uiSettings}
savedObjects={{} as SavedObjectsStart}
/>
);
const visButton = wrapper.find('button[data-test-subj="visType-vis"]');
Expand All @@ -138,6 +143,7 @@ describe('NewVisModal', () => {
visTypesRegistry={visTypes}
addBasePath={addBasePath}
uiSettings={uiSettings}
savedObjects={{} as SavedObjectsStart}
/>
);
const searchBox = wrapper.find('input[data-test-subj="filterVisType"]');
Expand All @@ -156,6 +162,7 @@ describe('NewVisModal', () => {
visTypesRegistry={visTypes}
addBasePath={addBasePath}
uiSettings={uiSettings}
savedObjects={{} as SavedObjectsStart}
/>
);
expect(wrapper.find('[data-test-subj="visType-visExp"]').exists()).toBe(false);
Expand All @@ -170,6 +177,7 @@ describe('NewVisModal', () => {
visTypesRegistry={visTypes}
addBasePath={addBasePath}
uiSettings={uiSettings}
savedObjects={{} as SavedObjectsStart}
/>
);
expect(wrapper.find('[data-test-subj="visType-visExp"]').exists()).toBe(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import React from 'react';
import { EuiModal, EuiOverlayMask } from '@elastic/eui';
import { i18n } from '@kbn/i18n';

import { IUiSettingsClient } from 'kibana/public';
import { IUiSettingsClient, SavedObjectsStart } from 'kibana/public';
import { VisType } from '../legacy_imports';
import { VisualizeConstants } from '../visualize_constants';
import { createUiStatsReporter, METRIC_TYPE } from '../../../../ui_metric/public';
Expand All @@ -37,6 +37,7 @@ interface TypeSelectionProps {
editorParams?: string[];
addBasePath: (path: string) => string;
uiSettings: IUiSettingsClient;
savedObjects: SavedObjectsStart;
}

interface TypeSelectionState {
Expand Down Expand Up @@ -81,7 +82,12 @@ class NewVisModal extends React.Component<TypeSelectionProps, TypeSelectionState
const selectionModal =
this.state.showSearchVisModal && this.state.visType ? (
<EuiModal onClose={this.onCloseModal} className="visNewVisSearchDialog">
<SearchSelection onSearchSelected={this.onSearchSelected} visType={this.state.visType} />
<SearchSelection
onSearchSelected={this.onSearchSelected}
visType={this.state.visType}
uiSettings={this.props.uiSettings}
savedObjects={this.props.savedObjects}
/>
</EuiModal>
) : (
<EuiModal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@ import { EuiModalBody, EuiModalHeader, EuiModalHeaderTitle } from '@elastic/eui'
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import React from 'react';
import { IUiSettingsClient, SavedObjectsStart } from 'kibana/public';

import { SavedObjectFinder, VisType } from '../../legacy_imports';
import { SavedObjectFinderUi } from '../../../../../../../plugins/kibana_react/public';
import { VisType } from '../../legacy_imports';

interface SearchSelectionProps {
onSearchSelected: (searchId: string, searchType: string) => void;
visType: VisType;
uiSettings: IUiSettingsClient;
savedObjects: SavedObjectsStart;
}

export class SearchSelection extends React.Component<SearchSelectionProps> {
Expand All @@ -50,7 +54,7 @@ export class SearchSelection extends React.Component<SearchSelectionProps> {
</EuiModalHeaderTitle>
</EuiModalHeader>
<EuiModalBody>
<SavedObjectFinder
<SavedObjectFinderUi
key="searchSavedObjectFinder"
onChoose={this.props.onSearchSelected}
showFilter
Expand Down Expand Up @@ -83,6 +87,8 @@ export class SearchSelection extends React.Component<SearchSelectionProps> {
},
]}
fixedPageSize={this.fixedPageSize}
uiSettings={this.props.uiSettings}
savedObjects={this.props.savedObjects}
/>
</EuiModalBody>
</React.Fragment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import React from 'react';
import ReactDOM from 'react-dom';

import { I18nProvider } from '@kbn/i18n/react';
import { IUiSettingsClient } from 'kibana/public';
import { IUiSettingsClient, SavedObjectsStart } from 'kibana/public';
import { NewVisModal } from './new_vis_modal';
import { TypesStart } from '../../../../visualizations/public/np_ready/public/types';

Expand All @@ -33,7 +33,8 @@ export function showNewVisModal(
visTypeRegistry: TypesStart,
{ editorParams = [] }: ShowNewVisModalParams = {},
addBasePath: (path: string) => string,
uiSettings: IUiSettingsClient
uiSettings: IUiSettingsClient,
savedObjects: SavedObjectsStart
) {
const container = document.createElement('div');
const onClose = () => {
Expand All @@ -51,6 +52,7 @@ export function showNewVisModal(
editorParams={editorParams}
addBasePath={addBasePath}
uiSettings={uiSettings}
savedObjects={savedObjects}
/>
</I18nProvider>
);
Expand Down
Loading

0 comments on commit 9102d82

Please sign in to comment.