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

Add video tracks functionality #25861

Merged
merged 3 commits into from
Oct 16, 2020
Merged

Conversation

jorgefilipecosta
Copy link
Member

Implements tracks adding and edition functionality on the video block.
Fixes: #7673

This PR follows the design proposed by @enriquesanchez with some adaptations because of the way our components work.

How has this been tested?

I added a video block, with a video file.
I used the tracks option on the toolbar.
I selected the upload option.
I verified a system window to select a file to upload opened.
I verified this window only allow to pick .vtt (all tracks on the tracks element must be in the vtt format).
I uploaded the file.
I saved the post and verified the track worked as expected.
I added another video block and used the tracks option.
I selected the "Open Media Library Option" and verified the media library only showed vtt files.
I verified I could edit the tracks.
I verified I could remove the tracks.

Screenshots

image

image

@jorgefilipecosta jorgefilipecosta added [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). [Block] Video Affects the Video Block [Type] Feature New feature to highlight in changelogs. labels Oct 6, 2020
@github-actions
Copy link

github-actions bot commented Oct 6, 2020

Size Change: +2.06 kB (0%)

Total Size: 1.19 MB

Filename Size Change
build/annotations/index.js 3.54 kB -1 B
build/autop/index.js 2.72 kB +1 B
build/block-editor/index.js 130 kB +12 B (0%)
build/block-library/editor-rtl.css 8.93 kB +240 B (2%)
build/block-library/editor.css 8.93 kB +239 B (2%)
build/block-library/index.js 144 kB +1.58 kB (1%)
build/blocks/index.js 47.6 kB -4 B (0%)
build/components/index.js 169 kB +13 B (0%)
build/compose/index.js 9.63 kB +1 B
build/data-controls/index.js 683 B -1 B
build/date/index.js 31.9 kB +1 B
build/edit-post/index.js 306 kB -4 B (0%)
build/editor/index.js 42.6 kB -1 B
build/element/index.js 4.45 kB +1 B
build/keyboard-shortcuts/index.js 2.38 kB -1 B
build/notices/index.js 1.69 kB -1 B
build/plugins/index.js 2.44 kB -1 B
build/redux-routine/index.js 2.85 kB -2 B (0%)
build/reusable-blocks/index.js 3.04 kB -1 B
build/server-side-render/index.js 2.61 kB +2 B (0%)
build/token-list/index.js 1.24 kB -1 B
build/url/index.js 4.06 kB -5 B (0%)
build/warning/index.js 1.13 kB -2 B (0%)
ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 1.14 kB 0 B
build/api-fetch/index.js 3.35 kB 0 B
build/blob/index.js 668 B 0 B
build/block-directory/index.js 8.6 kB 0 B
build/block-directory/style-rtl.css 943 B 0 B
build/block-directory/style.css 942 B 0 B
build/block-editor/style-rtl.css 11 kB 0 B
build/block-editor/style.css 10.9 kB 0 B
build/block-library/style-rtl.css 7.71 kB 0 B
build/block-library/style.css 7.71 kB 0 B
build/block-library/theme-rtl.css 741 B 0 B
build/block-library/theme.css 741 B 0 B
build/block-serialization-default-parser/index.js 1.77 kB 0 B
build/block-serialization-spec-parser/index.js 3.1 kB 0 B
build/components/style-rtl.css 15.4 kB 0 B
build/components/style.css 15.4 kB 0 B
build/core-data/index.js 12.1 kB 0 B
build/data/index.js 8.63 kB 0 B
build/deprecated/index.js 772 B 0 B
build/dom-ready/index.js 569 B 0 B
build/dom/index.js 4.43 kB 0 B
build/edit-navigation/index.js 10.6 kB 0 B
build/edit-navigation/style-rtl.css 868 B 0 B
build/edit-navigation/style.css 871 B 0 B
build/edit-post/style-rtl.css 6.37 kB 0 B
build/edit-post/style.css 6.35 kB 0 B
build/edit-site/index.js 21.6 kB 0 B
build/edit-site/style-rtl.css 3.8 kB 0 B
build/edit-site/style.css 3.81 kB 0 B
build/edit-widgets/index.js 21.6 kB 0 B
build/edit-widgets/style-rtl.css 3.09 kB 0 B
build/edit-widgets/style.css 3.09 kB 0 B
build/editor/editor-styles-rtl.css 480 B 0 B
build/editor/editor-styles.css 482 B 0 B
build/editor/style-rtl.css 3.85 kB 0 B
build/editor/style.css 3.84 kB 0 B
build/escape-html/index.js 733 B 0 B
build/format-library/index.js 7.49 kB 0 B
build/format-library/style-rtl.css 547 B 0 B
build/format-library/style.css 548 B 0 B
build/hooks/index.js 1.74 kB 0 B
build/html-entities/index.js 622 B 0 B
build/i18n/index.js 3.54 kB 0 B
build/is-shallow-equal/index.js 709 B 0 B
build/keycodes/index.js 1.85 kB 0 B
build/list-reusable-blocks/index.js 3.02 kB 0 B
build/list-reusable-blocks/style-rtl.css 476 B 0 B
build/list-reusable-blocks/style.css 476 B 0 B
build/media-utils/index.js 5.12 kB 0 B
build/nux/index.js 3.27 kB 0 B
build/nux/style-rtl.css 671 B 0 B
build/nux/style.css 668 B 0 B
build/primitives/index.js 1.35 kB 0 B
build/priority-queue/index.js 789 B 0 B
build/rich-text/index.js 13 kB 0 B
build/shortcode/index.js 1.7 kB 0 B
build/viewport/index.js 1.75 kB 0 B
build/wordcount/index.js 1.17 kB 0 B

