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

Add pagination to namespace list view #13195

Merged
merged 9 commits into from
Nov 29, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog/13195.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
ui: Added client side paging for namespace list view
```
5 changes: 5 additions & 0 deletions ui/app/adapters/namespace.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,9 @@ export default ApplicationAdapter.extend({
}
return this._super(...arguments);
},
query() {
return this.ajax(`/${this.urlPrefix()}/namespaces?list=true`).then(resp => {
arnav28 marked this conversation as resolved.
Show resolved Hide resolved
return resp;
});
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default Controller.extend({
refreshNamespaceList() {
// fetch new namespaces for the namespace picker
this.namespaceService.findNamespacesForUser.perform();
this.send('reload');
},
},
});
67 changes: 60 additions & 7 deletions ui/app/routes/vault/cluster/access/namespaces/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,74 @@ import Route from '@ember/routing/route';
import UnloadModel from 'vault/mixins/unload-model-route';

export default Route.extend(UnloadModel, {
queryParams: {
page: {
refreshModel: true,
},
},
version: service(),
beforeModel() {
this.store.unloadAll('namespace');
return this.version.fetchFeatures().then(() => {
return this._super(...arguments);
});
},
model() {
return this.version.hasNamespaces
? this.store.findAll('namespace').catch(e => {
if (e.httpStatus === 404) {

model(params) {
if (this.version.hasNamespaces) {
return this.store
.lazyPaginatedQuery('namespace', {
responsePath: 'data.keys',
page: Number(params?.page) || 1,
})
.then(model => {
return model;
})
.catch(err => {
if (err.httpStatus === 404) {
return [];
} else {
throw err;
}
throw e;
})
: null;
});
}
return null;
},

setupController(controller, model) {
const has404 = this.has404;
controller.set('hasModel', true);
arnav28 marked this conversation as resolved.
Show resolved Hide resolved
controller.setProperties({
model: model,
has404,
});
if (!has404) {
controller.setProperties({
page: Number(model?.meta?.currentPage) || 1,
});
}
},
actions: {
error(error, transition) {
/* eslint-disable-next-line ember/no-controller-access-in-routes */
const hasModel = this.controllerFor(this.routeName).get('hasModel');
if (hasModel && error.httpStatus === 404) {
this.set('has404', true);
transition.abort();
} else {
return true;
}
},
willTransition(transition) {
window.scrollTo(0, 0);
if (!transition || transition.targetName !== this.routeName) {
this.store.clearAllDatasets();
}
return true;
},
reload() {
this.store.clearAllDatasets();
this.refresh();
},
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</ToolbarActions>
</Toolbar>

<ListView @items={{model}} @itemNoun="namespace" as |list|>
<ListView @items={{model}} @itemNoun="namespace" @paginationRouteName="vault.cluster.access.namespaces" as |list|>
{{#if list.empty}}
<list.empty>
<LinkTo @route="vault.cluster.access.namespaces.create">
Expand Down