Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing stateful saved object finder #52166

Merged
merged 14 commits into from
Dec 10, 2019
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import {
AppStateClass as TAppStateClass,
KbnUrl,
SaveOptions,
SavedObjectFinder,
unhashUrl,
} from './legacy_imports';
import { FilterStateManager, IndexPattern } from '../../../data/public';
Expand Down Expand Up @@ -71,6 +70,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 @@ -115,7 +118,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 @@ -718,6 +721,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 @@ -22,9 +22,8 @@ import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import React from 'react';

import { SavedObjectFinder } from 'ui/saved_objects/components/saved_object_finder';

import { VisType } from '../../kibana_services';
import { VisType, getServices } from '../../kibana_services';
import { SavedObjectFinderUi } from '../../../../../../../plugins/kibana_react/public';

interface SearchSelectionProps {
onSearchSelected: (searchId: string, searchType: string) => void;
Expand All @@ -35,6 +34,9 @@ export class SearchSelection extends React.Component<SearchSelectionProps> {
private fixedPageSize: number = 8;

public render() {
const {
core: { uiSettings, savedObjects },
} = getServices();
return (
<React.Fragment>
<EuiModalHeader>
Expand All @@ -52,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 @@ -85,6 +87,8 @@ export class SearchSelection extends React.Component<SearchSelectionProps> {
},
]}
fixedPageSize={this.fixedPageSize}
uiSettings={uiSettings}
savedObjects={savedObjects}
/>
</EuiModalBody>
</React.Fragment>
Expand Down
108 changes: 0 additions & 108 deletions src/legacy/ui/public/saved_objects/components/saved_object_finder.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { ExpandPanelAction, ReplacePanelAction } from '.';
import { DashboardContainerFactory } from './embeddable/dashboard_container_factory';
import { Start as InspectorStartContract } from '../../../plugins/inspector/public';
import {
SavedObjectFinder as SavedObjectFinderUi,
SavedObjectFinderUi,
SavedObjectFinderProps,
ExitFullScreenButton as ExitFullScreenButtonUi,
ExitFullScreenButtonProps,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { IconType } from '@elastic/eui';
import { shallow } from 'enzyme';
import React from 'react';
import * as sinon from 'sinon';
import { SavedObjectFinder } from './saved_object_finder';
import { SavedObjectFinderUi as SavedObjectFinder } from './saved_object_finder';
// eslint-disable-next-line
import { coreMock } from '../../../../core/public/mocks';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { i18n } from '@kbn/i18n';

import { SavedObjectAttributes } from '../../../../core/server';
import { SimpleSavedObject, CoreStart } from '../../../../core/public';
import { useKibana } from '../context';

// TODO the typings for EuiListGroup are incorrect - maxWidth is missing. This can be removed when the types are adjusted
const FixedEuiListGroup = (EuiListGroup as any) as React.FunctionComponent<
Expand Down Expand Up @@ -104,12 +105,18 @@ interface SavedObjectFinderInitialPageSize extends BaseSavedObjectFinder {
initialPageSize?: 5 | 10 | 15 | 25;
fixedPageSize?: undefined;
}
export type SavedObjectFinderProps = {

export type SavedObjectFinderProps = SavedObjectFinderFixedPage | SavedObjectFinderInitialPageSize;

export type SavedObjectFinderUiProps = {
savedObjects: CoreStart['savedObjects'];
uiSettings: CoreStart['uiSettings'];
} & (SavedObjectFinderFixedPage | SavedObjectFinderInitialPageSize);
} & SavedObjectFinderProps;

class SavedObjectFinder extends React.Component<SavedObjectFinderProps, SavedObjectFinderState> {
class SavedObjectFinderUi extends React.Component<
SavedObjectFinderUiProps,
SavedObjectFinderState
> {
public static propTypes = {
onChoose: PropTypes.func,
noItemsMessage: PropTypes.node,
Expand Down Expand Up @@ -174,7 +181,7 @@ class SavedObjectFinder extends React.Component<SavedObjectFinderProps, SavedObj
}
}, 300);

constructor(props: SavedObjectFinderProps) {
constructor(props: SavedObjectFinderUiProps) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was introducing this wrapper component necessary, instead of just introducing two new props on the existing SavedObjectFinder component? Are there still places where SavedObjectFinder is used, without uiSettings and savedObjects props?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not at the moment, but this is the target architecture we are moving towards (see also #52493 ). Passing uiSettings and savedObjects services down through the component tree can be cumbersome in some cases, so the wrapper component is able to pick it out of the Kibana context: https://github.com/elastic/kibana/tree/master/src/plugins/kibana_react#context

The usages of saved object finder in embeddables will move into this direction soon. Future uses should be guided into this direction.

super(props);

this.state = {
Expand Down Expand Up @@ -523,4 +530,15 @@ class SavedObjectFinder extends React.Component<SavedObjectFinderProps, SavedObj
}
}

export { SavedObjectFinder };
const SavedObjectFinder = (props: SavedObjectFinderProps) => {
const { services } = useKibana();
return (
<SavedObjectFinderUi
{...props}
savedObjects={services.savedObject}
uiSettings={services.uiSettings}
/>
);
};

export { SavedObjectFinder, SavedObjectFinderUi };
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import 'uiExports/embeddableFactories';
import 'uiExports/embeddableActions';

import { npSetup, npStart } from 'ui/new_platform';
import { SavedObjectFinder } from 'ui/saved_objects/components/saved_object_finder';
import { ExitFullScreenButton } from 'ui/exit_full_screen';
import uiRoutes from 'ui/routes';
// @ts-ignore
Expand All @@ -39,7 +38,6 @@ export const setup = pluginInstance.setup(npSetup.core, {
embeddable: npSetup.plugins.embeddable,
inspector: npSetup.plugins.inspector,
__LEGACY: {
SavedObjectFinder,
ExitFullScreenButton,
},
});
Expand All @@ -64,7 +62,6 @@ export const start = pluginInstance.start(npStart.core, {
inspector: npStart.plugins.inspector,
uiActions: npStart.plugins.uiActions,
__LEGACY: {
SavedObjectFinder,
ExitFullScreenButton,
onRenderComplete: (renderCompleteListener: () => void) => {
if (rendered) {
Expand Down
Loading