compressed-size-action

@enriquesanchez
Copy link
Contributor

Thank you, @jorgefilipecosta! This is looking really really good.

I have some feedback on the design:

  1. We need a tooltip and aria-label for the tracks button in the block toolbar. It should say 'Text tracks'.
  2. The menu group label should also say 'Text tracks'.
  3. When selecting to upload a track file, keyboard focus should be placed on the first focusable element, the label field.
  4. When uploading a track, the 'Ok' button should say 'Add track' instead.
  5. Let's add a 'Cancel' button next to it. This should let users cancel the process in case they change their mind.
  6. I also think we should not show the 'Remove' button when the user is in the upload process. Removing should only be allowed once a track has been added.
  7. When editing a track, the 'Ok' button should say 'Save' and we should also have the option to 'Cancel'.
  8. When editing a track, we shuould display the 'Remove track' button.

Do you have any context on why we only support the vtt format? I know srt is a very common format for subtitles and I wonder why that one is not allowed.

Again, thank you for working on this 🎉

@jorgefilipecosta
Copy link
Member Author

Hi @enriquesanchez, thank you for the review. 👍
I will update this PR to address your feedback.

Let's add a 'Cancel' button next to it. This should let users cancel the process in case they change their mind.
Let's add a 'Cancel' button next to it. This should let users cancel the process in case they change their mind.
I also think we should not show the 'Remove' button when the user is in the upload process. Removing should only be allowed once a track has been added.
When editing a track, the 'Ok' button should say 'Save' and we should also have the option to 'Cancel'.

I did not add a Save because a save would not be reflecting what is happening. When the user changes something, e.g.: the label the attribute is already saved, there would be nothing to save. The changes are immediate and are saved on each keypress. That's what happens on all the other cases on the block editor, e.g., inspector changes; if we change a field, the change is applied right away. The user, of course, can use undo to undo the change. What the ok is doing is just going back to the tracklist. It is not saving anything. That's also the reason why we don't have a cancel because the cancel would also just go back to the tracklist. So Ok and Cancel are the same thing given how things are implemented.
I tried to follow the general philosophy of saving the attributes right away. I think we don't have other cases with a save operation.

But if we think in this case, we have a special situation and should not follow the pattern of the immediate block attribute changes, I can implement a local state on the component. User changes are saved to the local state. On the save operation, the changes are saved to the attributes, and on the cancel, they are discarded, and the local state is reset.
In that case, undo/redo would not affect local state changes. E.g.: the user changes the label and uses undo before pressing save, undo would affect other action, and the label the user wrote would still be there (the change would be discarded with cancel).
This situation is, in fact a little different from all the other cases, so It may make sense to implement something special, let me know what you think.

Do you have any context on why we only support the vtt format? I know srt is a very common format for subtitles and I wonder why that one is not allowed.

The track element specification says only vtt (Web Video Text Tracks) format for the track element as we can check at https://developer.mozilla.org/en-US/docs/Web/HTML/Element/track.

@jorgefilipecosta
Copy link
Member Author

jorgefilipecosta commented Oct 7, 2020

