open-nomad/ui/app/components/gutter-menu.js
Michael Lange b3fe5b4f75 Changing namespaces now situationally redirects to jobs or volumes
Changing namespaces can be done anywhere in the app even though many
Nomad resources aren't namespace-sensitive (e.g., clients, plugins).

A user changing namespaces is an intent to reset context, "now I want
to begin a task that relates to Namespace X". Where that task begins
used to always be the Jobs list, since it was the only namespace
sensitive resource. Now with CSI Volumes, "square 1" is Volumes if the
namespace is changed from a storage page.
2020-05-08 17:35:27 -07:00

51 lines
1.4 KiB
JavaScript

import { inject as service } from '@ember/service';
import Component from '@ember/component';
import { computed } from '@ember/object';
export default Component.extend({
system: service(),
router: service(),
sortedNamespaces: computed('system.namespaces.@each.name', function() {
const namespaces = this.get('system.namespaces').toArray() || [];
return namespaces.sort((a, b) => {
const aName = a.get('name');
const bName = b.get('name');
// Make sure the default namespace is always first in the list
if (aName === 'default') {
return -1;
}
if (bName === 'default') {
return 1;
}
if (aName < bName) {
return -1;
}
if (aName > bName) {
return 1;
}
return 0;
});
}),
onHamburgerClick() {},
gotoJobsForNamespace(namespace) {
if (!namespace || !namespace.get('id')) return;
// Jobs and CSI Volumes are both namespace-sensitive. Changing namespaces is
// an intent to reset context, but where to reset to depends on where the namespace
// is being switched from. Jobs take precedence, but if the namespace is switched from
// a storage-related page, context should be reset to volumes.
const destination = this.router.currentRouteName.startsWith('csi.') ? 'csi.volumes' : 'jobs';
this.router.transitionTo(destination, {
queryParams: { namespace: namespace.get('id') },
});
},
});