vault/ui/lib/sync/addon/components/secrets/sync-activation-modal.ts
Jordan Reimer ed67e9e59e
[UI] Ember Data Migration - Sync Cleanup (#30634)
* removes namespace param from activation flags endpoint in api client

* updates sync activation modal to use api service

* updates sync destination sync page to use api service

* removes ember data type deps from sync engine and updates tests

* updates sync activation modal to always override namespace header in activate request
2025-05-15 11:15:18 -06:00

53 lines
1.9 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 { waitFor } from '@ember/test-waiters';
import type FlagsService from 'vault/services/flags';
import type FlashMessageService from 'vault/services/flash-messages';
import type RouterService from '@ember/routing/router-service';
import type ApiService from 'vault/services/api';
interface Args {
onClose: () => void;
onError: (errorMessage: string) => void;
onConfirm: () => void;
}
export default class SyncActivationModal extends Component<Args> {
@service declare readonly flags: FlagsService;
@service declare readonly flashMessages: FlashMessageService;
@service('app-router') declare readonly router: RouterService;
@service declare readonly api: ApiService;
@tracked hasConfirmedDocs = false;
@task
@waitFor
*onFeatureConfirm() {
// clear any previous errors in the parent component
this.args.onConfirm();
// sync activation is managed by the root/administrative namespace so child namespaces are not sent.
// for non-managed clusters the root namespace path is technically an empty string, otherwise we pass 'admin' if HVD managed.
const namespace = this.flags.hvdManagedNamespaceRoot || '';
try {
yield this.api.sys.activationFlagsActivate_2(this.api.buildHeaders({ namespace }));
// must refresh and not transition because transition does not refresh the model from within a namespace
yield this.router.refresh('vault.cluster');
} catch (error) {
const { message } = yield this.api.parseError(error);
this.args.onError(message);
this.flashMessages.danger(`Error enabling feature \n ${message}`);
} finally {
this.args.onClose();
}
}
}