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: refactor KMIP role model #28418

Merged
merged 12 commits into from
Sep 20, 2024
Merged

Conversation

hashishaw
Copy link
Contributor

@hashishaw hashishaw commented Sep 17, 2024

Description

This PR refactors the kmip/role model in preparation for our Ember Data upgrade. During testing, the computed values in the model were causing weirdness with the new path-help approach.

Our latest best practices include having the models as thin as possible, and calculating things like fieldGroups in the components where they are used instead of on the model itself. However, to keep the scope of this PR small I opted to keep some of the model getters for field groups, specifically for the role details page. In the future we may choose to remove these in favor of component getters.

Before / After
Role create form

Role details Role edit form
  • Ent tests pass

@hashishaw hashishaw added this to the 1.19.0-rc milestone Sep 17, 2024
@github-actions github-actions bot added the hashicorp-contributed-pr If the PR is HashiCorp (i.e. not-community) contributed label Sep 17, 2024
export default Model.extend(COMPUTEDS, {
backend: attr({ readOnly: true }),
scope: attr({ readOnly: true }),
name: attr({ readOnly: true }),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

name was set on the model, but role is the attribute that comes back from OpenAPI. Since there's no way to filter out attributes from OpenAPI, I opted to keep role instead of name

Copy link

github-actions bot commented Sep 17, 2024

CI Results:
All Go tests succeeded! ✅

@hashishaw hashishaw marked this pull request as ready for review September 17, 2024 19:50
@hashishaw hashishaw requested a review from a team as a code owner September 17, 2024 19:50
Copy link

Build Results:
All builds succeeded! ✅

}),
@withExpandedAttributes()
export default class KmipRoleModel extends Model {
@attr({ readOnly: true }) backend;
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need to specify the role attribute here?

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe that withExpandedAttributes will populate the model with the properties returned from OpenAPI and it sounds like role is coming from there.

Copy link
Contributor

@hellobontempo hellobontempo left a comment

Choose a reason for hiding this comment

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

Nice work! Just a couple of questions, nothing blocking! ⭐

<MessageError @model={{@model}} data-test-edit-form-error />
<div class="box is-sideless is-fullwidth is-marginless">
<NamespaceReminder @mode="save" />
{{#if (eq @mode "create")}}
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of passing @mode do we want to leverage @model.isNew, since that's been the newer pattern we've used?

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you explain your reasoning behind making this util file? Just wondering about when to use this pattern in the future. To me it feels like a one-off while we bridge the old model pattern and transition to the new "schema" models, and that typically this sort of thing would live in the form component. But I could be missing something and am curious about your perspective! 💭

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question! I have it in a util because it was used in the form as well as the adapter for ensuring that the correct fields get sent to the API. As we move toward thinner models it's worth considering what we want the pattern to be, and this file could definitely become obsolete (or part of a different file structure) in the future

Copy link
Contributor

Choose a reason for hiding this comment

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

Gotcha! Did we ever get around to writing the schema model readme file? I wonder if it's worth considering a model/helpers file or something. But would have to think about this more... It also seems like since Ember is moving away from adapters/serializers all together (in the looong term plan) so, I think you're right that the need for this may become obsolete all together 🤔 Just spitballin

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 didn't -- probably worth doing a follow-up PR with the doc and a folder pattern for things like this. We are probably a long way from eliminating our adapters and serializers so it's definitely worth establishing a pattern


operationFormFields: computed('operationFieldsWithoutSpecial', function () {
get operationFormFields() {
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like this has been renamed and moved to operationFormGroups below in the form component, do we still need this getter here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this is used in the KMIP OperationDetailsDisplay component for role details page.

Copy link
Contributor

Choose a reason for hiding this comment

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

Awesome! I had done a search and missed that, thanks for following up

@model={{this.model}}
@mode="edit"
Copy link
Contributor

Choose a reason for hiding this comment

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

Same question as above about passing @mode

@model={{this.model}}
@mode="create"
@onSave={{transition-to "vault.cluster.secrets.backend.kmip.scope.roles" this.scope}}
@cancelLinkParams={{array "scope.roles" this.scope}}
@onCancel={{transition-to "vault.cluster.secrets.backend.kmip.scope.roles" this.scope}}
Copy link
Contributor

Choose a reason for hiding this comment

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

👏

@@ -17,6 +17,10 @@ module.exports = EngineAddon.extend({
enabled: true,
},

babel: {
plugins: [require.resolve('ember-concurrency/async-arrow-task-transform')],
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this?!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

😂 required to use the async-arrow notation -- the other engines already had it but when I refactored the form in KMIP I got an error that it needed this transform

Copy link
Contributor

Choose a reason for hiding this comment

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

Aha! Thank you for explaining 😂

@hashishaw hashishaw enabled auto-merge (squash) September 20, 2024 18:36
@hashishaw hashishaw merged commit 520f141 into main Sep 20, 2024
31 checks passed
@hashishaw hashishaw deleted the ui/update-kmip-model-prep-ember-data-upgrade branch September 20, 2024 18:53
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.

4 participants