Vault Automation 06ddf792f2
[UI] VAULT-41962 Updated tools sidebar (#11919) (#11984)
* VAULT-41962 Updated tools sidebar

* Fix failing tests and add copyright header

* Update capitailization of nav item titles

* Update tools breadcrumbs

* Add comments

* Fix failing tests!

* Update ui/tests/acceptance/config-ui/messages/messages-test.js



* Update ui/lib/core/addon/components/sidebar/nav/tools.ts



* Add more nav tests for custom messages

* Update test name

---------

Co-authored-by: Kianna <30884335+kiannaquach@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-01-26 10:11:40 -08:00

63 lines
1.7 KiB
TypeScript

/**
* Copyright IBM Corp. 2016, 2025
* SPDX-License-Identifier: BUSL-1.1
*/
import Component from '@glimmer/component';
import { service } from '@ember/service';
import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking';
import type ApiService from 'vault/services/api';
import type FlashMessageService from 'vault/services/flash-messages';
import type { HTMLElementEvent } from 'vault/forms';
/**
* @module ToolsRandom
* ToolsRandom components are components that perform sys/wrapping/random functionality.
* @example
* <Tools::Random />
*/
export default class ToolsRandom extends Component {
@service declare readonly api: ApiService;
@service declare readonly flashMessages: FlashMessageService;
@tracked bytes = 32;
@tracked format = 'base64';
@tracked randomBytes = '';
@tracked errorMessage = '';
get breadcrumbs() {
return [{ label: 'Vault', route: 'vault.cluster.dashboard', icon: 'vault' }, { label: 'Random bytes' }];
}
@action
reset() {
this.bytes = 32;
this.format = 'base64';
this.randomBytes = '';
this.errorMessage = '';
}
@action
handleSelect(evt: HTMLElementEvent<HTMLSelectElement>) {
const { value } = evt.target;
this.format = value;
}
@action
async handleSubmit(evt: HTMLElementEvent<HTMLFormElement>) {
evt.preventDefault();
const data = { bytes: Number(this.bytes), format: this.format };
try {
const { random_bytes } = await this.api.sys.generateRandom(data);
this.randomBytes = random_bytes || '';
this.flashMessages.success('Generated random bytes successfully.');
} catch (error) {
const { message } = await this.api.parseError(error);
this.errorMessage = message;
}
}
}