vault/ui/lib/pki/addon/components/page/pki-issuer-edit.ts
claire bontempo e97371680c
Re-add custom flash service so engines can extend cluster's template (#19963)
* Revert "UI: Remove custom service (#19925)"

This reverts commit b04751d22437b06947a84148c499c4728602b5e1.

* replace stickyInfo with options info

* revert replacing custom stickyInfo

* change flash message name to be consistent throughout application

* make service imports consistent for k8 engine

* replace stickyInfo with options info

* Revert "change flash message name to be consistent throughout application"

This reverts commit 17de49894de3976ed708fcf15f19f6f1eb1012a5.

* add comment

---------

Co-authored-by: Chelsea Shaw <cshaw@hashicorp.com>
2023-04-03 13:13:59 -06:00

63 lines
1.7 KiB
TypeScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import { task } from 'ember-concurrency';
import { waitFor } from '@ember/test-waiters';
import errorMessage from 'vault/utils/error-message';
import RouterService from '@ember/routing/router-service';
import FlashMessageService from 'vault/services/flash-messages';
import PkiIssuerModel from 'vault/models/pki/issuer';
interface Args {
model: PkiIssuerModel;
}
export default class PkiIssuerEditComponent extends Component<Args> {
@service declare readonly router: RouterService;
@service declare readonly flashMessages: FlashMessageService;
@tracked usageValues: Array<string> = [];
@tracked error = null;
constructor(owner: unknown, args: Args) {
super(owner, args);
this.usageValues = (this.args.model.usage || '').split(',');
}
toDetails() {
this.router.transitionTo('vault.cluster.secrets.backend.pki.issuers.issuer.details');
}
@action
setUsage(value: string) {
const method = this.usageValues.includes(value) ? 'removeObject' : 'addObject';
this.usageValues[method](value);
this.args.model.usage = this.usageValues.join(',');
}
@task
@waitFor
*save(event: Event) {
event.preventDefault();
try {
yield this.args.model.save();
this.flashMessages.success('Successfully updated issuer');
this.toDetails();
} catch (error) {
this.error = errorMessage(error);
}
}
@action
cancel() {
this.args.model.rollbackAttributes();
this.toDetails();
}
}