-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
adds simple logic that keeps authored captions in galleries #15004
Conversation
This is not the best fix yet, but it is a quick fix. @noisysocks you had been bitten by the disappearing captions, do you think this approach could work, and later move to calling the REST media api and update the caption for each attachment based on the GTB gallery 's rich text 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.
This makes sense to me. I don't think we need to bother with adding a new REST request. Are there any fields other fields other than caption
that we should source from the existing selected images?
This definitely works better, in that there are no lost captions. That's a massive win on its own. 🙌 There's still a couple weird experiences that occur under the following conditions:
It'd be great if we could offer logic to see if the caption has been changed since the Media modal was opened, and then update the caption in Gutenberg to match. Not sure if that's possible though. And also:
If you modify (not delete) the caption in Gutenberg, the caption will not be overwritten by the one in the media modal. When comparing to that, the behavior in step 5 is inconsistent. I'd expect the editor to know that if I've manually deleted a caption, it's intentionally gone and should not be replaced so easily. In general though, I'm super-glad that this means no more lost captions, so it's a definite improvement. 👍 |
I've updated the code to @noisysocks 's review and also @kjellr I have added the following behaviour:
Feels a lot better now, let me know if you can take it for another spin :) |
16efe35
to
c2e280f
Compare
55f67f1
to
66c5bb3
Compare
@gziolo @talldan can you please shine some light here as I can't seem to be able to figure out what is wrong with this failing test:
The only thing that causes it to fail appears to be the new item in block.js (attachmentCaption). All the other code passes all tests (I tested by applying each change incrementally). As soon as I add
to the block.json the test fails. The error is:
If you test be sure to run |
Isn't it missing |
Indeed @gziolo that was the issue! I have refactored the code and now the failing test works. Instead of adding a caption attribute to each image in the gallery I added an attachmentCaptions array attribute of the gallery ( props @talldan ) and that avoided the need to specify a selector and source. |
7effb39
to
c164a28
Compare
23cd0a9
to
dc5c599
Compare
dc5c599
to
c821ca5
Compare
c821ca5
to
3179f4b
Compare
@gziolo the bug you found here is not really solvable without tying up the gallery component to the media gallery in WP, as for fixing that we need to monitor the state of the attachments in the modal and only update the component if that state is "dirty". I would push forward with things as they are, what do you think? |
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.
It's better than it used to be. Let's move forward 👍
* adds simple logic that keeps authored captions in galleries * adds caption updating if changed in gallery, refactores some code * refactor code so as to avoig adding data to the DOM and updated the fixtures * updated new deprecated fixture * removes manual fixture edits * moves attachment captions to state * fixed a problem caused by rebasing
* adds simple logic that keeps authored captions in galleries * adds caption updating if changed in gallery, refactores some code * refactor code so as to avoig adding data to the DOM and updated the fixtures * updated new deprecated fixture * removes manual fixture edits * moves attachment captions to state * fixed a problem caused by rebasing
Description
Attempted fix for #8310
How has this been tested?
Types of changes
Bug fix (non-breaking change which fixes an issue)
Checklist: