feat: add pagination to evaluations.index

This commit is contained in:
Jai Bhagat
2021-12-21 13:31:28 -05:00
parent 79d1c11e24
commit 2b4a9f7512
3 changed files with 52 additions and 2 deletions

View File

@@ -3,12 +3,41 @@ import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking';
export default class EvaluationsController extends Controller {
queryParams = ['pageSize'];
queryParams = ['nextToken', 'pageSize'];
get shouldDisableNext() {
return !this.model.meta?.nextToken;
}
get shouldDisablePrev() {
return !this.previousTokens.length;
}
@tracked pageSize = 25;
@tracked nextToken = null;
@tracked previousTokens = [];
@action
onChange(newPageSize) {
this.pageSize = newPageSize;
}
@action
onNext(nextToken) {
this.previousTokens = [...this.previousTokens, this.nextToken];
this.nextToken = nextToken;
}
@action
onPrev(lastToken) {
this.previousTokens.pop();
this.previousTokens = [...this.previousTokens];
this.nextToken = lastToken;
}
@action
refresh() {
this.nextToken = null;
this.previousTokens = [];
}
}

View File

@@ -10,12 +10,16 @@ export default class EvaluationsIndexRoute extends Route {
pageSize: {
refreshModel: true,
},
nextToken: {
refreshModel: true,
},
};
model({ pageSize }) {
model({ pageSize, nextToken }) {
return this.store.query('evaluation', {
namespace: ALL_NAMESPACE_WILDCARD,
per_page: pageSize,
next_token: nextToken,
});
}
}

View File

@@ -58,5 +58,22 @@
</ListTable>
<div class="table-foot">
<PageSizeSelect @onChange={{this.onChange}} />
<button type="button" {{on "click" this.refresh}}>
Refresh
</button>
<button
type="button"
disabled={{this.shouldDisablePrev}}
{{on "click" (fn this.onPrev this.lastToken)}}
>
Prev
</button>
<button
type="button"
disabled={{this.shouldDisableNext}}
{{on "click" (fn this.onNext @model.meta.nextToken)}}
>
Next >
</button>
</div>
</section>