-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UI: convert mount backend code to TS #27349
Changes from all commits
6db6959
02b5afb
4b7d403
62020aa
447eb0d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -12,6 +12,12 @@ import { waitFor } from '@ember/test-waiters'; | |||
import { methods } from 'vault/helpers/mountable-auth-methods'; | ||||
import { isAddonEngine, allEngines } from 'vault/helpers/mountable-secret-engines'; | ||||
|
||||
import type FlashMessageService from 'vault/services/flash-messages'; | ||||
import type Store from '@ember-data/store'; | ||||
|
||||
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. | ||||
|
@@ -24,9 +30,17 @@ import { isAddonEngine, allEngines } from 'vault/helpers/mountable-secret-engine | |||
* | ||||
*/ | ||||
|
||||
export default class MountBackendForm extends Component { | ||||
@service store; | ||||
@service flashMessages; | ||||
type MountModel = MountSecretBackendModel | AuthEnableModel; | ||||
|
||||
interface Args { | ||||
mountModel: MountModel; | ||||
mountType: 'secret' | 'auth'; | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. got these options from here:
|
||||
onMountSuccess: (type: string, path: string, useEngineRoute: boolean) => void; | ||||
} | ||||
|
||||
export default class MountBackendForm extends Component<Args> { | ||||
@service declare readonly store: Store; | ||||
@service declare readonly flashMessages: FlashMessageService; | ||||
|
||||
// validation related properties | ||||
@tracked modelValidations = null; | ||||
|
@@ -40,10 +54,10 @@ export default class MountBackendForm extends Component { | |||
if (noTeardown && this.args?.mountModel?.isNew) { | ||||
this.args.mountModel.unloadRecord(); | ||||
} | ||||
super.willDestroy(...arguments); | ||||
super.willDestroy(); | ||||
} | ||||
|
||||
checkPathChange(type) { | ||||
checkPathChange(type: string) { | ||||
if (!type) return; | ||||
const mount = this.args.mountModel; | ||||
const currentPath = mount.path; | ||||
|
@@ -58,8 +72,8 @@ export default class MountBackendForm extends Component { | |||
} | ||||
} | ||||
|
||||
typeChangeSideEffect(type) { | ||||
if (!this.args.mountType === 'secret') return; | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TS caught this, which seemed like a typo so i fixed it 😮 |
||||
typeChangeSideEffect(type: string) { | ||||
if (this.args.mountType !== 'secret') return; | ||||
if (type === 'pki') { | ||||
// If type PKI, set max lease to ~10years | ||||
this.args.mountModel.config.maxLeaseTtl = '3650d'; | ||||
|
@@ -69,7 +83,7 @@ export default class MountBackendForm extends Component { | |||
} | ||||
} | ||||
|
||||
checkModelValidity(model) { | ||||
checkModelValidity(model: MountModel) { | ||||
const { isValid, state, invalidFormMessage } = model.validate(); | ||||
this.modelValidations = state; | ||||
this.invalidFormAlert = invalidFormMessage; | ||||
|
@@ -113,7 +127,7 @@ export default class MountBackendForm extends Component { | |||
|
||||
@task | ||||
@waitFor | ||||
*mountBackend(event) { | ||||
*mountBackend(event: Event) { | ||||
event.preventDefault(); | ||||
const mountModel = this.args.mountModel; | ||||
const { type, path } = mountModel; | ||||
|
@@ -165,13 +179,13 @@ export default class MountBackendForm extends Component { | |||
} | ||||
|
||||
@action | ||||
onKeyUp(name, value) { | ||||
onKeyUp(name: string, value: string) { | ||||
this.args.mountModel[name] = value; | ||||
this.checkModelWarnings(); | ||||
} | ||||
|
||||
@action | ||||
setMountType(value) { | ||||
setMountType(value: string) { | ||||
this.args.mountModel.type = value; | ||||
this.typeChangeSideEffect(value); | ||||
this.checkPathChange(value); | ||||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -6,8 +6,13 @@ | |||
import Route from '@ember/routing/route'; | ||||
import { service } from '@ember/service'; | ||||
|
||||
import type { ModelFrom } from 'vault/vault/route'; | ||||
import type Store from '@ember-data/store'; | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i noticed we've been importing the
however importing the type from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's strange, because in the |
||||
|
||||
export type AuthEnableModel = ModelFrom<VaultClusterSettingsAuthEnableRoute>; | ||||
|
||||
export default class VaultClusterSettingsAuthEnableRoute extends Route { | ||||
@service store; | ||||
@service declare readonly store: Store; | ||||
|
||||
model() { | ||||
const authMethod = this.store.createRecord('auth-method'); | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like this component is only rendered on 2 routes:
in both instances, the component directly receives the result of the model hook as its argument for
@mountModel
. this is why i set up the types this way.initially, i thought about setting the type to be either
SecretEngineModel
orAuthMethodModel
. however, this setup provides more flexibility -- it allows for potential changes in the route model that may include properties not specifically part of the underlying Ember data models.