Skip to content

Commit

Permalink
no longer export static createSavedObjectClass from savedObject plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
pgayvallet committed Oct 8, 2020
1 parent 769bd75 commit 21f91e9
Show file tree
Hide file tree
Showing 22 changed files with 94 additions and 133 deletions.
11 changes: 2 additions & 9 deletions src/plugins/dashboard/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -430,11 +430,7 @@ export class DashboardPlugin

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

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

Expand Down Expand Up @@ -466,10 +462,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: 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
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
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
12 changes: 10 additions & 2 deletions src/plugins/visualizations/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@
"version": "kibana",
"server": true,
"ui": true,
"requiredPlugins": ["data", "expressions", "uiActions", "embeddable", "inspector", "dashboard"],
"requiredPlugins": [
"data",
"expressions",
"uiActions",
"embeddable",
"inspector",
"dashboard",
"savedObjects"
],
"optionalPlugins": ["usageCollection"],
"requiredBundles": ["kibanaUtils", "discover", "savedObjects"]
"requiredBundles": ["kibanaUtils", "discover"]
}
13 changes: 5 additions & 8 deletions src/plugins/visualizations/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ import {
} from './saved_visualizations/_saved_vis';
import { createSavedSearchesLoader } from '../../discover/public';
import { DashboardStart } from '../../dashboard/public';
import { SavedObjectsStart } from '../../saved_objects/public';

/**
* Interface for this plugin's returned setup/start contracts.
Expand Down Expand Up @@ -112,6 +113,7 @@ export interface VisualizationsStartDeps {
uiActions: UiActionsStart;
application: ApplicationStart;
dashboard: DashboardStart;
savedObjects: SavedObjectsStart;
getAttributeService: DashboardStart['getAttributeService'];
savedObjectsClient: SavedObjectsClientContract;
}
Expand Down Expand Up @@ -160,7 +162,7 @@ export class VisualizationsPlugin

public start(
core: CoreStart,
{ data, expressions, uiActions, embeddable, dashboard }: VisualizationsStartDeps
{ data, expressions, uiActions, embeddable, dashboard, savedObjects }: VisualizationsStartDeps
): VisualizationsStart {
const types = this.types.start();
setI18n(core.i18n);
Expand All @@ -182,18 +184,13 @@ export class VisualizationsPlugin
const savedVisualizationsLoader = createSavedVisLoader({
savedObjectsClient: core.savedObjects.client,
indexPatterns: data.indexPatterns,
search: data.search,
chrome: core.chrome,
overlays: core.overlays,
savedObjects,
visualizationTypes: types,
});
setSavedVisualizationsLoader(savedVisualizationsLoader);
const savedSearchLoader = createSavedSearchesLoader({
savedObjectsClient: core.savedObjects.client,
indexPatterns: data.indexPatterns,
search: data.search,
chrome: core.chrome,
overlays: core.overlays,
savedObjects,
});
setSavedSearchLoader(savedSearchLoader);
return {
Expand Down
Loading

0 comments on commit 21f91e9

Please sign in to comment.