-
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: Ember deprecation - addObject, removeObject #25952
Conversation
…forcement-form (see #16470)
- only used one place (auth-form) so simplified that usage - glimmerize and refactor so that the tests work
@@ -144,7 +144,7 @@ export default ApplicationAdapter.extend({ | |||
async _updateAllowedRoles(store, { role, backend, db, type = 'add' }) { | |||
const connection = await store.queryRecord('database/connection', { backend, id: db }); | |||
const roles = [...(connection.allowed_roles || [])]; | |||
const allowedRoles = type === 'add' ? addToArray([roles, role]) : removeFromArray([roles, role]); | |||
const allowedRoles = type === 'add' ? addToArray(roles, role) : removeFromArray(roles, role); |
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.
I simplified the interface for the exported methods so that we don't need to wrap the params in an array
CI Results: |
return this.events.some((e) => e.violatedDirective.startsWith('connect-src')); | ||
}), | ||
export default class CspEventService extends Service { | ||
@tracked connectionViolations = []; |
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.
Full list of events didn't seem to be used anywhere, and the alias for the getter wasn't updating on the auth-form correctly so I refactored this service to track connectionViolations
directly
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.
This util was only used in one component, so I moved the logic back. See #16470
@@ -32,7 +32,6 @@ export default class RolesPageComponent extends Component { | |||
try { | |||
const message = `Successfully deleted role ${model.name}`; | |||
await model.destroyRecord(); | |||
this.args.roles.removeObject(model); |
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.
Destroying record automatically removes it from the store, so no need to update this.args.roles
list directly
Build Results: |
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.
Nice work tackling this! Mostly just comments and cleanup questions 🏅
export function addToArray([array, string]) { | ||
export function addManyToArray(array, otherArray) { | ||
assert(`Both values must be an array`, Array.isArray(array) && Array.isArray(otherArray)); | ||
const newArray = [...array].concat(otherArray); |
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.
out of curiosity - is there a reason you used concat()
here instead of spreading otherArray
?
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.
If there was, I don't remember it 😂
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.
TIL: concat
will add otherArray
as a single item if it isn't an array, which is nice. https://stackoverflow.com/questions/48865710/spread-operator-vs-array-concat
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.
Oh neat! 💡
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.
I wonder if these helpers should live in the addon
engine, it seems like something we may want access to in the wider app? It also seems like this should be a util as I don't see it used in any templates, which would simplify the extra logic needed to build the helper, but that may be too much scope creep for this PR to relocate. 😶🌫️
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.
That's a good idea for a follow-on! I think it will be easier to track the changes outside of this PR
@@ -195,6 +195,7 @@ export default class SecretCreateOrUpdate extends Component { | |||
if (isBlank(item.name)) { | |||
return; | |||
} | |||
// secretData is a KVObject/ArrayProxy so removeObject is fine here |
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.
thank you for the comment!
} else { | ||
updatedValue = removeFromArray(updatedValue, event.target.value); | ||
} | ||
this.args.model[this.valuePath] = updatedValue; |
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.
I think this.setAndBroadcast
handles setting the model, so I don't think line 204 is necessary?
@action
setAndBroadcast(value) {
this.args.model.set(this.valuePath, value);
this.onChange(this.valuePath, value);
}
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.
I'm matching what the previous line 198 does (either valueArray.addObject(value)
or valueArray.removeObject(value)
. It might be unnecessary but I'm hesitant to change such a far-reaching behavior here
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.
🤔 Ah, to me it looks like lines 200 and 202 are adding or removing the object. I don't think 198 valueArray[method](event.target.value);
updated the original model value, that appeared left to line 199, which is why the refactor appeared to duplicate that process.
This PR manages the following deprecation, which is a subset of
ember-data:deprecate-array-like
:This deprecation caused quite a bit of refactoring, because the deprecated methods would immediately notify Ember lifecycle of the change, but
Array.push
andArray.splice
do not. Additionally,removeObject
andaddObject
etc automatically handled making sure duplicate entries weren't added.With the new changes, we now need to set the tracked value to the new value with items removed or added. I used a helper we already had to help simplify the changes. There are also a few straggling instances of
addObject
andremoveObject
if you search the codebase, but those are actually happening on items of typeArrayProxy
so they are still valid. I tried to add comments everywhere that happens.