Repository: hashicorp/vault
File: ui/app/components/mount-backend-form.ts (TypeScript)

Code before:
/**
 * 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 { action } from '@ember/object';
import { task } from 'ember-concurrency';
import { waitFor } from '@ember/test-waiters';
import { isAddonEngine } from 'vault/helpers/mountable-secret-engines';
import { filterEnginesByMountType } from 'vault/utils/all-engines-metadata';

import type FlashMessageService from 'vault/services/flash-messages';
import type Store from '@ember-data/store';
import type AdapterError from '@ember-data/adapter/error';
import { debug } from '@ember/debug';

import type { AuthEnableModel } from 'vault/routes/vault/cluster/settings/auth/enable';
import type { MountSecretBackendModel } from 'vault/routes/vault/cluster/settings/mount-secret-backend';

/**
 * @module MountBackendForm
 * The `MountBackendForm` is used to mount either a secret or auth backend.
 *
 * @example ```js
 *   <MountBackendForm @mountType="secret" @onMountSuccess={{this.onMountSuccess}} />```
 *
 * @param {function} onMountSuccess - A function that transitions once the Mount has been successfully posted.
 * @param {string} mountType=auth - The type of engine to mount, either 'secret' or 'auth'.
 *
 */

type MountModel = MountSecretBackendModel | AuthEnableModel;

interface Args {
  mountModel: MountModel;
  mountType: 'secret' | 'auth';
  onMountSuccess: (type: string, path: string, useEngineRoute: boolean) => void;
}

export default class MountBackendForm extends Component<Args> {

Review comment (refactor):
Can we move this import under filterEnginesByMountType? This chunk of imports is specifically for importing types.

Code after:
/**
 * 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 { action } from '@ember/object';
import { task } from 'ember-concurrency';
import { waitFor } from '@ember/test-waiters';
import { isAddonEngine } from 'vault/helpers/mountable-secret-engines';
import { presence } from 'vault/utils/forms/validators';
import { filterEnginesByMountCategory } from 'vault/utils/all-engines-metadata';
import { assert } from '@ember/debug';

import type FlashMessageService from 'vault/services/flash-messages';
import type Store from '@ember-data/store';
import type AdapterError from '@ember-data/adapter/error';

import type { AuthEnableModel } from 'vault/routes/vault/cluster/settings/auth/enable';
import type { MountSecretBackendModel } from 'vault/routes/vault/cluster/settings/mount-secret-backend';

/**
 * @module MountBackendForm
 * The `MountBackendForm` is used to mount either a secret or auth backend.
 *
 * @example ```js
 *   <MountBackendForm @mountCategory="secret" @onMountSuccess={{this.onMountSuccess}} />```
 *
 * @param {function} onMountSuccess - A function that transitions once the Mount has been successfully posted.
 * @param {string} mountCategory=auth - The type of engine to mount, either 'secret' or 'auth'.
 *
 */

type MountModel = MountSecretBackendModel | AuthEnableModel;

interface Args {
  mountModel: MountModel;
  mountCategory: 'secret' | 'auth';
  onMountSuccess: (type: string, path: string, useEngineRoute: boolean) => void;
}