Skip to content

Commit

Permalink
Move new_vis_modal to visualizations plugin (elastic#56654) (elastic#…
Browse files Browse the repository at this point in the history
…56956)

Move new_vis_modal to visualizations plugin.
These removes one import from visualisations plugin to kibana/
showNewVisModal() is part of the plugin contract and plugin dependencies are provided implicitly.
# Conflicts:
#	x-pack/plugins/translations/translations/ja-JP.json
#	x-pack/plugins/translations/translations/zh-CN.json
  • Loading branch information
Dosant authored Feb 6, 2020
1 parent 11257e3 commit 6086487
Show file tree
Hide file tree
Showing 26 changed files with 110 additions and 166 deletions.
1 change: 0 additions & 1 deletion src/legacy/core_plugins/kibana/public/visualize/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { PluginInitializerContext } from 'kibana/public';
import { VisualizePlugin } from './plugin';

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

// Core will be looking for this when loading our plugin in the new platform
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@

@import 'editor/index';
@import 'listing/index';
@import 'wizard/index';
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,4 @@
edit-item="listingController.editItem"
listing-limit="listingController.listingLimit"
></visualize-listing-table>

<new-vis-modal
is-open="listingController.showNewVisModal"
on-close="listingController.closeNewVisModal"
vis-types-registry="listingController.visTypeRegistry"
add-base-path="listingController.addBasePath"
ui-settings="listingController.uiSettings"
saved-objects="listingController.savedObjects"
usage-collection="listingController.usageCollection"
></new-vis-modal>

</div>
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import { addHelpMenuToAppChrome } from '../help_menu/help_menu_util';
import { VisualizeListingTable } from './visualize_listing_table';
import { NewVisModal } from '../wizard/new_vis_modal';

import { VisualizeConstants } from '../visualize_constants';
import { i18n } from '@kbn/i18n';

Expand All @@ -30,17 +30,6 @@ export function initListingDirective(app) {
app.directive('visualizeListingTable', reactDirective =>
reactDirective(wrapInI18nContext(VisualizeListingTable))
);
app.directive('newVisModal', reactDirective =>
reactDirective(wrapInI18nContext(NewVisModal), [
['visTypesRegistry', { watchDepth: 'collection' }],
['onClose', { watchDepth: 'reference' }],
['addBasePath', { watchDepth: 'reference' }],
['uiSettings', { watchDepth: 'reference' }],
['savedObjects', { watchDepth: 'reference' }],
['usageCollection', { watchDepth: 'reference' }],
'isOpen',
])
);
}

