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: Fix id fields not allowing update #19117

Merged
merged 19 commits into from
Feb 10, 2023
Merged

Conversation

hashishaw
Copy link
Collaborator

@hashishaw hashishaw commented Feb 10, 2023

After the Ember Upgrade from 3.x to 4.x it was discovered that Ember now disallows setting the ID on a model, rather than logging a warning as it did previously.

This showed up as a form seeming to not let you type after the first letter:
before - bug

This PR removes fieldValue: 'id' from all models that do not use OpenAPI, and overrides to match the attribute name on those that do (so that even if it comes back from OpenAPI we do not have this issue). It also ensures that models which do not have an explicit id set one manually on the adapter response.
after - fixed

✅ I ran the enterprise tests locally and they are passing

@@ -2,7 +2,7 @@ import ApplicationSerializer from './application';

export default ApplicationSerializer.extend({
normalizeResponse(store, primaryModelClass, payload, id, requestType) {
if (payload.data.masking_character) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Before this change, attempting to save a new template (or any of the other items) would throw this mysterious error in the console:

Uncaught (in promise) TypeError: e is undefined
    persist transform-edit-base.js:87
    invokeCallback rsvp.js:495
    publish rsvp.js:478
    publishRejection rsvp.js:414
    <anonymous> Ember

Copy link
Contributor

Choose a reason for hiding this comment

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

That looks like a fun error to track down 😬

@@ -58,7 +58,11 @@
<MessageError @model={{this.model}} />
<NamespaceReminder @mode={{this.mode}} @noun="Transform role" />
{{#each this.model.attrs as |attr|}}
<FormField data-test-field @attr={{attr}} @model={{this.model}} />
{{#if attr.options.readOnly}}
<ReadonlyFormField @attr={{attr}} @value={{get this.model attr.name}} />
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Caught this in testing -- we were allowing users to update the name field on edit

@@ -81,7 +81,8 @@ export default Component.extend(FocusOnInsertMixin, {
createOrUpdate(type, event) {
event.preventDefault();

const modelId = this.model.id;
// all of the attributes with fieldValue:'id' are called `name`
const modelId = this.model.id || this.model.name;
Copy link
Contributor

Choose a reason for hiding this comment

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

is there a reason to keep this.model.id here? In case somehow the id differs from name on edit?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ID does exist if we're editing, so I figured we'd keep it as the authoritative source of truth if it exists

export default ApplicationSerializer.extend({
primaryKey: 'name',
Copy link
Contributor

Choose a reason for hiding this comment

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

👏

@@ -1,6 +1,9 @@
import ApplicationSerializer from './application';

export default ApplicationSerializer.extend({
primaryKey: 'name',

// Used for both pki-role (soon to be deprecated) and role-ssh
Copy link
Contributor

Choose a reason for hiding this comment

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

thank you for this comment!

extractLazyPaginatedData(payload) {
return payload.data.keys.map((key) => {
const model = {
id: key,
name: key,
Copy link
Contributor

Choose a reason for hiding this comment

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

I noticed we kept id: key here when adding name - is that something we should also do in ui/app/serializers/role.js on line 17?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's a good question, I went back and forth between keeping both and replacing it. I reasoned to add to this one because extractLazyPaginatedData seems to be vault-specific, so there's no guarantee that we're using it in a conventional way which would take advantage of primaryKey (which I believe is extracted via extractId)
I also figured by removing it from the other serializers where we use primaryKey there may be fewer places we need to track down in case we need to update the ID in the future. But, I'm happy to add back id to the others if the team thinks it makes the most sense!

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for explaining your reasoning! I think this makes sense, and ideally decreases the difficulty in tracking down future ember data issues

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.

really great job tackling this so quickly! MVP🥇

Copy link
Contributor

@zofskeez zofskeez left a comment

Choose a reason for hiding this comment

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

Thanks for tackling this! 🚀

@@ -1,17 +1,22 @@
import { assign } from '@ember/polyfills';
Copy link
Contributor

Choose a reason for hiding this comment

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

🎉

Comment on lines +65 to +68
assert(
'Form is attempting to modify an ID. Ember-data does not allow this.',
valuePath.toLowerCase() !== 'id'
);
Copy link
Contributor

Choose a reason for hiding this comment

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

🎉

@hashishaw hashishaw merged commit 8901e50 into main Feb 10, 2023
@hashishaw hashishaw deleted the ui/fix-fieldvalue-id-after-upgrade branch February 10, 2023 19:32
jayant07-yb pushed a commit to jayant07-yb/hashicorp-vault-integrations that referenced this pull request Mar 15, 2023
@cinthiaconti cinthiaconti modified the milestones: 1.13.0-rc1, 1.14 May 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants