Skip to content

Commit

Permalink
Visualizations Plugin -> New Platform Ready (elastic#44644)
Browse files Browse the repository at this point in the history
* Created np_ready/public and moved files into it.
* Added kibana.json
* Added plugin.ts and moved plugin class into it.
* Added legacy.ts and moved ui imports to legacy.ts.
* Added mock.ts
* Created registerVisualization() and removed VisTypesRegistryProvider from setup().
* Fixed imports from plugins/visualizations.
* Removed visualizations from index.ts and call setup directly from legacy.ts
  • Loading branch information
sainthkh authored and mattkime committed Sep 4, 2019
1 parent 9a1070e commit 20c7675
Show file tree
Hide file tree
Showing 46 changed files with 956 additions and 616 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ import { SavedObjectsClientProvider } from 'ui/saved_objects';
import { VisualizeListingTable } from './visualize_listing_table';
import { NewVisModal } from '../wizard/new_vis_modal';
import { VisualizeConstants } from '../visualize_constants';
import { visualizations } from 'plugins/visualizations';
import { setup } from '../../../../visualizations/public/np_ready/public/legacy';
import { i18n } from '@kbn/i18n';

const app = uiModules.get('app/visualize', ['ngRoute', 'react']);
app.directive('visualizeListingTable', reactDirective => reactDirective(wrapInI18nContext(VisualizeListingTable)));
app.directive('visualizeListingTable', reactDirective =>
reactDirective(wrapInI18nContext(VisualizeListingTable))
);
app.directive('newVisModal', reactDirective => reactDirective(wrapInI18nContext(NewVisModal)));

export function VisualizeListingController($injector, createNewVis) {
Expand All @@ -43,7 +45,7 @@ export function VisualizeListingController($injector, createNewVis) {
const savedObjectClient = Private(SavedObjectsClientProvider);

this.visTypeRegistry = Private(VisTypesRegistryProvider);
this.visTypeAliases = visualizations.types.visTypeAliasRegistry.get();
this.visTypeAliases = setup.types.visTypeAliasRegistry.get();

timefilter.disableAutoRefreshSelector();
timefilter.disableTimeRangeSelector();
Expand Down Expand Up @@ -80,15 +82,16 @@ export function VisualizeListingController($injector, createNewVis) {
const services = Private(SavedObjectRegistryProvider).byLoaderPropertiesName;
const visualizationService = services.visualizations;

this.fetchItems = (filter) => {
this.fetchItems = filter => {
const isLabsEnabled = config.get('visualize:enableLabs');
return visualizationService.findListItems(filter, config.get('savedObjects:listingLimit'))
return visualizationService
.findListItems(filter, config.get('savedObjects:listingLimit'))
.then(result => {
this.totalItems = result.total;

return {
total: result.total,
hits: result.hits.filter(result => (isLabsEnabled || result.type.stage !== 'experimental'))
hits: result.hits.filter(result => isLabsEnabled || result.type.stage !== 'experimental'),
};
});
};
Expand All @@ -97,23 +100,27 @@ export function VisualizeListingController($injector, createNewVis) {
return Promise.all(
selectedItems.map(item => {
return savedObjectClient.delete(item.savedObjectType, item.id);
}),
).then(() => {
chrome.untrackNavLinksForDeletedSavedObjects(selectedItems.map(item => item.id));
}).catch(error => {
toastNotifications.addError(error, {
title: i18n.translate('kbn.visualize.visualizeListingDeleteErrorTitle', {
defaultMessage: 'Error deleting visualization',
}),
})
)
.then(() => {
chrome.untrackNavLinksForDeletedSavedObjects(selectedItems.map(item => item.id));
})
.catch(error => {
toastNotifications.addError(error, {
title: i18n.translate('kbn.visualize.visualizeListingDeleteErrorTitle', {
defaultMessage: 'Error deleting visualization',
}),
});
});
});
};

chrome.breadcrumbs.set([{
text: i18n.translate('kbn.visualize.visualizeListingBreadcrumbsTitle', {
defaultMessage: 'Visualize',
})
}]);
chrome.breadcrumbs.set([
{
text: i18n.translate('kbn.visualize.visualizeListingBreadcrumbsTitle', {
defaultMessage: 'Visualize',
}),
},
]);

this.listingLimit = config.get('savedObjects:listingLimit');
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { VisTypesRegistryProvider } from 'ui/registry/vis_types';
import { uiModules } from 'ui/modules';
import { SavedObjectLoader, SavedObjectsClientProvider } from 'ui/saved_objects';
import { savedObjectManagementRegistry } from '../../management/saved_object_registry';
import { visualizations } from 'plugins/visualizations';
import { setup } from '../../../../visualizations/public/np_ready/public/legacy';
import { createVisualizeEditUrl } from '../visualize_constants';
import { findListItems } from './find_list_items';

Expand All @@ -32,22 +32,30 @@ const app = uiModules.get('app/visualize');
// edited by the object editor.
savedObjectManagementRegistry.register({
service: 'savedVisualizations',
title: 'visualizations'
title: 'visualizations',
});

app.service('savedVisualizations', function (SavedVis, Private, kbnUrl, chrome) {
const visTypes = Private(VisTypesRegistryProvider);
const savedObjectClient = Private(SavedObjectsClientProvider);
const saveVisualizationLoader = new SavedObjectLoader(SavedVis, kbnUrl, chrome, savedObjectClient);
const saveVisualizationLoader = new SavedObjectLoader(
SavedVis,
kbnUrl,
chrome,
savedObjectClient
);

saveVisualizationLoader.mapHitSource = function (source, id) {
source.id = id;
source.url = this.urlFor(id);

let typeName = source.typeName;
if (source.visState) {
try { typeName = JSON.parse(source.visState).type; }
catch (e) { /* missing typename handled below */ } // eslint-disable-line no-empty
try {
typeName = JSON.parse(source.visState).type;
} catch (e) {
/* missing typename handled below */
} // eslint-disable-line no-empty
}

if (!typeName || !visTypes.byName[typeName]) {
Expand Down Expand Up @@ -78,7 +86,7 @@ app.service('savedVisualizations', function (SavedVis, Private, kbnUrl, chrome)
size,
mapSavedObjectApiHits: this.mapSavedObjectApiHits.bind(this),
savedObjectsClient: this.savedObjectsClient,
visTypes: visualizations.types.visTypeAliasRegistry.get(),
visTypes: setup.types.visTypeAliasRegistry.get(),
});
};

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

import chrome from 'ui/chrome';
import { VisType } from 'ui/vis';
import { VisTypeAlias } from 'plugins/visualizations';
import { VisTypeAlias } from '../../../../visualizations/public/np_ready/public';
import { VisualizeConstants } from '../visualize_constants';

import { SearchSelection } from './search_selection';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {
} from '@elastic/eui';
import { memoizeLast } from 'ui/utils/memoize';
import { VisType } from 'ui/vis';
import { VisTypeAlias } from 'plugins/visualizations';
import { VisTypeAlias } from '../../../../../visualizations/public/np_ready/public';
import { NewVisHelp } from './new_vis_help';
import { VisHelpText } from './vis_help_text';
import { VisTypeIcon } from './vis_type_icon';
Expand Down
4 changes: 2 additions & 2 deletions src/legacy/core_plugins/metrics/public/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
import { PluginInitializerContext } from 'kibana/public';
import { npSetup, npStart } from 'ui/new_platform';

import { visualizations } from '../../visualizations/public';
import { setup as setupVisualizations } from '../../visualizations/public/np_ready/public/legacy';
import { MetricsPluginSetupDependencies } from './plugin';
import { plugin } from '.';

const plugins: Readonly<MetricsPluginSetupDependencies> = {
visualizations,
visualizations: setupVisualizations,
data: npSetup.plugins.data,
};

Expand Down
2 changes: 1 addition & 1 deletion src/legacy/core_plugins/metrics/public/metrics_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { i18n } from '@kbn/i18n';
// @ts-ignore
import { defaultFeedbackMessage } from 'ui/vis/default_feedback_message';

import { visFactory } from '../../visualizations/public';
import { visFactory } from '../../visualizations/public/np_ready/public';

// @ts-ignore
import { createMetricsRequestHandler } from './request_handler';
Expand Down
4 changes: 2 additions & 2 deletions src/legacy/core_plugins/metrics/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
import { PluginInitializerContext, CoreSetup, CoreStart, Plugin } from '../../../../core/public';
import { Plugin as DataPublicPlugin } from '../../../../plugins/data/public';
import { VisualizationsSetup } from '../../visualizations/public';
import { VisualizationsSetup } from '../../visualizations/public/np_ready/public';

import { createMetricsFn } from './metrics_fn';
import { createMetricsTypeDefinition } from './metrics_type';
Expand All @@ -39,7 +39,7 @@ export class MetricsPlugin implements Plugin<Promise<void>, void> {

public async setup(core: CoreSetup, { data, visualizations }: MetricsPluginSetupDependencies) {
data.expressions.registerFunction(createMetricsFn);
visualizations.types.VisTypesRegistryProvider.register(createMetricsTypeDefinition);
visualizations.types.registerVisualization(createMetricsTypeDefinition);
}

public start(core: CoreStart) {
Expand Down
Loading

0 comments on commit 20c7675

Please sign in to comment.