We need a tooltip and aria-label for the tracks button in the block toolbar. It should say 'Text tracks'.
The menu group label should also say 'Text tracks'.
When selecting to upload a track file, keyboard focus should be placed on the first focusable element, the label field.

Done 👍

@enriquesanchez
Copy link
Contributor

I did not add a Save because a save would not be reflecting what is happening.

Thank you for that detailed clarification, @jorgefilipecosta. I don't think this should be a special case and perhaps the design needs a bit of adjusting so we don't mislead users.

The presence of a Save/Done/OK button does create the illusion of there being a confirmation step when in reality there isn't one. That said, because this is not a simple menu popover, I think there should still be a clear way to close it. In light of this, I think that your initial implementation is right; we just need to change the button to use the default style and change the label to 'Close' so it's more clear what is happening:

Frame 33

How does that feel to you?


I also just noticed that in the PR the file name is missing in the 'File:' field up top:

Screen Shot 2020-10-07 at 14 08 26

@mtias
Copy link
Member

mtias commented Oct 9, 2020

Can we add a little inline description on what "tracks" are? It's can be quite inscrutable as is.

@jorgefilipecosta
Copy link
Member Author

Hi @mtias,
Before any track is added there is a small text indicating what a track is:
image

Would you like that this text is expended or would want to show this message in other states e.g: there are tracks already added or the user is editing a track?

@jorgefilipecosta
Copy link
Member Author

Hi @enriquesanchez,

I also just noticed that in the PR the file name is missing in the 'File:' field up top:

It was fixed.

Your feedback was applied and the UI updates were implemented.

@mtias
Copy link
Member

mtias commented Oct 12, 2020

Would you like that this text is expended or would want to show this message in other states e.g: there are tracks already added or the user is editing a track?

Ah, thanks. I think it can make sense to keep it always displayed, but let's see how it feels

@enriquesanchez
Copy link
Contributor

enriquesanchez commented Oct 12, 2020

@jorgefilipecosta Thanks for the updates 🙌

I'm still not seeing the file name displayed. I made sure to update the branch and tried in both Firefox and Safari. Maybe I'm missing something?

Screen Shot 2020-10-12 at 16 09 48


I also tested with VoiceOver and I think we can add a small improvement to make it more accessible. The 'Edit' button for each text track should say what text track is that you'll be editing. I think we can leave the 'Edit' label as is and just add an aria-label that is more descriptive: 'Edit [title of track]' (ie: Edit French subtitles).

I also noticed that you can leave these fields empty, which results in this:

Screen Shot 2020-10-12 at 16 25 39

I don't think we should allow for this to happen and should make these fields required. Alternatively, we can at least display some defaults. For example, if no label is provided we can use the file name as the track's label.

For reference the Classic editor defaults to label="English", srclang="en", and kind="subtitles".

What do you think?

@jorgefilipecosta
Copy link
Member Author

Would you like that this text is expended or would want to show this message in other states e.g: there are tracks already added or the user is editing a track?

Ah, thanks. I think it can make sense to keep it always displayed, but let's see how it feels

I followed this suggestion by @mtias and added the text to the tracklist too:

image

I also tested with VoiceOver and I think we can add a small improvement to make it more accessible. The 'Edit' button for each text track should say what text track is that you'll be editing. I think we can leave the 'Edit' label as is and just add an aria-label that is more descriptive: 'Edit [title of track]' (ie: Edit French subtitles).

Suggestion applied.

I don't think we should allow for this to happen and should make these fields required. Alternatively, we can at least display some defaults. For example, if no label is provided we can use the file name as the track's label.

I followed the same approach the classic editor does. At the start the inputs are empty but if the user does not fill them they get the default values of "English" and "en" exactly what the classic editor does.

I'm still not seeing the file name displayed. I made sure to update the branch and tried in both Firefox and Safari. Maybe I'm missing something?

I'm not being able to reproduce the issue:

image

Right after I upload a vtt file for like 1 second the field is empty but after the file is uploaded the name appears, and each time I go to edit.
Would you be able to share the steps you did, the vtt file you are using, and the markup of the block (switch to the code editor and copy paster what is there)? Thank you in advance this may be helpful for me to understand where is the bug.

@youknowriad youknowriad self-requested a review October 13, 2020 16:51
@enriquesanchez
Copy link
Contributor

@mtias Would like for us to reconsider showing the description of what text tracks are all the time. I think it's enough to display it when there are no text tracks/ the first time the menu is opened. Authors will encounter the description every time they add a new video, for example.

