Skip to content

Commit

Permalink
Add a pager to the dashboard package list
Browse files Browse the repository at this point in the history
Refs #959.

Implement a rudimentary cursor-based pager on the dashboard package list
with previous and next page links.
  • Loading branch information
djjuhasz committed Jun 26, 2024
1 parent a9947f7 commit 9ef2178
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 5 deletions.
40 changes: 37 additions & 3 deletions dashboard/src/pages/packages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,47 @@ const toggleLegend = () => {
>{{ pkg.name }}</router-link
>
</td>
<td><UUID :id="pkg.aipId" /></td>
<td>
<UUID :id="pkg.aipId" />
</td>
<td>{{ $filters.formatDateTime(pkg.startedAt) }}</td>
<td><UUID :id="pkg.locationId" /></td>
<td><StatusBadge :status="pkg.status" /></td>
<td>
<UUID :id="pkg.locationId" />
</td>
<td>
<StatusBadge :status="pkg.status" />
</td>
</tr>
</tbody>
</table>
</div>
<div>
<nav aria-label="Package list pages">
<ul class="pagination justify-content-center">
<li class="page-item">
<a
href="#"
:class="{
'page-link': true,
disabled: !packageStore.hasPrevPage,
}"
@click.prevent="packageStore.prevPage"
>Previous</a
>
</li>
<li class="page-item">
<a
href="#"
:class="{
'page-link': true,
disabled: !packageStore.hasNextPage,
}"
@click.prevent="packageStore.nextPage"
>Next</a
>
</li>
</ul>
</nav>
</div>
</div>
</template>
35 changes: 34 additions & 1 deletion dashboard/src/stores/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ export const usePackageStore = defineStore("package", {
// A list of packages shown during searches.
packages: [] as Array<api.EnduroStoredPackage>,

// Cursor for this page of packages.
cursor: 0,

// Cursor for next page of packages.
nextCursor: 0,

// A list of previous page cursors.
prevCursors: [] as Array<number>,

// User-interface interactions between components.
ui: {
download: new UIRequest(),
Expand All @@ -44,6 +53,12 @@ export const usePackageStore = defineStore("package", {
isRejected(): boolean {
return this.isDone && this.current?.locationId === undefined;
},
hasNextPage(): boolean {
return this.nextCursor != 0;
},
hasPrevPage(): boolean {
return this.prevCursors.length > 0;
},
getActionById: (state) => {
return (
actionId: number,
Expand Down Expand Up @@ -103,8 +118,11 @@ export const usePackageStore = defineStore("package", {
]);
},
async fetchPackages() {
const resp = await client.package.packageList();
const resp = await client.package.packageList({
cursor: this.cursor > 0 ? this.cursor.toString() : undefined,
});
this.packages = resp.items;
this.nextCursor = Number(resp.nextCursor);
},
async fetchPackagesDebounced() {
return this.fetchPackages();
Expand Down Expand Up @@ -156,6 +174,21 @@ export const usePackageStore = defineStore("package", {
this.current.status = api.EnduroStoredPackageStatusEnum.InProgress;
});
},
nextPage() {
if (this.nextCursor == 0) {
return;
}
this.prevCursors.push(this.cursor);
this.cursor = this.nextCursor;
this.fetchPackages();
},
prevPage() {
let prev = this.prevCursors.pop();
if (prev !== undefined) {
this.cursor = prev;
this.fetchPackages();
}
},
},
debounce: {
fetchPackagesDebounced: [500, { isImmediate: false }],
Expand Down
2 changes: 1 addition & 1 deletion dashboard/src/styles/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ Notes:
- `main.scss` is imported by `main.ts` - the global stylesheet for the app.
- `bootstrap-base.scss` is also made available to all components using
`<style lang=scss>` via `vite.config.ts`. It does not impact on the final
size of the stylesheets because `bootstra-base.scss` does not produce classes
size of the stylesheets because `bootstrap-base.scss` does not produce classes
only variables and mixins.
1 change: 1 addition & 0 deletions dashboard/src/styles/bootstrap.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
@import "bootstrap/scss/close";
@import "bootstrap/scss/tooltip";
@import "bootstrap/scss/offcanvas";
@import "bootstrap/scss/pagination";

// Utilities API last to generate classes based on the Sass map in `_utilities.scss`.
@import "bootstrap/scss/utilities/api";

0 comments on commit 9ef2178

Please sign in to comment.