-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Changes from all commits
d05f2ff
c642301
795be3f
7e29bc5
acdbf07
d862eb0
5c594d9
24aa2bd
94e725a
3df2f28
a0911fa
63ff1d7
d4fde7c
25ba93d
c9df033
546a5cd
ced3f6e
88eba9f
4ee89b3
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 |
---|---|---|
|
@@ -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; | ||
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. is there a reason to keep 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. ID does exist if we're editing, so I figured we'd keep it as the authoritative source of truth if it exists |
||
// prevent from submitting if there's no key | ||
// maybe do something fancier later | ||
if (type === 'create' && isBlank(modelId)) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
import ApplicationSerializer from './application'; | ||
|
||
export default ApplicationSerializer.extend({ | ||
primaryKey: 'name', | ||
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. 👏 |
||
|
||
extractLazyPaginatedData(payload) { | ||
return payload.data.keys.map((key) => { | ||
const model = { | ||
id: key, | ||
name: key, | ||
}; | ||
if (payload.backend) { | ||
model.backend = payload.backend; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
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. thank you for this comment! |
||
extractLazyPaginatedData(payload) { | ||
if (payload.zero_address_roles) { | ||
payload.zero_address_roles.forEach((role) => { | ||
|
@@ -11,7 +14,7 @@ export default ApplicationSerializer.extend({ | |
if (!payload.data.key_info) { | ||
return payload.data.keys.map((key) => { | ||
const model = { | ||
id: key, | ||
name: key, | ||
}; | ||
if (payload.backend) { | ||
model.backend = payload.backend; | ||
|
@@ -22,7 +25,7 @@ export default ApplicationSerializer.extend({ | |
|
||
const ret = payload.data.keys.map((key) => { | ||
const model = { | ||
id: key, | ||
name: key, | ||
key_type: payload.data.key_info[key].key_type, | ||
zero_address: payload.data.key_info[key].zero_address, | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ import ApplicationSerializer from './application'; | |
|
||
export default ApplicationSerializer.extend({ | ||
normalizeResponse(store, primaryModelClass, payload, id, requestType) { | ||
if (payload.data.masking_character) { | ||
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. Before this change, attempting to save a new template (or any of the other items) would throw this mysterious error in the console:
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 looks like a fun error to track down 😬 |
||
if (payload.data?.masking_character) { | ||
payload.data.masking_character = String.fromCharCode(payload.data.masking_character); | ||
} | ||
return this._super(store, primaryModelClass, payload, id, requestType); | ||
|
@@ -21,6 +21,7 @@ export default ApplicationSerializer.extend({ | |
return payload.data.keys.map((key) => { | ||
const model = { | ||
id: key, | ||
name: key, | ||
}; | ||
if (payload.backend) { | ||
model.backend = payload.backend; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
import ApplicationSerializer from '../application'; | ||
|
||
export default ApplicationSerializer.extend({ | ||
primaryKey: 'name', | ||
extractLazyPaginatedData(payload) { | ||
return payload.data.keys.map((key) => { | ||
const model = { | ||
id: key, | ||
name: key, | ||
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 kept 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 a good question, I went back and forth between keeping both and replacing it. I reasoned to add to this one because 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. Thanks for explaining your reasoning! I think this makes sense, and ideally decreases the difficulty in tracking down future ember data issues |
||
}; | ||
if (payload.backend) { | ||
model.backend = payload.backend; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import { action } from '@ember/object'; | |
import { capitalize } from 'vault/helpers/capitalize'; | ||
import { humanize } from 'vault/helpers/humanize'; | ||
import { dasherize } from 'vault/helpers/dasherize'; | ||
import { assert } from '@ember/debug'; | ||
/** | ||
* @module FormField | ||
* `FormField` components are field elements associated with a particular model. | ||
|
@@ -61,6 +62,10 @@ export default class FormFieldComponent extends Component { | |
super(...arguments); | ||
const { attr, model } = this.args; | ||
const valuePath = attr.options?.fieldValue || attr.name; | ||
assert( | ||
'Form is attempting to modify an ID. Ember-data does not allow this.', | ||
valuePath.toLowerCase() !== 'id' | ||
); | ||
Comment on lines
+65
to
+68
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. 🎉 |
||
const modelValue = model[valuePath]; | ||
this.showInput = !!modelValue; | ||
} | ||
|
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.
🎉