Noelle Daley c5a0040886
[Secrets Sync] split activation modal into separate component (#26822)
* add new SyncActivationModal component

* secrets overview: use SyncActivationModal

* tests: add SyncActivationModal tests

* int/sync/secrets/overview-test: remove redundant tests now handled by modal tests

* cleanup: reorganize sync selectors

* chore: will i ever remember copyright headers? nah
2024-05-21 18:50:19 -07:00

69 lines
2.3 KiB
TypeScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { service } from '@ember/service';
import { task } from 'ember-concurrency';
import { action } from '@ember/object';
import Ember from 'ember';
import type FlashMessageService from 'vault/services/flash-messages';
import type StoreService from 'vault/services/store';
import type VersionService from 'vault/services/version';
import type FlagsService from 'vault/services/flags';
import type { SyncDestinationAssociationMetrics } from 'vault/vault/adapters/sync/association';
import type SyncDestinationModel from 'vault/vault/models/sync/destination';
interface Args {
destinations: Array<SyncDestinationModel>;
totalVaultSecrets: number;
isActivated: boolean;
licenseHasSecretsSync: boolean;
isHvdManaged: boolean;
}
export default class SyncSecretsDestinationsPageComponent extends Component<Args> {
@service declare readonly flashMessages: FlashMessageService;
@service declare readonly store: StoreService;
@service declare readonly version: VersionService;
@service declare readonly flags: FlagsService;
@tracked destinationMetrics: SyncDestinationAssociationMetrics[] = [];
@tracked page = 1;
@tracked showActivateSecretsSyncModal = false;
@tracked activationError: null | string = null;
// eventually remove when we deal with permissions on activation-features
@tracked hideOptIn = false;
@tracked hideError = false;
pageSize = Ember.testing ? 3 : 5; // lower in tests to test pagination without seeding more data
constructor(owner: unknown, args: Args) {
super(owner, args);
if (this.args.destinations.length) {
this.fetchAssociationsForDestinations.perform();
}
}
fetchAssociationsForDestinations = task(this, {}, async (page = 1) => {
try {
const total = page * this.pageSize;
const paginatedDestinations = this.args.destinations.slice(total - this.pageSize, total);
this.destinationMetrics = await this.store
.adapterFor('sync/association')
.fetchByDestinations(paginatedDestinations);
this.page = page;
} catch (error) {
this.destinationMetrics = [];
}
});
@action
onModalError(errorMsg: string) {
this.activationError = errorMsg;
}
}