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

Visualizations Plugin -> New Platform Ready #44644

Merged
merged 9 commits into from
Sep 4, 2019
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,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';
Copy link
Member

Choose a reason for hiding this comment

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

I think we should be exporting this contract from the top level public instead, e.g. visualizations/public/legacy

np_ready directory is an implementation detail of the visualizations plugin and consumers of this shim shouldn't need to be aware of whether the directory exists or not.

also (nit) for clarity I think it's nice to do import { setup as visualizations } or setup as visualizationsSetup or similar as we have done elsewhere... would be good to make this consistent across the PR

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 @@ -44,7 +46,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 @@ -81,15 +83,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 @@ -98,23 +101,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');

Expand Down
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