Skip to content

Commit

Permalink
ui: Fix sticky namespace selector (#11830)
Browse files Browse the repository at this point in the history
When adding a namespace via the UI, the app model which contains a list
of namespace isn't refreshed. This means when we use the same list after
adding a namespace to search for the namespace that is contained in the
URL, if that namespace in the URL is the new one, its is not found, and
therefore the menu does not get 'selected' properly, leaving a default
selection of 'default'

This commit instead uses peekAll of the Ember Data store to access the
entire list of cached namespaces instead of using the now stale
app.nspaces one.
  • Loading branch information
johncowen authored Dec 15, 2021
1 parent 073544a commit aafc02b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 4 additions & 0 deletions .changelog/11830.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
```release-note:bug
ui: Fixes an issue where under some circumstances the namespace selector could
become 'stuck' on the default namespace
```
9 changes: 4 additions & 5 deletions ui/packages/consul-ui/app/routes/dc.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,19 @@ export default class DcRoute extends Route {
@service('repository/dc') repo;
@service('repository/nspace/disabled') nspacesRepo;
@service('settings') settingsRepo;
@service('store') store;

async model(params) {
const app = this.modelFor('application');

let [token, nspace, dc] = await Promise.all([
this.settingsRepo.findBySlug('token'),
this.nspacesRepo.getActive(),
this.repo.findBySlug(params.dc, app.dcs),
this.repo.findBySlug(params.dc, this.store.peekAll('dc')),
]);
// if there is only 1 namespace then use that
// otherwise find the namespace object that corresponds
// to the active one
nspace =
app.nspaces.length > 1 ? findActiveNspace(app.nspaces, nspace) : app.nspaces.firstObject;
const nspaces = this.store.peekAll('nspace');
nspace = findActiveNspace(nspaces, nspace);

let permissions;
if (get(token, 'SecretID')) {
Expand Down

0 comments on commit aafc02b

Please sign in to comment.