Skip to content
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

Merged
merged 5 commits into from
Jun 4, 2024
Merged

Conversation

andaley
Copy link
Contributor

@andaley andaley commented Jun 4, 2024

🛠️ Description

Migrating a few files to TS, as having types will help us build the WIF UI.

  • ent tests pass locally

@github-actions github-actions bot added the hashicorp-contributed-pr If the PR is HashiCorp (i.e. not-community) contributed label Jun 4, 2024
@andaley andaley added this to the 1.17.1 milestone Jun 4, 2024
@andaley andaley marked this pull request as ready for review June 4, 2024 17:29
@andaley andaley requested a review from a team as a code owner June 4, 2024 17:29

interface Args {
mountModel: MountModel;
mountType: 'secret' | 'auth';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got these options from here:

* @param {string} [mountType=auth] - mount type can be `auth` or `secret`

export default class MountBackendForm extends Component {
@service store;
@service flashMessages;
type MountModel = MountSecretBackendModel | AuthEnableModel;
Copy link
Contributor Author

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:

Screenshot 2024-06-03 at 6 25 34 PM

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 or AuthMethodModel. 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.

@@ -58,8 +72,8 @@ export default class MountBackendForm extends Component {
}
}

typeChangeSideEffect(type) {
if (!this.args.mountType === 'secret') return;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TS caught this, which seemed like a typo so i fixed it 😮

@@ -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';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i noticed we've been importing the Store type 2 different ways. one is this way, and the other is like this:

import type StoreService from 'vault/services/store';

however importing the type from @ember-data works better since it recognizes that properties like isDestroying etc are indeed on that type. the alternative way of importing Store caused a bunch of type errors.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's strange, because in the store.d.ts file we're extending Store from @ember-data/store 🤔 Should be harmless here since we're not using any of the extended methods here, but smells like something wrong in our ts setup

Copy link

github-actions bot commented Jun 4, 2024

Build Results:
All builds succeeded! ✅

Copy link

github-actions bot commented Jun 4, 2024

CI Results:
All Go tests succeeded! ✅

Copy link
Contributor

@hashishaw hashishaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✨ love these kinds of PRs! Thanks for doing this 🧹

@andaley andaley enabled auto-merge (squash) June 4, 2024 21:31
@andaley andaley merged commit 87f693c into main Jun 4, 2024
31 checks passed
@andaley andaley deleted the ui/ts-mount-backend-related-code branch June 4, 2024 21:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hashicorp-contributed-pr If the PR is HashiCorp (i.e. not-community) contributed pr/no-changelog ui
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants