Fix focal point not saving when asset blueprint has no fields #6814
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #2954.
The issue was that focal point setter assumes that
values
will be an object.https://github.com/ncla/cms/blob/b28df0896d614383cd0a561359d9d885cb7c00e8/resources/js/components/assets/Editor/Editor.vue#L330-L334
As far as I understood, Vue's special $set is used to trigger reactivity in a component. When the blueprint has no fields, an array is set from the HTTP response. When blueprint has fields, the response value gives us an object.
https://github.com/ncla/cms/blob/b28df0896d614383cd0a561359d9d885cb7c00e8/resources/js/components/assets/Editor/Editor.vue#L295-L298
However because
values
is an array now,this.$set(this.values, 'focus', point);
will not work because it assumes the property in an object. If you set 2nd argument to a number then it will be used as an array index and a value will be set.See Vue 2 docs here: https://v2.vuejs.org/v2/guide/reactivity.html#For-Objects
As a fix, I simply check if
values
in the HTTP response is empty to prevent changing thevalues
type from object to array.Side note: I initially thought that this was bug introduced with hidden fields changes but that came much later than the bug report.