Files
threshold-ui/ui/desktop/app/controllers/scopes/scope/projects/targets/target.js
T
Cameron Perera e3433ec1f7 feat: 🎸 add pagination to host source table (#2854)
* feat: 🎸 add pagination to host source table

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-17093

* test: 💍 add e2e tests for host source pagination

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-17093

* refactor: 💡 change paginatedHosts to getter

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-17093

* test: 💍 refactor e2e pagination test

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-17093
2025-05-29 15:55:05 -05:00

74 lines
1.7 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import Controller, { inject as controller } from '@ember/controller';
import { service } from '@ember/service';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';
export default class ScopesScopeProjectsTargetsTargetController extends Controller {
@controller('scopes/scope/projects/targets/index') targets;
// =services
@service store;
@service confirm;
// =attributes
queryParams = [{ isConnecting: { type: 'boolean' } }];
@tracked page = 1;
@tracked pageSize = 10;
@tracked totalItems = this.model.hosts.length;
@tracked isConnecting = false;
isConnectionError = false;
// =methods
get paginatedHosts() {
return this.model.hosts.slice(
(this.page - 1) * this.pageSize,
this.page * this.pageSize,
);
}
/**
* Connect method that calls parent connect method and handles
* connection errors unique to this route
* @param {TargetModel} target
* @param {HostModel} host
*/
@action
async connect(target, host) {
try {
await this.targets.connect(target, host);
} catch (error) {
this.isConnectionError = true;
this.confirm
.confirm(error.message, { isConnectError: true })
// Retry
.then(() => this.connect(target, host))
.catch(() => {
// Reset the flag as this was user initiated and we're not
// in a transition
this.isConnectionError = false;
});
}
}
@action
async handlePageChange(page) {
this.page = page;
}
@action
async handlePageSizeChange(pageSize) {
this.page = 1;
this.pageSize = pageSize;
}
}