Skip to content

Commit

Permalink
Refactor Visualize routes into VisualizeConstants file. Fix functiona…
Browse files Browse the repository at this point in the history
…l tests.
  • Loading branch information
cjcenizal committed Feb 4, 2017
1 parent 39ed424 commit 43ceb6e
Show file tree
Hide file tree
Showing 14 changed files with 48 additions and 27 deletions.
11 changes: 4 additions & 7 deletions src/core_plugins/kibana/public/visualize/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ import uiRoutes from 'ui/routes';
import uiModules from 'ui/modules';
import editorTemplate from 'plugins/kibana/visualize/editor/editor.html';
import { DashboardConstants } from 'plugins/kibana/dashboard/dashboard_constants';
import { VisualizeConstants } from '../visualize_constants';

uiRoutes
.when('/visualize/create', {
.when(VisualizeConstants.CREATE_URL, {
template: editorTemplate,
resolve: {
savedVis: function (savedVisualizations, courier, $route, Private) {
Expand All @@ -37,7 +38,7 @@ uiRoutes
}
}
})
.when('/visualize/edit/:id', {
.when(`${VisualizeConstants.EDIT_URL}/:id`, {
template: editorTemplate,
resolve: {
savedVis: function (savedVisualizations, courier, $route) {
Expand Down Expand Up @@ -286,10 +287,6 @@ function VisEditor($scope, $route, timefilter, AppState, $window, kbnUrl, courie
}
};

$scope.startOver = function () {
kbnUrl.change('/visualize', {});
};

/**
* Called when the user clicks "Save" button.
*/
Expand All @@ -315,7 +312,7 @@ function VisEditor($scope, $route, timefilter, AppState, $window, kbnUrl, courie
} else if (savedVis.id === $route.current.params.id) {
docTitle.change(savedVis.lastSavedTitle);
} else {
kbnUrl.change('/visualize/edit/{{id}}', { id: savedVis.id });
kbnUrl.change(`${VisualizeConstants.EDIT_URL}/{{id}}`, { id: savedVis.id });
}
}
}, notify.fatal);
Expand Down
3 changes: 2 additions & 1 deletion src/core_plugins/kibana/public/visualize/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ import uiRoutes from 'ui/routes';

import visualizeListingTemplate from './listing/visualize_listing.html';
import { VisualizeListingController } from './listing/visualize_listing';
import { VisualizeConstants } from './visualize_constants';

uiRoutes
.defaults(/visualize/, {
requireDefaultIndex: true
})
.when('/visualize', {
.when(VisualizeConstants.LANDING_PAGE_URL, {
template: visualizeListingTemplate,
controller: VisualizeListingController,
controllerAs: 'listingController',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const VisualizeConstants = {
LANDING_PAGE_URL: '/visualize',
WIZARD_STEP_1_PAGE_URL: '/visualize/new',
WIZARD_STEP_2_PAGE_URL: '/visualize/new/configure',
CREATE_URL: '/visualize/create',
EDIT_URL: '/visualize/edit',
};
34 changes: 25 additions & 9 deletions src/core_plugins/kibana/public/visualize/wizard/wizard.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

import 'plugins/kibana/visualize/saved_visualizations/saved_visualizations';
import 'ui/directives/saved_object_finder';
import 'ui/directives/paginated_selectable_list';
import 'plugins/kibana/discover/saved_searches/saved_searches';
import { DashboardConstants } from 'plugins/kibana/dashboard/dashboard_constants';
import { VisualizeConstants } from '../visualize_constants';
import routes from 'ui/routes';
import RegistryVisTypesProvider from 'ui/registry/vis_types';
import uiModules from 'ui/modules';
Expand All @@ -15,7 +15,7 @@ const module = uiModules.get('app/visualize', ['kibana/courier']);
/********
/** Wizard Step 1
/********/
routes.when('/visualize/new', {
routes.when(VisualizeConstants.WIZARD_STEP_1_PAGE_URL, {
template: visualizeWizardStep1Template,
controller: 'VisualizeWizardStep1',
});
Expand All @@ -27,9 +27,15 @@ module.controller('VisualizeWizardStep1', function ($scope, $route, kbnUrl, time
kbnUrl.removeParam(DashboardConstants.ADD_VISUALIZATION_TO_DASHBOARD_MODE_PARAM);

$scope.visTypes = Private(RegistryVisTypesProvider);

$scope.visTypeUrl = function (visType) {
const baseUrl = visType.requiresSearch ? '#/visualize/new/configure?' : '#/visualize/create?';
const baseUrl =
visType.requiresSearch
? `#${VisualizeConstants.WIZARD_STEP_2_PAGE_URL}?`
: `#${VisualizeConstants.CREATE_URL}?`;

const params = [`type=${encodeURIComponent(visType.name)}`];

if (addToDashMode) {
params.push(DashboardConstants.ADD_VISUALIZATION_TO_DASHBOARD_MODE_PARAM);
}
Expand All @@ -41,7 +47,7 @@ module.controller('VisualizeWizardStep1', function ($scope, $route, kbnUrl, time
/********
/** Wizard Step 2
/********/
routes.when('/visualize/new/configure', {
routes.when(VisualizeConstants.WIZARD_STEP_2_PAGE_URL, {
template: visualizeWizardStep2Template,
controller: 'VisualizeWizardStep2',
resolve: {
Expand All @@ -59,10 +65,17 @@ module.controller('VisualizeWizardStep2', function ($route, $scope, timefilter,
$scope.step2WithSearchUrl = function (hit) {
if (addToDashMode) {
return kbnUrl.eval(
`#/visualize/create?&type={{type}}&savedSearchId={{id}}&${DashboardConstants.ADD_VISUALIZATION_TO_DASHBOARD_MODE_PARAM}`,
{ type: type, id: hit.id });
`#${VisualizeConstants.CREATE_URL}` +
`?type={{type}}&savedSearchId={{id}}` +
`&${DashboardConstants.ADD_VISUALIZATION_TO_DASHBOARD_MODE_PARAM}`,
{ type: type, id: hit.id }
);
}
return kbnUrl.eval('#/visualize/create?&type={{type}}&savedSearchId={{id}}', { type: type, id: hit.id });

return kbnUrl.eval(
`#${VisualizeConstants.CREATE_URL}?type={{type}}&savedSearchId={{id}}`,
{ type: type, id: hit.id }
);
};

timefilter.enabled = false;
Expand All @@ -76,8 +89,11 @@ module.controller('VisualizeWizardStep2', function ($route, $scope, timefilter,
if (!pattern) return;

if (addToDashMode) {
return `#/visualize/create?${DashboardConstants.ADD_VISUALIZATION_TO_DASHBOARD_MODE_PARAM}&type=${type}&indexPattern=${pattern}`;
return `#${VisualizeConstants.CREATE_URL}` +
`?${DashboardConstants.ADD_VISUALIZATION_TO_DASHBOARD_MODE_PARAM}` +
`&type=${type}&indexPattern=${pattern}`;
}
return `#/visualize/create?type=${type}&indexPattern=${pattern}`;

return `#${VisualizeConstants.CREATE_URL}?type=${type}&indexPattern=${pattern}`;
};
});
2 changes: 1 addition & 1 deletion test/functional/apps/visualize/_area_chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ bdd.describe('visualize app', function describeIndexTests() {
const toTime = '2015-09-23 18:31:44.000';

PageObjects.common.debug('navigateToApp visualize');
return PageObjects.common.navigateToUrl('visualize', 'step/1')
return PageObjects.common.navigateToUrl('visualize', 'new')
.then(function () {
PageObjects.common.debug('clickAreaChart');
return PageObjects.visualize.clickAreaChart();
Expand Down
2 changes: 1 addition & 1 deletion test/functional/apps/visualize/_chart_types.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ bdd.describe('visualize app', function describeIndexTests() {

bdd.before(function () {
PageObjects.common.debug('navigateToApp visualize');
return PageObjects.common.navigateToUrl('visualize', 'step/1');
return PageObjects.common.navigateToUrl('visualize', 'new');
});

bdd.describe('chart types', function indexPatternCreation() {
Expand Down
2 changes: 1 addition & 1 deletion test/functional/apps/visualize/_data_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ bdd.describe('visualize app', function describeIndexTests() {

bdd.before(function () {
PageObjects.common.debug('navigateToApp visualize');
return PageObjects.common.navigateToUrl('visualize', 'step/1')
return PageObjects.common.navigateToUrl('visualize', 'new')
.then(function () {
PageObjects.common.debug('clickDataTable');
return PageObjects.visualize.clickDataTable();
Expand Down
2 changes: 1 addition & 1 deletion test/functional/apps/visualize/_heatmap_chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ bdd.describe('visualize app', function describeIndexTests() {

bdd.before(function () {
PageObjects.common.debug('navigateToApp visualize');
return PageObjects.common.navigateToApp('visualize')
return PageObjects.common.navigateToUrl('visualize', 'new')
.then(function () {
PageObjects.common.debug('clickHeatmapChart');
return PageObjects.visualize.clickHeatmapChart();
Expand Down
2 changes: 1 addition & 1 deletion test/functional/apps/visualize/_line_chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ bdd.describe('visualize app', function describeIndexTests() {
const toTime = '2015-09-23 18:31:44.000';

PageObjects.common.debug('navigateToApp visualize');
return PageObjects.common.navigateToUrl('visualize', 'step/1')
return PageObjects.common.navigateToUrl('visualize', 'new')
.then(function () {
PageObjects.common.debug('clickLineChart');
return PageObjects.visualize.clickLineChart();
Expand Down
2 changes: 1 addition & 1 deletion test/functional/apps/visualize/_metric_chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ bdd.describe('visualize app', function describeIndexTests() {

bdd.before(function () {
PageObjects.common.debug('navigateToApp visualize');
return PageObjects.common.navigateToUrl('visualize', 'step/1')
return PageObjects.common.navigateToUrl('visualize', 'new')
.then(function () {
PageObjects.common.debug('clickMetric');
return PageObjects.visualize.clickMetric();
Expand Down
2 changes: 1 addition & 1 deletion test/functional/apps/visualize/_pie_chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ bdd.describe('visualize app', function describeIndexTests() {
const toTime = '2015-09-23 18:31:44.000';

PageObjects.common.debug('navigateToApp visualize');
return PageObjects.common.navigateToUrl('visualize', 'step/1')
return PageObjects.common.navigateToUrl('visualize', 'new')
.then(function () {
PageObjects.common.debug('clickPieChart');
return PageObjects.visualize.clickPieChart();
Expand Down
2 changes: 1 addition & 1 deletion test/functional/apps/visualize/_tile_map.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ bdd.describe('visualize app', function describeIndexTests() {
bdd.before(function () {

PageObjects.common.debug('navigateToApp visualize');
return PageObjects.common.navigateToUrl('visualize', 'step/1')
return PageObjects.common.navigateToUrl('visualize', 'new')
.then(function () {
PageObjects.common.debug('clickTileMap');
return PageObjects.visualize.clickTileMap();
Expand Down
2 changes: 1 addition & 1 deletion test/functional/apps/visualize/_vertical_bar_chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ bdd.describe('visualize app', function describeIndexTests() {

bdd.before(function () {
PageObjects.common.debug('navigateToApp visualize');
return PageObjects.common.navigateToUrl('visualize', 'step/1')
return PageObjects.common.navigateToUrl('visualize', 'new')
.then(function () {
PageObjects.common.debug('clickVerticalBarChart');
return PageObjects.visualize.clickVerticalBarChart();
Expand Down
2 changes: 1 addition & 1 deletion test/support/page_objects/visualize_page.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ export default class VisualizePage {
clickLoadSavedVisButton() {
// TODO: Use a test subject selector once we rewrite breadcrumbs to accept each breadcrumb
// element as a child instead of building the breadcrumbs dynamically.
return self.remote
return this.remote
.setFindTimeout(defaultFindTimeout)
.findByCssSelector('[href="#/visualize"]')
.click();
Expand Down

0 comments on commit 43ceb6e

Please sign in to comment.