I don't think it's necesssary to show it after tracks have been added. By then the user should already be familiar with the feature, and not having it helps us keep the menu more condensed in the case multiple tracks are added.

@enriquesanchez
Copy link
Contributor

Thank you for working on these updates, @jorgefilipecosta. This is in much better shape now. 🙌

I noticed a small issue when navigating with keyboard. When opening the menu, if you use the down arrow the menu closes and focus is lost and moved up to the title of the document. I expect that users might try to use up/down arrow keys when they open this menu for the first time because up/down is used to navigate other menus in the block editor. We should make sure that focus is retained inside the popover.

}

export default function TracksEditor( { tracks = [], onChange } ) {
const mediaUpload = useSelect( ( select ) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just noting that this can be undefined, in which case we should probably hide the button entirely right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Or maybe allow using external URLs (can be for later).

Copy link
Member Author

Choose a reason for hiding this comment

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

Yah not rendering anything seems like a good option for now. I updated the code.

<TracksEditor
tracks={ tracks }
onChange={ ( newTracks ) => {
setAttributes( { tracks: newTracks } );
Copy link
Contributor

Choose a reason for hiding this comment

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

Just want to ask whether the shape of the "track" object set here is well defined and that we're not dumping the whole object from the API or something like that.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, the shape is very specific an array of objects that may have {src, label, srcLang, kind } properties all being strings. We never dump anything from an API there we are intentional in storing the src explicitly (the other attributes came from user inputs).

@mtias
Copy link
Member

mtias commented Oct 14, 2020

@enriquesanchez sure, don't have a strong opinion on it outside of the fact I think we can generally use contextual guidance built in into the UI better.

@jorgefilipecosta
Copy link
Member Author

Hi @enriquesanchez,

I noticed a small issue when navigating with keyboard. When opening the menu, if you use the down arrow the menu closes and focus is lost and moved up to the title of the document. I expect that users might try to use up/down arrow keys when they open this menu for the first time because up/down is used to navigate other menus in the block editor. We should make sure that focus is retained inside the popover.

It was fixed.

I also reverted and made the help text only appear before the first track is added.

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

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

LGTM code wise

@enriquesanchez
Copy link
Contributor

Much better, thank you @jorgefilipecosta 👏

I'm still finding that the popover closes and my focus moves up to the document title when I use up/down arrows in the edit screen.

Screen Shot 2020-10-14 at 16 46 33

Can you reproduce this?

@jorgefilipecosta
Copy link
Member Author

I'm still finding that the popover closes and my focus moves up to the document title when I use up/down arrows in the edit screen.

Nice catch @enriquesanchez the issue was fixed.

@enriquesanchez
Copy link
Contributor

👏 This is working really well, @jorgefilipecosta. Thank you!

I'm making some minor CSS tweaks on alignment and spacing of labels and fields and once I have that ready we should be good to go.

@tellthemachines
Copy link
Contributor

Hey peeps, is this ready to merge?

@@ -102,3 +87,18 @@
.block-library-video-tracks-editor__add-tracks-container {
padding: $grid-unit-15;
}

.block-library-video-tracks-editor__single-track-editor .components-base-control {
Copy link
Contributor

Choose a reason for hiding this comment

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

these look like editor specific styles so they should move to editor.scss right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually the whole changes on this file should probably move there.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure how these changes will affect the whole of the editor. My intention was to specifically target the video tracks popover.

@jorgefilipecosta jorgefilipecosta merged commit 602fcc3 into master Oct 16, 2020
WordPress 5.6.x Must Haves automation moved this from In progress to Done Oct 16, 2020
@jorgefilipecosta jorgefilipecosta deleted the add/video-tracks-functionality branch October 16, 2020 19:00
@github-actions github-actions bot added this to the Gutenberg 9.2 milestone Oct 16, 2020
Comment on lines +2 to +4
return tracks.map( ( track ) => {
return <track key={ track.src } { ...track } />;
} );
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should use a different variable name in the loop that can't be confused with the <track /> tag name easily?

Suggested change
return tracks.map( ( track ) => {
return <track key={ track.src } { ...track } />;
} );
return tracks.map( ( t ) => {
return <track key={ t.src } { ...t } />;
} );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Video Affects the Video Block [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). [Type] Feature New feature to highlight in changelogs.
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

Video Block: Subtitles
6 participants