vault/ui/lib/sync/addon/components/secrets/destination-header.ts
claire bontempo 2cabfe0143
Secrets Sync UI: Add purge delete progress and error banner to destination header (#24761)
* add deletion in progress banner

* update kv details banner to inline alert

* add logic for purge error

* add params to mirage

* comment in purge_initiated_at for mirage

* update flash message for deleting

* add test for banner

* transition to destination associations after delete

* redirect to details after delete instead of list

* remove attrs from serializer

* update mirage handler to mock purge_initiated_at
2024-01-10 21:07:10 -07:00

43 lines
1.4 KiB
TypeScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import Component from '@glimmer/component';
import { action } from '@ember/object';
import { inject as service } from '@ember/service';
import errorMessage from 'vault/utils/error-message';
import type SyncDestinationModel from 'vault/models/sync/destination';
import type RouterService from '@ember/routing/router-service';
import type StoreService from 'vault/services/store';
import type FlashMessageService from 'vault/services/flash-messages';
interface Args {
destination: SyncDestinationModel;
}
export default class DestinationsTabsToolbar extends Component<Args> {
@service declare readonly router: RouterService;
@service declare readonly store: StoreService;
@service declare readonly flashMessages: FlashMessageService;
@action
async deleteDestination() {
try {
const { destination } = this.args;
const message = `Destination ${destination.name} has been queued for deletion.`;
await destination.destroyRecord();
this.store.clearDataset('sync/destination');
this.router.transitionTo(
'vault.cluster.sync.secrets.destinations.destination.secrets',
destination.type,
destination.name
);
this.flashMessages.success(message);
} catch (error) {
this.flashMessages.danger(`Error deleting destination \n ${errorMessage(error)}`);
}
}
}