Skip to content

Commit

Permalink
Refactor saved object management registry usage (elastic#54155)
Browse files Browse the repository at this point in the history
* Migrate registry to TypeScript

* Migrate management code

* Migrate SavedObjectLoader services registration to management section

* Replace Angular SavedSearchLoader in transform plugin

* Migrate saved_visualizations from visualize to visualizations plugin
  • Loading branch information
kertal committed Jan 28, 2020
1 parent 82509cb commit 35ce70d
Show file tree
Hide file tree
Showing 33 changed files with 164 additions and 268 deletions.
1 change: 0 additions & 1 deletion src/legacy/core_plugins/kibana/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ export default function(kibana) {
'plugins/kibana/visualize/legacy',
'plugins/kibana/dashboard/legacy',
],
savedObjectTypes: ['plugins/kibana/dashboard/saved_dashboard/saved_dashboard_register'],
app: {
id: 'kibana',
title: 'Kibana',
Expand Down

This file was deleted.

1 change: 1 addition & 0 deletions src/legacy/core_plugins/kibana/public/dashboard/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { PluginInitializerContext } from 'kibana/public';
import { DashboardPlugin } from './plugin';

export * from './np_ready/dashboard_constants';
export { createSavedDashboardLoader } from './saved_dashboard/saved_dashboards';

// Core will be looking for this when loading our plugin in the new platform
export const plugin = (context: PluginInitializerContext) => {
Expand Down
1 change: 0 additions & 1 deletion src/legacy/core_plugins/kibana/public/dashboard/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { npSetup, npStart, legacyChrome } from './legacy_imports';
import { LegacyAngularInjectedDependencies } from './plugin';
import { start as data } from '../../../data/public/legacy';
import { start as embeddables } from '../../../embeddable_api/public/np_ready/public/legacy';
import './saved_dashboard/saved_dashboard_register';
import './dashboard_config';
import { plugin } from './index';

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
IndexPatternsContract,
DataPublicPluginStart,
} from 'src/plugins/data/public';
import { createSavedSearchesService } from './saved_searches';
import { createSavedSearchesLoader } from './saved_searches';
import { DiscoverStartPlugins } from './plugin';
import { EuiUtilsStart } from '../../../../../plugins/eui_utils/public';
import { SharePluginStart } from '../../../../../plugins/share/public';
Expand Down Expand Up @@ -68,7 +68,7 @@ export async function buildServices(
chrome: core.chrome,
overlays: core.overlays,
};
const savedObjectService = createSavedSearchesService(services);
const savedObjectService = createSavedSearchesLoader(services);
return {
addBasePath: core.http.basePath.prepend,
capabilities: core.application.capabilities,
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/core_plugins/kibana/public/discover/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import { PluginInitializerContext } from 'kibana/public';
import { DiscoverPlugin } from './plugin';

export { createSavedSearchesService } from './saved_searches/saved_searches';
export { createSavedSearchesLoader } from './saved_searches/saved_searches';

// Core will be looking for this when loading our plugin in the new platform
export const plugin = (context: PluginInitializerContext) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@
*/

export * from './saved_searches';
import './saved_searches_register';
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { SavedObjectLoader } from 'ui/saved_objects';
import { SavedObjectKibanaServices } from 'ui/saved_objects/types';
import { createSavedSearchClass } from './_saved_search';

export function createSavedSearchesService(services: SavedObjectKibanaServices) {
export function createSavedSearchesLoader(services: SavedObjectKibanaServices) {
const SavedSearchClass = createSavedSearchClass(services);
const savedSearchLoader = new SavedObjectLoader(
SavedSearchClass,
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* 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 _ from 'lodash';
import { i18n } from '@kbn/i18n';
import { npStart } from 'ui/new_platform';
import { SavedObjectLoader } from 'ui/saved_objects';
import { createSavedDashboardLoader } from '../dashboard';
import { createSavedSearchesLoader } from '../discover';
import { TypesService, createSavedVisLoader } from '../../../visualizations/public';

/**
* This registry is used for the editing mode of Saved Searches, Visualizations,
* Dashboard and Time Lion saved objects.
*/
interface SavedObjectRegistryEntry {
id: string;
service: SavedObjectLoader;
title: string;
}

const registry: SavedObjectRegistryEntry[] = [];

export const savedObjectManagementRegistry = {
register: (service: SavedObjectRegistryEntry) => {
registry.push(service);
},
all: () => {
return registry;
},
get: (id: string) => {
return _.find(registry, { id });
},
};

const services = {
savedObjectsClient: npStart.core.savedObjects.client,
indexPatterns: npStart.plugins.data.indexPatterns,
chrome: npStart.core.chrome,
overlays: npStart.core.overlays,
};

savedObjectManagementRegistry.register({
id: 'savedVisualizations',
service: createSavedVisLoader({
...services,
...{ visualizationTypes: new TypesService().start() },
}),
title: 'visualizations',
});

savedObjectManagementRegistry.register({
id: 'savedDashboards',
service: createSavedDashboardLoader(services),
title: i18n.translate('kbn.dashboard.savedDashboardsTitle', {
defaultMessage: 'dashboards',
}),
});

savedObjectManagementRegistry.register({
id: 'savedSearches',
service: createSavedSearchesLoader(services),
title: 'searches',
});
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function updateObjectsTable($scope, $injector) {
const confirmModalPromise = $injector.get('confirmModalPromise');

const savedObjectsClient = npStart.core.savedObjects.client;
const services = savedObjectManagementRegistry.all().map(obj => $injector.get(obj.service));
const services = savedObjectManagementRegistry.all().map(obj => obj.service);
const uiCapabilites = npStart.core.application.capabilities;

$scope.$$postDigest(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,9 @@ uiModules
.directive('kbnManagementObjectsView', function(kbnIndex, confirmModal) {
return {
restrict: 'E',
controller: function(
$scope,
$injector,
$routeParams,
$location,
$window,
$rootScope,
uiCapabilities
) {
controller: function($scope, $routeParams, $location, $window, $rootScope, uiCapabilities) {
const serviceObj = savedObjectManagementRegistry.get($routeParams.service);
const service = $injector.get(serviceObj.service);
const service = serviceObj.service;
const savedObjectsClient = npStart.core.savedObjects.client;

/**
Expand Down Expand Up @@ -184,6 +176,7 @@ uiModules
return orderIndex > -1 ? orderIndex : Infinity;
});
});
$scope.$digest();
})
.catch(error => fatalError(error, location));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ export function getIndexBreadcrumbs() {
];
}

export function getViewBreadcrumbs($routeParams, $injector) {
export function getViewBreadcrumbs($routeParams) {
const serviceObj = savedObjectManagementRegistry.get($routeParams.service);
const service = $injector.get(serviceObj.service);
const { service } = serviceObj;

return [
...getIndexBreadcrumbs(),
Expand Down
3 changes: 1 addition & 2 deletions src/legacy/core_plugins/kibana/public/visualize/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ import { VisualizePlugin } from './plugin';

export * from './np_ready/visualize_constants';
export { showNewVisModal } from './np_ready/wizard';

export { createSavedVisLoader } from './saved_visualizations/saved_visualizations';
export { VisualizeConstants, createVisualizeEditUrl } from './np_ready/visualize_constants';

// Core will be looking for this when loading our plugin in the new platform
export const plugin = (context: PluginInitializerContext) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import angular from 'angular';
import _ from 'lodash';
import { Subscription } from 'rxjs';
import { i18n } from '@kbn/i18n';
import '../../saved_visualizations/saved_visualizations';

import React from 'react';
import { FormattedMessage } from '@kbn/i18n/react';
Expand Down
Loading

0 comments on commit 35ce70d

Please sign in to comment.