export function VisualizeListingController($injector, createNewVis) {
Expand All @@ -59,21 +48,18 @@ export function VisualizeListingController($injector, createNewVis) {
uiSettings,
visualizations,
core: { docLinks, savedObjects },
usageCollection,
} = getServices();
const kbnUrl = $injector.get('kbnUrl');

timefilter.disableAutoRefreshSelector();
timefilter.disableTimeRangeSelector();

this.showNewVisModal = false;
this.addBasePath = addBasePath;
this.uiSettings = uiSettings;
this.savedObjects = savedObjects;
this.usageCollection = usageCollection;

this.createNewVis = () => {
this.showNewVisModal = true;
visualizations.showNewVisModal();
};

this.editItem = ({ editUrl }) => {
Expand All @@ -85,19 +71,15 @@ export function VisualizeListingController($injector, createNewVis) {
return addBasePath(editUrl);
};

this.closeNewVisModal = () => {
this.showNewVisModal = false;
// In case the user came via a URL to this page, change the URL to the regular landing page URL after closing the modal
if (createNewVis) {
kbnUrl.changePath(VisualizeConstants.LANDING_PAGE_PATH);
}
};

if (createNewVis) {
// In case the user navigated to the page via the /visualize/new URL we start the dialog immediately
this.createNewVis();
visualizations.showNewVisModal({
onClose: () => {
// In case the user came via a URL to this page, change the URL to the regular landing page URL after closing the modal
kbnUrl.changePath(VisualizeConstants.LANDING_PAGE_PATH);
},
});
}
this.visTypeRegistry = visualizations.types;

this.fetchItems = filter => {
const isLabsEnabled = uiSettings.get('visualize:enableLabs');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,24 @@
import { i18n } from '@kbn/i18n';
import { SavedObjectAttributes } from 'kibana/public';
import {
EmbeddableFactory,
ErrorEmbeddable,
Container,
EmbeddableFactory,
EmbeddableOutput,
ErrorEmbeddable,
} from '../../../../../plugins/embeddable/public';
import { showNewVisModal } from '../../../kibana/public/visualize';
import { SavedVisualizations } from '../../../kibana/public/visualize/np_ready/types';
import { DisabledLabEmbeddable } from './disabled_lab_embeddable';
import { getIndexPattern } from './get_index_pattern';
import {
VisSavedObject,
VisualizeEmbeddable,
VisualizeInput,
VisualizeOutput,
VisSavedObject,
} from './visualize_embeddable';
import { VISUALIZE_EMBEDDABLE_TYPE } from './constants';

import {
getUISettings,
getCapabilities,
getHttp,
getTypes,
getSavedObjects,
getUsageCollector,
} from '../np_ready/public/services';
import { getCapabilities, getHttp, getTypes, getUISettings } from '../np_ready/public/services';
import { showNewVisModal } from '../np_ready/public/wizard';

interface VisualizationAttributes extends SavedObjectAttributes {
visState: string;
Expand Down Expand Up @@ -157,16 +150,9 @@ export class VisualizeEmbeddableFactory extends EmbeddableFactory<
public async create() {
// TODO: This is a bit of a hack to preserve the original functionality. Ideally we will clean this up
// to allow for in place creation of visualizations without having to navigate away to a new URL.
showNewVisModal(
getTypes(),
{
editorParams: ['addToDashboard'],
},
getHttp().basePath.prepend,
getUISettings(),
getSavedObjects(),
getUsageCollector()
);
showNewVisModal({
editorParams: ['addToDashboard'],
});
return undefined;
}
}
3 changes: 2 additions & 1 deletion src/legacy/core_plugins/visualizations/public/index.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@import 'src/legacy/ui/public/styles/styling_constants';

@import './embeddable/_index';
@import './embeddable/index';
@import './np_ready/public/index';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import 'wizard/index';
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const createStartContract = (): VisualizationsStart => ({
getAliases: jest.fn(),
},
getSavedVisualizationsLoader: jest.fn(),
showNewVisModal: jest.fn(),
});

const createInstance = async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
SavedObjectKibanaServicesWithVisualizations,
} from '../../saved_visualizations';
import { SavedVisualizations } from '../../../../kibana/public/visualize/np_ready/types';
import { showNewVisModal } from './wizard';
/**
* Interface for this plugin's returned setup/start contracts.
*
Expand All @@ -55,6 +56,7 @@ export interface VisualizationsSetup {
export interface VisualizationsStart {
types: TypesStart;
getSavedVisualizationsLoader: () => SavedVisualizations;
showNewVisModal: typeof showNewVisModal;
}

export interface VisualizationsSetupDeps {
Expand Down Expand Up @@ -92,7 +94,7 @@ export class VisualizationsPlugin
public setup(
core: CoreSetup,
{ expressions, embeddable, usageCollection }: VisualizationsSetupDeps
) {
): VisualizationsSetup {
setUISettings(core.uiSettings);
setUsageCollector(usageCollection);

Expand All @@ -107,7 +109,7 @@ export class VisualizationsPlugin
};
}

public start(core: CoreStart, { data }: VisualizationsStartDeps) {
public start(core: CoreStart, { data }: VisualizationsStartDeps): VisualizationsStart {
const types = this.types.start();
setI18n(core.i18n);
setTypes(types);
Expand All @@ -128,6 +130,7 @@ export class VisualizationsPlugin
return {
types,
getSavedVisualizationsLoader: () => this.getSavedVisualizationsLoader(),
showNewVisModal,
};
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@
* under the License.
*/

export { NewVisModal } from './new_vis_modal';
export { showNewVisModal } from './show_new_vis';
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,7 @@

import React from 'react';
import { mountWithIntl } from 'test_utils/enzyme_helpers';

import { VisType } from '../../legacy_imports';
import { TypesStart } from '../../../../../visualizations/public/np_ready/public/types';

jest.mock('../../legacy_imports', () => ({
State: () => null,
AppState: () => null,
}));

import { TypesStart, VisType } from '../types';
import { NewVisModal } from './new_vis_modal';
import { SavedObjectsStart } from 'kibana/public';

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

import { METRIC_TYPE, UiStatsMetricType } from '@kbn/analytics';
import { IUiSettingsClient, SavedObjectsStart } from 'kibana/public';
import { VisType } from '../../legacy_imports';
import { VisualizeConstants } from '../visualize_constants';
import { SearchSelection } from './search_selection';
import { TypeSelection } from './type_selection';
import {
TypesStart,
VisTypeAlias,
} from '../../../../../visualizations/public/np_ready/public/types';
import { TypesStart, VisType, VisTypeAlias } from '../types';
import { UsageCollectionSetup } from '../../../../../../../plugins/usage_collection/public';

interface TypeSelectionProps {
Expand All @@ -50,7 +45,9 @@ interface TypeSelectionState {
visType?: VisType;
}

const baseUrl = `#${VisualizeConstants.CREATE_PATH}?`;
// TODO: redirect logic is specific to visualise & dashboard
// but it is likely should be decoupled. e.g. handled by the container instead
const baseUrl = `#/visualize/create?`;

class NewVisModal extends React.Component<TypeSelectionProps, TypeSelectionState> {
public static defaultProps = {
Expand Down Expand Up @@ -82,7 +79,7 @@ class NewVisModal extends React.Component<TypeSelectionProps, TypeSelectionState
}

const visNewVisDialogAriaLabel = i18n.translate(
'kbn.visualize.newVisWizard.helpTextAriaLabel',
'visualizations.newVisWizard.helpTextAriaLabel',
{
defaultMessage:
'Start creating your visualization by selecting a type for that visualization. Hit escape to close this modal. Hit Tab key to go further.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import React from 'react';
import { IUiSettingsClient, SavedObjectsStart } from 'kibana/public';

import { SavedObjectFinderUi } from '../../../../../../../../plugins/kibana_react/public';
import { VisType } from '../../../legacy_imports';
import { VisType } from '../../types';

interface SearchSelectionProps {
onSearchSelected: (searchId: string, searchType: string) => void;
Expand All @@ -42,13 +42,13 @@ export class SearchSelection extends React.Component<SearchSelectionProps> {
<EuiModalHeader>
<EuiModalHeaderTitle>
<FormattedMessage
id="kbn.visualize.newVisWizard.newVisTypeTitle"
id="visualizations.newVisWizard.newVisTypeTitle"
defaultMessage="New {visTypeName}"
values={{ visTypeName: this.props.visType.title }}
/>{' '}
/{' '}
<FormattedMessage
id="kbn.visualize.newVisWizard.chooseSourceTitle"
id="visualizations.newVisWizard.chooseSourceTitle"
defaultMessage="Choose a source"
/>
</EuiModalHeaderTitle>
Expand All @@ -59,7 +59,7 @@ export class SearchSelection extends React.Component<SearchSelectionProps> {
onChoose={this.props.onSearchSelected}
showFilter
noItemsMessage={i18n.translate(
'kbn.visualize.newVisWizard.searchSelection.notFoundLabel',
'visualizations.newVisWizard.searchSelection.notFoundLabel',
{
defaultMessage: 'No matching indices or saved searches found.',
}
Expand All @@ -69,7 +69,7 @@ export class SearchSelection extends React.Component<SearchSelectionProps> {
type: 'search',
getIconForSavedObject: () => 'search',
name: i18n.translate(
'kbn.visualize.newVisWizard.searchSelection.savedObjectType.search',
'visualizations.newVisWizard.searchSelection.savedObjectType.search',
{
defaultMessage: 'Saved search',
}
Expand All @@ -79,7 +79,7 @@ export class SearchSelection extends React.Component<SearchSelectionProps> {
type: 'index-pattern',
getIconForSavedObject: () => 'indexPatternApp',
name: i18n.translate(
'kbn.visualize.newVisWizard.searchSelection.savedObjectType.indexPattern',
'visualizations.newVisWizard.searchSelection.savedObjectType.indexPattern',
{
defaultMessage: 'Index pattern',
}
Expand Down
Loading

0 comments on commit 6086487

Please sign in to comment.