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: Ember upgrade: Handle deprecation router service from host #28603

Merged

Conversation

hellobontempo
Copy link
Contributor

@hellobontempo hellobontempo commented Oct 4, 2024

Description

Handles Use alias for inject router service from host application. This PR is based on initial work done by #28281, which I recommend comparing to the changes here.

In summary this PR:

  • replaces router engine dependencies with aliased app-router
  • call the alias @service('app-router') router within engines instead of @service router

Deviations from original PR:

The reason for this is based on the ember guides here:

Screenshot 2024-10-04 at 2 32 21 PM
  • I decided to handle the transition-to slightly differently than the original PR. I uninstalled ember-router-helpers and replaced it with a global transition-to helper that uses getOwner to dynamically determine which router to use.
  • Similarly, I refactored LinkedBlock (which is a core component used across engines and the main app) to lookup the appropriate router service via a getter, which felt more stable instead of attempting to inject a service that doesn't exist (which according to above, would throw an error)

TODO only if you're a HashiCorp employee

  • Backport Labels: If this PR is in the ENT repo and needs to be backported, backport
    to N, N-1, and N-2, using the backport/ent/x.x.x+ent labels. If this PR is in the CE repo, you should only backport to N, using the backport/x.x.x label, not the enterprise labels.
    • If this fixes a critical security vulnerability or severity 1 bug, it will also need to be backported to the current LTS versions of Vault. To ensure this, use all available enterprise labels.
  • ENT Breakage: If this PR either 1) removes a public function OR 2) changes the signature
    of a public function, even if that change is in a CE file, double check that
    applying the patch for this PR to the ENT repo and running tests doesn't
    break any tests. Sometimes ENT only tests rely on public functions in CE
    files.
  • Jira: If this change has an associated Jira, it's referenced either
    in the PR description, commit message, or branch name.
  • RFC: If this change has an associated RFC, please link it in the description.
  • ENT PR: If this change has an associated ENT PR, please link it in the
    description. Also, make sure the changelog is in this PR, not in your ENT PR.

@hellobontempo hellobontempo requested a review from a team as a code owner October 4, 2024 21:38
@hellobontempo hellobontempo added this to the 1.19.0-rc milestone Oct 4, 2024
@github-actions github-actions bot added the hashicorp-contributed-pr If the PR is HashiCorp (i.e. not-community) contributed label Oct 4, 2024
@hellobontempo hellobontempo changed the title UI/vault 31211/deprecation router service from host UI: Ember upgrade: Handle deprecation router service from host Oct 4, 2024
Copy link

github-actions bot commented Oct 4, 2024

Build Results:
All builds succeeded! ✅

Copy link

github-actions bot commented Oct 4, 2024

CI Results:
All Go tests succeeded! ✅

@@ -8,20 +8,27 @@ import Resolver from 'ember-resolver';
import loadInitializers from 'ember-load-initializers';
import config from 'vault/config/environment';

// TODO: DEPRECATION https://ember-engines.com/docs/deprecations#-use-alias-for-inject-router-service-from-host-application
Copy link
Contributor Author

Choose a reason for hiding this comment

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

now engines reference the alias app-router instead of router directly

@@ -23,7 +23,7 @@ import { isAfter } from 'date-fns';
*/

export default class MessagesList extends Component {
@service router;
@service('app-router') router;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is how you pass the service if the variable you assign it to (i.e. router) differs from the service name

<MyForm @onSave={{transition-to "vault.cluster.some.route.item" "item-id"}} />
<MyForm @onSave={{transition-to "vault.cluster.some.external.route" external=true}} />
*/
export default class TransitionTo extends Helper {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Open to other ideas here, this seemed like a nice and simple way to dynamically use the transition-to helper without knowing the router ahead of time. It also was nice to remove an dependency 🎉

For reference, Chelsea had made a specific engine-transition-to helper here. Which is what I used as a basis for building this component.

Also there are no instances now where we pass external=true but I've copied her test to validate this works as expected.

Copy link
Contributor

Choose a reason for hiding this comment

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

I like this approach a lot. Nice work!

@@ -136,7 +136,6 @@
"ember-qunit": "^8.0.1",
"ember-resolver": "^11.0.1",
"ember-responsive": "5.0.0",
"ember-router-helpers": "^0.4.0",
Copy link
Contributor Author

@hellobontempo hellobontempo Oct 7, 2024

Choose a reason for hiding this comment

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

replaced with (new) global transition-to helper

@@ -4,7 +4,7 @@
*/

import Component from '@glimmer/component';
import { service } from '@ember/service';
import { getOwner } from '@ember/owner';
Copy link
Contributor

Choose a reason for hiding this comment

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

👍🏻

@@ -11,7 +11,6 @@ import { task } from 'ember-concurrency';

export default Mixin.create({
store: service(),
router: service(),
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder why we had this service in here to begin with🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I was going to move the service to the components that used the ReplicationActions mixin but then realized this wasn't used anywhere in the mixin or where the mixin was used?? My guess is left behind during a refactor?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But would definitely appreciate a second set of eyes double checking!

Copy link
Contributor

@Monkeychip Monkeychip left a comment

Choose a reason for hiding this comment

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

I was able to smoke test replication and other transitions. Nice work!

@hellobontempo
Copy link
Contributor Author

✅ enterprise tests
Screenshot 2024-10-08 at 9 01 11 AM

@hellobontempo hellobontempo merged commit 7774261 into main Oct 8, 2024
31 checks passed
@hellobontempo hellobontempo deleted the ui/VAULT-31211/deprecation-router-service-from-host branch October 8, 2024 16:01
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