From 87bc85d2d18077652636a1399dd4458d00773306 Mon Sep 17 00:00:00 2001 From: Matthew Irish Date: Wed, 28 Nov 2018 11:06:37 -0600 Subject: [PATCH 1/4] centralize page size setting, and default to page size of 5 in dev --- ui/app/routes/vault/cluster/policies/index.js | 1 - ui/app/services/store.js | 7 ++++++- ui/config/environment.js | 3 +++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/ui/app/routes/vault/cluster/policies/index.js b/ui/app/routes/vault/cluster/policies/index.js index 831d7725db03..a1aac6911f37 100644 --- a/ui/app/routes/vault/cluster/policies/index.js +++ b/ui/app/routes/vault/cluster/policies/index.js @@ -27,7 +27,6 @@ export default Route.extend(ClusterRoute, ListRoute, { page: params.page, pageFilter: params.pageFilter, responsePath: 'data.keys', - size: 100, }) .catch(err => { // acls will never be empty, but sentinel policies can be diff --git a/ui/app/services/store.js b/ui/app/services/store.js index c5254742235b..e9aa21107975 100644 --- a/ui/app/services/store.js +++ b/ui/app/services/store.js @@ -6,6 +6,9 @@ import { assert } from '@ember/debug'; import { set, get, computed } from '@ember/object'; import DS from 'ember-data'; import clamp from 'vault/utils/clamp'; +import config from 'vault/config/environment'; + +const { DEFAULT_PAGE_SIZE } = config.APP; export function normalizeModelName(modelName) { return dasherize(modelName); @@ -69,7 +72,9 @@ export default DS.Store.extend({ const responsePath = query.responsePath; assert('responsePath is required', responsePath); assert('page is required', typeof query.page === 'number'); - assert('size is required', query.size); + if (!query.size) { + query.size = DEFAULT_PAGE_SIZE; + } if (dataCache) { return resolve(this.fetchPage(modelName, query)); diff --git a/ui/config/environment.js b/ui/config/environment.js index b0d4b92ba716..43558df1adfb 100644 --- a/ui/config/environment.js +++ b/ui/config/environment.js @@ -24,6 +24,8 @@ module.exports = function(environment) { // endpoints that UI uses to determine the cluster state // calls to these endpoints will always go to the root namespace NAMESPACE_ROOT_URLS: ['sys/health', 'sys/seal-status', 'sys/license/features'], + // number of records to show on a single page by default - this is used by the client-side pagination + DEFAULT_PAGE_SIZE: 100, }, flashMessageDefaults: { timeout: 7000, @@ -60,6 +62,7 @@ module.exports = function(environment) { ENV.flashMessageDefaults.timeout = 50; } if (environment !== 'production') { + ENV.APP.DEFAULT_PAGE_SIZE = 5; ENV.contentSecurityPolicyHeader = 'Content-Security-Policy'; ENV.contentSecurityPolicyMeta = true; ENV.contentSecurityPolicy = { From 2972478fd0799c7d5bb88ad3cc510f60e6f26648 Mon Sep 17 00:00:00 2001 From: Matthew Irish Date: Wed, 28 Nov 2018 11:12:53 -0600 Subject: [PATCH 2/4] remove size arg when using lazyPaginatedQuery so that the app uses the config default size --- ui/app/routes/vault/cluster/access/identity/aliases/index.js | 1 - ui/app/routes/vault/cluster/access/identity/index.js | 1 - ui/app/routes/vault/cluster/access/leases/list.js | 1 - ui/app/routes/vault/cluster/secrets/backend/list.js | 1 - 4 files changed, 4 deletions(-) diff --git a/ui/app/routes/vault/cluster/access/identity/aliases/index.js b/ui/app/routes/vault/cluster/access/identity/aliases/index.js index 46b134329fbb..abee732e5bea 100644 --- a/ui/app/routes/vault/cluster/access/identity/aliases/index.js +++ b/ui/app/routes/vault/cluster/access/identity/aliases/index.js @@ -10,7 +10,6 @@ export default Route.extend(ListRoute, { responsePath: 'data.keys', page: params.page, pageFilter: params.pageFilter, - size: 100, }) .catch(err => { if (err.httpStatus === 404) { diff --git a/ui/app/routes/vault/cluster/access/identity/index.js b/ui/app/routes/vault/cluster/access/identity/index.js index 2d453df15166..a9a983ecdd36 100644 --- a/ui/app/routes/vault/cluster/access/identity/index.js +++ b/ui/app/routes/vault/cluster/access/identity/index.js @@ -10,7 +10,6 @@ export default Route.extend(ListRoute, { responsePath: 'data.keys', page: params.page, pageFilter: params.pageFilter, - size: 100, }) .catch(err => { if (err.httpStatus === 404) { diff --git a/ui/app/routes/vault/cluster/access/leases/list.js b/ui/app/routes/vault/cluster/access/leases/list.js index 7c417c778c25..e56f23d49739 100644 --- a/ui/app/routes/vault/cluster/access/leases/list.js +++ b/ui/app/routes/vault/cluster/access/leases/list.js @@ -24,7 +24,6 @@ export default Route.extend({ responsePath: 'data.keys', page: params.page, pageFilter: params.pageFilter, - size: 100, }) .then(model => { this.set('has404', false); diff --git a/ui/app/routes/vault/cluster/secrets/backend/list.js b/ui/app/routes/vault/cluster/secrets/backend/list.js index 3171d1249e6b..2e861d4ee59b 100644 --- a/ui/app/routes/vault/cluster/secrets/backend/list.js +++ b/ui/app/routes/vault/cluster/secrets/backend/list.js @@ -63,7 +63,6 @@ export default Route.extend({ responsePath: 'data.keys', page: params.page, pageFilter: params.pageFilter, - size: 100, }) .then(model => { this.set('has404', false); From 63460b12d47eafb5f9a1513c8c59f523253ded14 Mon Sep 17 00:00:00 2001 From: Matthew Irish Date: Wed, 28 Nov 2018 11:29:12 -0600 Subject: [PATCH 3/4] move list-pagination component out of the loop --- ui/app/templates/vault/cluster/policies/index.hbs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/ui/app/templates/vault/cluster/policies/index.hbs b/ui/app/templates/vault/cluster/policies/index.hbs index da7b5bc80b7b..c8f254c61e7f 100644 --- a/ui/app/templates/vault/cluster/policies/index.hbs +++ b/ui/app/templates/vault/cluster/policies/index.hbs @@ -139,18 +139,18 @@ {{/linked-block}} {{/if}} - {{#if (gt model.meta.lastPage 1) }} - {{list-pagination - page=model.meta.currentPage - lastPage=model.meta.lastPage - link="vault.cluster.policies.index" - }} - {{/if}} {{else}} {{/each}} + {{#if (gt model.meta.lastPage 1) }} + {{list-pagination + page=model.meta.currentPage + lastPage=model.meta.lastPage + link="vault.cluster.policies.index" + }} + {{/if}} {{else}} Date: Wed, 28 Nov 2018 16:05:41 -0600 Subject: [PATCH 4/4] update store tests --- ui/tests/unit/services/store-test.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/ui/tests/unit/services/store-test.js b/ui/tests/unit/services/store-test.js index 1a5ba7a8d15d..88b7f5fa3997 100644 --- a/ui/tests/unit/services/store-test.js +++ b/ui/tests/unit/services/store-test.js @@ -4,6 +4,9 @@ import { module, test } from 'qunit'; import { setupTest } from 'ember-qunit'; import { normalizeModelName, keyForCache } from 'vault/services/store'; import clamp from 'vault/utils/clamp'; +import config from 'vault/config/environment'; + +const { DEFAULT_PAGE_SIZE } = config.APP; module('Unit | Service | store', function(hooks) { setupTest(hooks); @@ -197,10 +200,12 @@ module('Unit | Service | store', function(hooks) { let response = { data: ['foo'], }; + let queryArgs; const store = this.owner.factoryFor('service:store').create({ adapterFor() { return { - query() { + query(store, modelName, query) { + queryArgs = query; return resolve(response); }, }; @@ -217,6 +222,12 @@ module('Unit | Service | store', function(hooks) { { response: { data: null }, dataset: ['foo'] }, 'stores returned dataset' ); + + run(function() { + store.lazyPaginatedQuery('secret', { page: 1, responsePath: 'data' }); + }); + assert.equal(queryArgs.size, DEFAULT_PAGE_SIZE, 'calls query with DEFAULT_PAGE_SIZE'); + assert.throws( () => { store.lazyPaginatedQuery('transit-key', {}); @@ -231,12 +242,5 @@ module('Unit | Service | store', function(hooks) { /page is required/, 'requires page' ); - assert.throws( - () => { - store.lazyPaginatedQuery('transit-key', { responsePath: 'foo', page: 1 }); - }, - /size is required/, - 'requires size' - ); }); });