Skip to content

Commit

Permalink
Merge pull request elastic#7516 from tylersmalley/7481-require-index-…
Browse files Browse the repository at this point in the history
…pattern

Adds route option for requireDefaultIndex

Former-commit-id: b4c3991
  • Loading branch information
tylersmalley authored Jun 22, 2016
2 parents 7efd342 + 826db3a commit ce2bab2
Show file tree
Hide file tree
Showing 16 changed files with 68 additions and 20 deletions.
6 changes: 3 additions & 3 deletions src/plugins/kibana/public/dashboard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,8 @@ import uiRoutes from 'ui/routes';
import uiModules from 'ui/modules';
import indexTemplate from 'plugins/kibana/dashboard/index.html';



require('ui/saved_objects/saved_object_registry').register(require('plugins/kibana/dashboard/services/saved_dashboard_register'));


const app = uiModules.get('app/dashboard', [
'elasticsearch',
'ngRoute',
Expand All @@ -33,6 +30,9 @@ const app = uiModules.get('app/dashboard', [
]);

uiRoutes
.defaults(/dashboard/, {
requireDefaultIndex: true
})
.when('/dashboard', {
template: indexTemplate,
resolve: {
Expand Down
3 changes: 3 additions & 0 deletions src/plugins/kibana/public/discover/controllers/discover.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ const app = uiModules.get('apps/discover', [
]);

uiRoutes
.defaults(/discover/, {
requireDefaultIndex: true
})
.when('/discover/:id?', {
template: indexTemplate,
reloadOnSearch: false,
Expand Down
1 change: 0 additions & 1 deletion src/plugins/kibana/public/management/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ uiRoutes
});

require('ui/index_patterns/route_setup/load_default')({
notRequiredRe: /^\/management\/data\//,
whenMissingRedirectTo: '/management/data/index'
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ const indexPatternsResolutions = {
// add a dependency to all of the subsection routes
uiRoutes
.defaults(/management\/kibana\/indices/, {
resolve: indexPatternsResolutions
resolve: indexPatternsResolutions,
requireDefaultIndex: true
});

uiRoutes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ <h4>Caution: You can break stuff here</h4>
<table class="table">
<thead>
<tr>
<th>Name</th>
<th>Value</th>
<th>Actions <kbn-info info="Edit or restore the default value."></kbn-info></th>
<th class="col-xs-4 col-sm-4">Name</th>
<th class="col-xs-4 col-sm-5">Value</th>
<th class="col-xs-3 col-sm-2">Actions <kbn-info info="Edit or restore the default value."></kbn-info></th>
</tr>
</thead>
<tbody>
Expand Down
8 changes: 6 additions & 2 deletions src/plugins/kibana/public/management/styles/main.less
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,12 @@ kbn-management-objects {
kbn-management-advanced {
// super specific rule to override bootstrap's equally specific rule
// https://github.com/twbs/bootstrap/blob/1f329f8f17aa989eabc6e94bdcab93e69ef0e463/less/tables.less#L35
.table > tbody > tr > td {
vertical-align: middle;
.table {
table-layout: fixed;

tbody > tr > td {
vertical-align: middle;
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/plugins/kibana/public/visualize/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import uiRoutes from 'ui/routes';


uiRoutes
.defaults(/visualize/, {
requireDefaultIndex: true
})
.when('/visualize', {
redirectTo: '/visualize/step/1'
});
Expand All @@ -28,4 +31,3 @@ uiRoutes

require('ui/saved_objects/saved_object_registry')
.register(require('plugins/kibana/visualize/saved_visualizations/saved_visualization_register'));

6 changes: 2 additions & 4 deletions src/ui/public/index_patterns/route_setup/load_default.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,27 @@ let notify = new Notifier({

module.exports = function (opts) {
opts = opts || {};
let notRequiredRe = opts.notRequiredRe || null;
let whenMissingRedirectTo = opts.whenMissingRedirectTo || null;
let defaultRequiredToasts = null;

uiRoutes
.addSetupWork(function loadDefaultIndexPattern(Private, Promise, $route, config, indexPatterns) {
let getIds = Private(GetIdsProvider);
let rootSearchSource = Private(CourierDataSourceRootSearchSourceProvider);
let path = _.get($route, 'current.$$route.originalPath');
let route = _.get($route, 'current.$$route');

return getIds()
.then(function (patterns) {
let defaultId = config.get('defaultIndex');
let defined = !!defaultId;
let exists = _.contains(patterns, defaultId);
let required = !notRequiredRe || !path.match(notRequiredRe);

if (defined && !exists) {
config.remove('defaultIndex');
defaultId = defined = false;
}

if (!defined && required) {
if (!defined && route.requireDefaultIndex) {
throw new NoDefaultIndexPattern();
}

Expand Down
12 changes: 12 additions & 0 deletions src/ui/public/routes/__tests__/_route_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,17 @@ describe('routes/route_manager', function () {
expect($rp.when.secondCall.args[1]).to.have.property('reloadOnSearch', false);
expect($rp.when.lastCall.args[1]).to.have.property('reloadOnSearch', true);
});

it('sets route.requireDefaultIndex to false by default', function () {
routes.when('/nothing-set');
routes.when('/no-index-required', { requireDefaultIndex: false });
routes.when('/index-required', { requireDefaultIndex: true });
routes.config($rp);

expect($rp.when.callCount).to.be(3);
expect($rp.when.firstCall.args[1]).to.have.property('requireDefaultIndex', false);
expect($rp.when.secondCall.args[1]).to.have.property('requireDefaultIndex', false);
expect($rp.when.lastCall.args[1]).to.have.property('requireDefaultIndex', true);
});
});
});
4 changes: 4 additions & 0 deletions src/ui/public/routes/route_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ function RouteManager() {
route.reloadOnSearch = false;
}

if (route.requireDefaultIndex === void 0) {
route.requireDefaultIndex = false;
}

wrapRouteWithPrep(route, setup);
$routeProvider.when(path, route);
});
Expand Down
3 changes: 3 additions & 0 deletions test/functional/apps/management/_creation_form_changes.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ bdd.describe('user input reactions', function () {
return esClient.deleteAndUpdateConfigDoc()
.then(function () {
return settingsPage.navigateTo();
})
.then(function () {
return settingsPage.clickExistingData();
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ bdd.describe('creating and deleting default index', function describeIndexTests(
return esClient.deleteAndUpdateConfigDoc()
.then(function () {
return settingsPage.navigateTo();
})
.then(function () {
return settingsPage.clickExistingData();
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ bdd.describe('index result field sort', function describeIndexTests() {
columns.forEach(function (col) {
bdd.describe('sort by heading - ' + col.heading, function indexPatternCreation() {
bdd.before(function () {
return settingsPage.navigateTo();
return settingsPage.navigateTo()
.then(function () {
return settingsPage.clickExistingData();
});
});

bdd.beforeEach(function () {
Expand Down
3 changes: 3 additions & 0 deletions test/functional/apps/management/_initial_state.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ bdd.describe('initial state', function () {
return esClient.deleteAndUpdateConfigDoc()
.then(function () {
return settingsPage.navigateTo();
})
.then(function () {
return settingsPage.clickExistingData();
});
});

Expand Down
6 changes: 6 additions & 0 deletions test/functional/apps/management/_kibana_settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ bdd.describe('creating and deleting default index', function describeIndexTests(
bdd.before(function () {
// delete .kibana index and then wait for Kibana to re-create it
return esClient.deleteAndUpdateConfigDoc()
.then(function () {
return settingsPage.navigateTo();
})
.then(function () {
return settingsPage.clickExistingData();
})
.then(function () {
return settingsPage.createIndexPattern();
})
Expand Down
15 changes: 11 additions & 4 deletions test/support/pages/settings_page.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,20 @@ export default (function () {
return this.remote.findDisplayedByCssSelector('.app-link:nth-child(5) a').click();
},

clickPath: function (path) {
return this.remote.findDisplayedByCssSelector('[kbn-href="#/management/' + path + '"]').click();
clickLinkText: function (text) {
return this.remote.findDisplayedByLinkText(text).click();
},

clickKibanaSettings: function () {
return this.clickPath('kibana/settings');
return this.clickLinkText('Advanced Settings');
},

clickKibanaIndicies: function () {
return this.clickPath('kibana/indices');
return this.clickLinkText('Index Patterns');
},

clickExistingData: function () {
return this.clickLinkText('Existing Data');
},

getAdvancedSettings: function getAdvancedSettings(propertyName) {
Expand Down Expand Up @@ -315,6 +319,9 @@ export default (function () {

return common.try(function () {
return self.navigateTo()
.then(function () {
return self.clickExistingData();
})
.then(function () {
return self.selectTimeFieldOption('@timestamp');
})
Expand Down

0 comments on commit ce2bab2

Please sign in to comment.