Skip to content

Commit

Permalink
Ensure the current nspace is shown on the settings page
Browse files Browse the repository at this point in the history
The settings page is alittle strange as its the only URL that doesn't
have dc and nspace informaiton in it. Therefore for DCs we save the last
DC viewed in localStorage and read it from there is we can't figure it
out from the URL.

This takes the same approach for nspaces
  • Loading branch information
John Cowen committed Nov 18, 2019
1 parent fd6746f commit 56054ef
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion ui-v2/app/instance-initializers/nspace.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import config from 'consul-ui/config/environment';
export function initialize(container) {
if (config.CONSUL_NSPACES_ENABLED) {
['dc', 'dc.intentions.edit', 'dc.intentions.create'].forEach(function(item) {
['dc', 'settings', 'dc.intentions.edit', 'dc.intentions.create'].forEach(function(item) {
container.inject(`route:${item}`, 'nspaceRepo', 'service:repository/nspace/enabled');
container.inject(`route:nspace.${item}`, 'nspaceRepo', 'service:repository/nspace/enabled');
});
Expand Down
4 changes: 2 additions & 2 deletions ui-v2/app/routes/dc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ export default Route.extend({
model: function(params) {
const repo = this.repo;
const nspaceRepo = this.nspaceRepo;
const nspace = this.nspaceRepo.getActive();
return hash({
dcs: repo.findAll(),
nspaces: nspaceRepo.findAll(),
nspace: this.nspaceRepo.getActive(),
}).then(function(model) {
return hash({
...model,
Expand All @@ -24,7 +24,7 @@ export default Route.extend({
nspace:
model.nspaces.length > 1
? model.nspaces.find(function(item) {
return item.Name === nspace.Name;
return item.Name === model.nspace.Name;
})
: model.nspaces.firstObject,
},
Expand Down
4 changes: 4 additions & 0 deletions ui-v2/app/routes/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ export default Route.extend({
client: service('client/http'),
repo: service('settings'),
dcRepo: service('repository/dc'),
nspaceRepo: service('repository/nspace/disabled'),
model: function(params) {
const nspace = this.nspaceRepo.getActive();
return hash({
item: this.repo.findAll(),
dcs: this.dcRepo.findAll(),
nspaces: this.nspaceRepo.findAll(),
nspace: this.nspaceRepo.getActive(),
}).then(model => {
if (typeof get(model.item, 'client.blocking') === 'undefined') {
set(model, 'item.client', { blocking: true });
Expand Down
1 change: 1 addition & 0 deletions ui-v2/app/services/repository/dc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import RepositoryService from 'consul-ui/services/repository';
import { inject as service } from '@ember/service';
import { get } from '@ember/object';
import Error from '@ember/error';
import { Promise } from 'rsvp';

const modelName = 'dc';
export default RepositoryService.extend({
Expand Down
19 changes: 15 additions & 4 deletions ui-v2/app/services/repository/nspace/enabled.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { inject as service } from '@ember/service';
import { get } from '@ember/object';
import { Promise } from 'rsvp';
import config from 'consul-ui/config/environment';
import RepositoryService from 'consul-ui/services/repository';

Expand Down Expand Up @@ -44,9 +45,19 @@ export default RepositoryService.extend({
}
}
}
// If we can't figure out the nspace from the URL just use default
return {
Name: (routeParams.nspace || `~default`).substr(1),
};
return this.settings
.findBySlug('nspace')
.then(function(nspace) {
// If we can't figure out the nspace from the URL use
// the previously saved nspace and if thats not there
// then just use default
return routeParams.nspace || nspace || '~default';
})
.then(nspace => this.settings.persist({ nspace: nspace }))
.then(function(item) {
return {
Name: item.nspace.substr(1),
};
});
},
});
2 changes: 1 addition & 1 deletion ui-v2/app/templates/dc.hbs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{{#hashicorp-consul id="wrapper" dcs=dcs dc=dc nspaces=nspaces nspace=nspace}}
{{outlet}}
{{outlet}}
{{/hashicorp-consul}}

0 comments on commit 56054ef

Please sign in to comment.