Skip to content

Commit

Permalink
Use SavedObjectClass from savedObject start contract instead of `…
Browse files Browse the repository at this point in the history
…createSavedObjectClass` (#80063) (#80459)

* no longer export static createSavedObjectClass from savedObject plugin

* fix forgotten call

* yet another usage

* more fixes

* move so to required plugins for timelion
  • Loading branch information
pgayvallet authored Oct 14, 2020
1 parent 256d3b9 commit fa784db
Show file tree
Hide file tree
Showing 32 changed files with 147 additions and 150 deletions.
10 changes: 2 additions & 8 deletions src/plugins/dashboard/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -412,10 +412,7 @@ export class DashboardPlugin

public start(core: CoreStart, plugins: StartDependencies): DashboardStart {
const { notifications } = core;
const {
uiActions,
data: { indexPatterns, search },
} = plugins;
const { uiActions } = plugins;

const SavedObjectFinder = getSavedObjectFinder(core.savedObjects, core.uiSettings);

Expand Down Expand Up @@ -447,10 +444,7 @@ export class DashboardPlugin

const savedDashboardLoader = createSavedDashboardLoader({
savedObjectsClient: core.savedObjects.client,
indexPatterns,
search,
chrome: core.chrome,
overlays: core.overlays,
savedObjects: plugins.savedObjects,
});
const dashboardContainerFactory = plugins.embeddable.getEmbeddableFactory(
DASHBOARD_CONTAINER_TYPE
Expand Down
11 changes: 3 additions & 8 deletions src/plugins/dashboard/public/saved_dashboards/saved_dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import {
createSavedObjectClass,
SavedObject,
SavedObjectKibanaServices,
} from '../../../../plugins/saved_objects/public';
import { SavedObject, SavedObjectsStart } from '../../../../plugins/saved_objects/public';
import { extractReferences, injectReferences } from './saved_dashboard_references';

import { Filter, ISearchSource, Query, RefreshInterval } from '../../../../plugins/data/public';
Expand All @@ -45,10 +41,9 @@ export interface SavedObjectDashboard extends SavedObject {

// Used only by the savedDashboards service, usually no reason to change this
export function createSavedDashboardClass(
services: SavedObjectKibanaServices
savedObjectStart: SavedObjectsStart
): new (id: string) => SavedObjectDashboard {
const SavedObjectClass = createSavedObjectClass(services);
class SavedDashboard extends SavedObjectClass {
class SavedDashboard extends savedObjectStart.SavedObjectClass {
// save these objects with the 'dashboard' type
public static type = 'dashboard';

Expand Down
16 changes: 6 additions & 10 deletions src/plugins/dashboard/public/saved_dashboards/saved_dashboards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,19 @@
* under the License.
*/

import { SavedObjectsClientContract, ChromeStart, OverlayStart } from 'kibana/public';
import { DataPublicPluginStart, IndexPatternsContract } from '../../../../plugins/data/public';
import { SavedObjectLoader } from '../../../../plugins/saved_objects/public';
import { SavedObjectsClientContract } from 'kibana/public';
import { SavedObjectLoader, SavedObjectsStart } from '../../../../plugins/saved_objects/public';
import { createSavedDashboardClass } from './saved_dashboard';

interface Services {
savedObjectsClient: SavedObjectsClientContract;
indexPatterns: IndexPatternsContract;
search: DataPublicPluginStart['search'];
chrome: ChromeStart;
overlays: OverlayStart;
savedObjects: SavedObjectsStart;
}

/**
* @param services
*/
export function createSavedDashboardLoader(services: Services) {
const SavedDashboard = createSavedDashboardClass(services);
return new SavedObjectLoader(SavedDashboard, services.savedObjectsClient);
export function createSavedDashboardLoader({ savedObjects, savedObjectsClient }: Services) {
const SavedDashboard = createSavedDashboardClass(savedObjects);
return new SavedObjectLoader(SavedDashboard, savedObjectsClient);
}
10 changes: 3 additions & 7 deletions src/plugins/discover/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,9 @@
"urlForwarding",
"navigation",
"uiActions",
"visualizations"
"visualizations",
"savedObjects"
],
"optionalPlugins": ["home", "share"],
"requiredBundles": [
"kibanaUtils",
"home",
"savedObjects",
"kibanaReact"
]
"requiredBundles": ["kibanaUtils", "home", "kibanaReact"]
}
8 changes: 2 additions & 6 deletions src/plugins/discover/public/build_services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import { Start as InspectorPublicPluginStart } from 'src/plugins/inspector/publi
import { SharePluginStart } from 'src/plugins/share/public';
import { ChartsPluginStart } from 'src/plugins/charts/public';
import { VisualizationsStart } from 'src/plugins/visualizations/public';
import { SavedObjectKibanaServices } from 'src/plugins/saved_objects/public';

import { DiscoverStartPlugins } from './plugin';
import { createSavedSearchesLoader, SavedSearch } from './saved_searches';
Expand Down Expand Up @@ -78,12 +77,9 @@ export async function buildServices(
context: PluginInitializerContext,
getEmbeddableInjector: any
): Promise<DiscoverServices> {
const services: SavedObjectKibanaServices = {
const services = {
savedObjectsClient: core.savedObjects.client,
indexPatterns: plugins.data.indexPatterns,
search: plugins.data.search,
chrome: core.chrome,
overlays: core.overlays,
savedObjects: plugins.savedObjects,
};
const savedObjectService = createSavedSearchesLoader(services);

Expand Down
8 changes: 3 additions & 5 deletions src/plugins/discover/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import { UrlForwardingSetup, UrlForwardingStart } from 'src/plugins/url_forwardi
import { HomePublicPluginSetup } from 'src/plugins/home/public';
import { Start as InspectorPublicPluginStart } from 'src/plugins/inspector/public';
import { DataPublicPluginStart, DataPublicPluginSetup, esFilters } from '../../data/public';
import { SavedObjectLoader } from '../../saved_objects/public';
import { SavedObjectLoader, SavedObjectsStart } from '../../saved_objects/public';
import { createKbnUrlTracker } from '../../kibana_utils/public';
import { DEFAULT_APP_CATEGORIES } from '../../../core/public';
import { UrlGeneratorState } from '../../share/public';
Expand Down Expand Up @@ -141,6 +141,7 @@ export interface DiscoverStartPlugins {
urlForwarding: UrlForwardingStart;
inspector: InspectorPublicPluginStart;
visualizations: VisualizationsStart;
savedObjects: SavedObjectsStart;
}

const innerAngularName = 'app/discover';
Expand Down Expand Up @@ -351,10 +352,7 @@ export class DiscoverPlugin
urlGenerator: this.urlGenerator,
savedSearchLoader: createSavedSearchesLoader({
savedObjectsClient: core.savedObjects.client,
indexPatterns: plugins.data.indexPatterns,
search: plugins.data.search,
chrome: core.chrome,
overlays: core.overlays,
savedObjects: plugins.savedObjects,
}),
};
}
Expand Down
14 changes: 4 additions & 10 deletions src/plugins/discover/public/saved_searches/_saved_search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,10 @@
* specific language governing permissions and limitations
* under the License.
*/
import {
createSavedObjectClass,
SavedObject,
SavedObjectKibanaServices,
} from '../../../saved_objects/public';
import { SavedObject, SavedObjectsStart } from '../../../saved_objects/public';

export function createSavedSearchClass(services: SavedObjectKibanaServices) {
const SavedObjectClass = createSavedObjectClass(services);

class SavedSearch extends SavedObjectClass {
export function createSavedSearchClass(savedObjects: SavedObjectsStart) {
class SavedSearch extends savedObjects.SavedObjectClass {
public static type: string = 'search';
public static mapping = {
title: 'text',
Expand Down Expand Up @@ -70,5 +64,5 @@ export function createSavedSearchClass(services: SavedObjectKibanaServices) {
}
}

return SavedSearch as new (id: string) => SavedObject;
return (SavedSearch as unknown) as new (id: string) => SavedObject;
}
14 changes: 10 additions & 4 deletions src/plugins/discover/public/saved_searches/saved_searches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,18 @@
* under the License.
*/

import { SavedObjectLoader, SavedObjectKibanaServices } from '../../../saved_objects/public';
import { SavedObjectsClientContract } from 'kibana/public';
import { SavedObjectLoader, SavedObjectsStart } from '../../../saved_objects/public';
import { createSavedSearchClass } from './_saved_search';

export function createSavedSearchesLoader(services: SavedObjectKibanaServices) {
const SavedSearchClass = createSavedSearchClass(services);
const savedSearchLoader = new SavedObjectLoader(SavedSearchClass, services.savedObjectsClient);
interface Services {
savedObjectsClient: SavedObjectsClientContract;
savedObjects: SavedObjectsStart;
}

export function createSavedSearchesLoader({ savedObjectsClient, savedObjects }: Services) {
const SavedSearchClass = createSavedSearchClass(savedObjects);
const savedSearchLoader = new SavedObjectLoader(SavedSearchClass, savedObjectsClient);
// Customize loader properties since adding an 's' on type doesn't work for type 'search' .
savedSearchLoader.loaderProperties = {
name: 'searches',
Expand Down
1 change: 0 additions & 1 deletion src/plugins/saved_objects/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export {
export { getSavedObjectFinder, SavedObjectFinderUi, SavedObjectMetaData } from './finder';
export {
SavedObjectLoader,
createSavedObjectClass,
checkForDuplicateTitle,
saveWithConfirmation,
isErrorNonFatal,
Expand Down
34 changes: 34 additions & 0 deletions src/plugins/saved_objects/public/mocks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { SavedObjectsStart } from './plugin';

const createStartContract = (): SavedObjectsStart => {
return {
SavedObjectClass: jest.fn(),
settings: {
getPerPage: () => 20,
getListingLimit: () => 100,
},
};
};

export const savedObjectsPluginMock = {
createStartContract,
};
3 changes: 2 additions & 1 deletion src/plugins/saved_objects/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ import './index.scss';
import { createSavedObjectClass } from './saved_object';
import { DataPublicPluginStart } from '../../data/public';
import { PER_PAGE_SETTING, LISTING_LIMIT_SETTING } from '../common';
import { SavedObject } from './types';

export interface SavedObjectsStart {
SavedObjectClass: any;
SavedObjectClass: new (raw: Record<string, any>) => SavedObject;
settings: {
getPerPage: () => number;
getListingLimit: () => number;
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/timelion/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
"requiredBundles": [
"kibanaLegacy",
"kibanaUtils",
"savedObjects",
"visTypeTimelion"
],
"requiredPlugins": [
"visualizations",
"data",
"navigation",
"visTypeTimelion",
"savedObjects",
"kibanaLegacy"
]
}
6 changes: 3 additions & 3 deletions src/plugins/timelion/public/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import {
createTopNavDirective,
createTopNavHelper,
} from '../../kibana_legacy/public';
import { TimelionPluginDependencies } from './plugin';
import { TimelionPluginStartDependencies } from './plugin';
import { DataPublicPluginStart } from '../../data/public';
// @ts-ignore
import { initTimelionApp } from './app';
Expand All @@ -50,7 +50,7 @@ export interface RenderDeps {
pluginInitializerContext: PluginInitializerContext;
mountParams: AppMountParameters;
core: CoreStart;
plugins: TimelionPluginDependencies;
plugins: TimelionPluginStartDependencies;
timelionPanels: Map<string, Panel>;
}

Expand Down Expand Up @@ -137,7 +137,7 @@ function createLocalIconModule() {
.directive('icon', (reactDirective) => reactDirective(EuiIcon));
}

function createLocalTopNavModule(navigation: TimelionPluginDependencies['navigation']) {
function createLocalTopNavModule(navigation: TimelionPluginStartDependencies['navigation']) {
angular
.module('app/timelion/TopNav', ['react'])
.directive('kbnTopNav', createTopNavDirective)
Expand Down
17 changes: 13 additions & 4 deletions src/plugins/timelion/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,29 @@ import { createKbnUrlTracker } from '../../kibana_utils/public';
import { DataPublicPluginStart, esFilters, DataPublicPluginSetup } from '../../data/public';
import { NavigationPublicPluginStart } from '../../navigation/public';
import { VisualizationsStart } from '../../visualizations/public';
import { SavedObjectsStart } from '../../saved_objects/public';
import {
VisTypeTimelionPluginStart,
VisTypeTimelionPluginSetup,
} from '../../vis_type_timelion/public';

export interface TimelionPluginDependencies {
export interface TimelionPluginSetupDependencies {
data: DataPublicPluginSetup;
visTypeTimelion: VisTypeTimelionPluginSetup;
}

export interface TimelionPluginStartDependencies {
data: DataPublicPluginStart;
navigation: NavigationPublicPluginStart;
visualizations: VisualizationsStart;
visTypeTimelion: VisTypeTimelionPluginStart;
savedObjects: SavedObjectsStart;
kibanaLegacy: KibanaLegacyStart;
}

/** @internal */
export class TimelionPlugin implements Plugin<void, void> {
export class TimelionPlugin
implements Plugin<void, void, TimelionPluginSetupDependencies, TimelionPluginStartDependencies> {
initializerContext: PluginInitializerContext;
private appStateUpdater = new BehaviorSubject<AppUpdater>(() => ({}));
private stopUrlTracking: (() => void) | undefined = undefined;
Expand All @@ -60,7 +69,7 @@ export class TimelionPlugin implements Plugin<void, void> {
}

public setup(
core: CoreSetup,
core: CoreSetup<TimelionPluginStartDependencies>,
{
data,
visTypeTimelion,
Expand Down Expand Up @@ -122,7 +131,7 @@ export class TimelionPlugin implements Plugin<void, void> {
pluginInitializerContext: this.initializerContext,
timelionPanels,
core: coreStart,
plugins: pluginsStart as TimelionPluginDependencies,
plugins: pluginsStart,
});
return () => {
unlistenParentHistory();
Expand Down
11 changes: 3 additions & 8 deletions src/plugins/timelion/public/services/_saved_sheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,11 @@
*/

import { IUiSettingsClient } from 'kibana/public';
import { createSavedObjectClass, SavedObjectKibanaServices } from '../../../saved_objects/public';
import { SavedObjectsStart } from '../../../saved_objects/public';

// Used only by the savedSheets service, usually no reason to change this
export function createSavedSheetClass(
services: SavedObjectKibanaServices,
config: IUiSettingsClient
) {
const SavedObjectClass = createSavedObjectClass(services);

class SavedSheet extends SavedObjectClass {
export function createSavedSheetClass(savedObjects: SavedObjectsStart, config: IUiSettingsClient) {
class SavedSheet extends savedObjects.SavedObjectClass {
static type = 'timelion-sheet';

// if type:sheet has no mapping, we push this mapping into ES
Expand Down
10 changes: 1 addition & 9 deletions src/plugins/timelion/public/services/saved_sheets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,7 @@ import { RenderDeps } from '../application';

export function initSavedSheetService(app: angular.IModule, deps: RenderDeps) {
const savedObjectsClient = deps.core.savedObjects.client;
const services = {
savedObjectsClient,
indexPatterns: deps.plugins.data.indexPatterns,
search: deps.plugins.data.search,
chrome: deps.core.chrome,
overlays: deps.core.overlays,
};

const SavedSheet = createSavedSheetClass(services, deps.core.uiSettings);
const SavedSheet = createSavedSheetClass(deps.plugins.savedObjects, deps.core.uiSettings);

const savedSheetLoader = new SavedObjectLoader(SavedSheet, savedObjectsClient);
savedSheetLoader.urlFor = (id) => `#/${encodeURIComponent(id)}`;
Expand Down
Loading

0 comments on commit fa784db

Please sign in to comment.