Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove namespace cache #13679

Merged
merged 11 commits into from
Jul 11, 2022
3 changes: 3 additions & 0 deletions .changelog/13679.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
ui: Namespace filter query paramters are now isolated by route
```
10 changes: 2 additions & 8 deletions ui/app/controllers/csi/volumes/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { set } from '@ember/object';
import { inject as service } from '@ember/service';
import { action, computed } from '@ember/object';
import { alias, readOnly } from '@ember/object/computed';
Expand Down Expand Up @@ -64,7 +63,7 @@ export default class IndexController extends Controller.extend(

fuzzySearchEnabled = true;

@computed('qpNamespace', 'model.namespaces.[]', 'system.cachedNamespace')
@computed('qpNamespace', 'model.namespaces.[]')
get optionsNamespaces() {
const availableNamespaces = this.model.namespaces.map((namespace) => ({
key: namespace.name,
Expand All @@ -81,7 +80,7 @@ export default class IndexController extends Controller.extend(
// eslint-disable-next-line ember/no-incorrect-calls-with-inline-anonymous-functions
scheduleOnce('actions', () => {
// eslint-disable-next-line ember/no-side-effects
this.set('qpNamespace', this.system.cachedNamespace || '*');
this.set('qpNamespace', '*');
});
}

Expand All @@ -101,11 +100,6 @@ export default class IndexController extends Controller.extend(
@alias('listSorted') listToSearch;
@alias('listSearched') sortedVolumes;

@action
cacheNamespace(namespace) {
set(this, 'system.cachedNamespace', namespace);
}

setFacetQueryParam(queryParam, selection) {
this.set(queryParam, serialize(selection));
}
Expand Down
12 changes: 3 additions & 9 deletions ui/app/controllers/jobs/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/* eslint-disable ember/no-incorrect-calls-with-inline-anonymous-functions */
import { set } from '@ember/object';
import { inject as service } from '@ember/service';
import { alias, readOnly } from '@ember/object/computed';
import Controller from '@ember/controller';
import { action, computed } from '@ember/object';
import { computed } from '@ember/object';
import { scheduleOnce } from '@ember/runloop';
import intersection from 'lodash.intersection';
import Sortable from 'nomad-ui/mixins/sortable';
Expand Down Expand Up @@ -165,7 +164,7 @@ export default class IndexController extends Controller.extend(
}));
}

@computed('qpNamespace', 'model.namespaces.[]', 'system.cachedNamespace')
@computed('qpNamespace', 'model.namespaces.[]')
get optionsNamespaces() {
const availableNamespaces = this.model.namespaces.map((namespace) => ({
key: namespace.name,
Expand All @@ -181,7 +180,7 @@ export default class IndexController extends Controller.extend(
if (!availableNamespaces.mapBy('key').includes(this.qpNamespace)) {
scheduleOnce('actions', () => {
// eslint-disable-next-line ember/no-side-effects
this.set('qpNamespace', this.system.cachedNamespace || '*');
this.set('qpNamespace', '*');
});
}

Expand Down Expand Up @@ -252,11 +251,6 @@ export default class IndexController extends Controller.extend(

isShowingDeploymentDetails = false;

@action
cacheNamespace(namespace) {
set(this, 'system.cachedNamespace', namespace);
}

setFacetQueryParam(queryParam, selection) {
this.set(queryParam, serialize(selection));
}
Expand Down
7 changes: 1 addition & 6 deletions ui/app/controllers/optimize.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export default class OptimizeController extends Controller {
if (!availableNamespaces.mapBy('key').includes(this.qpNamespace)) {
scheduleOnce('actions', () => {
// eslint-disable-next-line ember/no-side-effects
this.qpNamespace = this.system.cachedNamespace || '*';
this.qpNamespace = '*';
});
}

Expand Down Expand Up @@ -247,11 +247,6 @@ export default class OptimizeController extends Controller {
});
}

@action
cacheNamespace(namespace) {
this.system.cachedNamespace = namespace;
}

@action
setFacetQueryParam(queryParam, selection) {
this[queryParam] = serialize(selection);
Expand Down
7 changes: 0 additions & 7 deletions ui/app/services/system.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Service, { inject as service } from '@ember/service';
import { computed } from '@ember/object';
import { tracked } from '@glimmer/tracking';
import { alias } from '@ember/object/computed';
import PromiseObject from '../utils/classes/promise-object';
import PromiseArray from '../utils/classes/promise-array';
Expand Down Expand Up @@ -132,12 +131,6 @@ export default class SystemService extends Service {
);
}

// The cachedNamespace is set on pages that have a namespaces filter.
// It is set so other pages that have a namespaces filter can default to
// what the previous namespaces filter page used rather than defaulting
// to 'default' or '*'.
@tracked cachedNamespace = null;

@task(function* () {
const emptyLicense = { License: { Features: [] } };

Expand Down
4 changes: 1 addition & 3 deletions ui/app/templates/csi/volumes/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@
@label="Namespace"
@options={{this.optionsNamespaces}}
@selection={{this.qpNamespace}}
@onSelect={{action
(queue (action this.cacheNamespace) (action this.setFacetQueryParam "qpNamespace"))
}}
@onSelect={{action this.setFacetQueryParam "qpNamespace"}}
/>
</div>
</div>
Expand Down
7 changes: 1 addition & 6 deletions ui/app/templates/jobs/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,7 @@
@label="Namespace"
@options={{this.optionsNamespaces}}
@selection={{this.qpNamespace}}
@onSelect={{action
(queue
(action this.cacheNamespace)
(action this.setFacetQueryParam "qpNamespace")
)
}}
@onSelect={{action this.setFacetQueryParam "qpNamespace"}}
/>
{{/if}}
<MultiSelectDropdown
Expand Down
7 changes: 1 addition & 6 deletions ui/app/templates/optimize.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,7 @@
@label="Namespace"
@options={{this.optionsNamespaces}}
@selection={{this.qpNamespace}}
@onSelect={{action
(queue
(action this.cacheNamespace)
(action this.setFacetQueryParam "qpNamespace")
)
}}
@onSelect={{action this.setFacetQueryParam "qpNamespace"}}
/>
{{/if}}
<MultiSelectDropdown
Expand Down
14 changes: 0 additions & 14 deletions ui/tests/acceptance/jobs-list-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { setupMirage } from 'ember-cli-mirage/test-support';
import a11yAudit from 'nomad-ui/tests/helpers/a11y-audit';
import pageSizeSelect from './behaviors/page-size-select';
import JobsList from 'nomad-ui/tests/pages/jobs/list';
import Layout from 'nomad-ui/tests/pages/layout';
import percySnapshot from '@percy/ember';

let managementToken, clientToken;
Expand Down Expand Up @@ -423,19 +422,6 @@ module('Acceptance | jobs list', function (hooks) {
);
});

test('the active namespace is carried over to the storage pages', async function (assert) {
server.createList('namespace', 2);

const namespace = server.db.namespaces[1];
await JobsList.visit();
await JobsList.facets.namespace.toggle();
await JobsList.facets.namespace.options.objectAt(2).select();

await Layout.gutter.visitStorage();

assert.equal(currentURL(), `/csi/volumes?namespace=${namespace.id}`);
});

test('when the user has a client token that has a namespace with a policy to run a job', async function (assert) {
const READ_AND_WRITE_NAMESPACE = 'read-and-write-namespace';
const READ_ONLY_NAMESPACE = 'read-only-namespace';
Expand Down
13 changes: 13 additions & 0 deletions ui/tests/acceptance/optimize-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ module('Acceptance | optimize', function (hooks) {
.flat()
.find((r) => r.resource === 'CPU');

const currentTaskGroupHasMemoryRecommendation =
currentTaskGroup.tasks.models
.mapBy('recommendations.models')
.flat()
.find((r) => r.resource === 'MemoryMB');

// If no CPU recommendation, will not be able to accept recommendation with all memory recommendations turned off

if (!currentTaskGroupHasCPURecommendation) {
Expand All @@ -85,6 +91,13 @@ module('Acceptance | optimize', function (hooks) {
resource: 'CPU',
});
}
if (!currentTaskGroupHasMemoryRecommendation) {
const currentTaskGroupTask = currentTaskGroup.tasks.models[0];
this.server.create('recommendation', {
task: currentTaskGroupTask,
resource: 'MemoryMB',
});
}

await Optimize.visit();

Expand Down
15 changes: 0 additions & 15 deletions ui/tests/acceptance/volumes-list-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import { setupMirage } from 'ember-cli-mirage/test-support';
import a11yAudit from 'nomad-ui/tests/helpers/a11y-audit';
import pageSizeSelect from './behaviors/page-size-select';
import VolumesList from 'nomad-ui/tests/pages/storage/volumes/list';
import Layout from 'nomad-ui/tests/pages/layout';
import percySnapshot from '@percy/ember';

const assignWriteAlloc = (volume, alloc) => {
volume.writeAllocs.add(alloc);
volume.allocations.add(alloc);
Expand Down Expand Up @@ -193,19 +191,6 @@ module('Acceptance | volumes list', function (hooks) {
assert.equal(VolumesList.volumes.objectAt(0).name, volume2.id);
});

test('the active namespace is carried over to the jobs pages', async function (assert) {
server.createList('namespace', 2);

const namespace = server.db.namespaces[1];
await VolumesList.visit();
await VolumesList.facets.namespace.toggle();
await VolumesList.facets.namespace.options.objectAt(2).select();

await Layout.gutter.visitJobs();

assert.equal(currentURL(), `/jobs?namespace=${namespace.id}`);
});

test('when accessing volumes is forbidden, a message is shown with a link to the tokens page', async function (assert) {
server.pretender.get('/v1/volumes', () => [403, {}, null]);

Expand Down