Skip to content

Sidebar file actions - #18178

Merged
jancborchardt merged 3 commits into
masterfrom
files-sidebar-actions
Aug 13, 2015
Merged

jancborchardt merged 3 commits into
masterfrom
files-sidebar-actions

Conversation

@PVince81

Copy link
Copy Markdown
Contributor

Fix for #18169

  • move sidebar views to backbone
  • pass backbone FileInfoModel
  • trigger file action on model
  • make the actions actually work...
  • JS unit tests

It doesn't work yet. The file actions are requiring too much context.
But I'll explore another interesting idea: DetailsViewModel. That one could contain all the required information like FileInfo, FileActions and FileList. (even though I'd eventually like the DetailsView to be able to work without knowing anything about the list)

CC @blizzz

@PVince81

Copy link
Copy Markdown
Contributor Author

another challenge:

  • when the user clicks the star in the row, the state in the sidebar must update too and the other way around

A clean way for that is listening to changes on the file model.
Since we still don't have file models for the file list, use a "virtual" model that is used only for the current row.

@PVince81 PVince81 added this to the 8.2-current milestone Aug 11, 2015
@PVince81

Copy link
Copy Markdown
Contributor Author
  • BUG: clicking back and forth between rows doesn't properly reload the thumbnail in sidebar

@PVince81

Copy link
Copy Markdown
Contributor Author

Basically the tough part is to be able to have a shared FileInfoModel instance that is accessible both by the FileList and also by the DetailsView. Since refactoring the FileList to use Backbone collections is out of scope, I'd need to introduce a method setHighlightedFile(fileModel) to be able to set the current model. Then both FileList and DetailsView will listen to its changes and re-render their views in case a property changed (for example the favorite state).
The state would be altered by the FileActions, but for that FileActions need to know what is the currently highlighted file model to be able to pass it to the action handlers. And the action handlers will then call fileInfoModel.set('favorite', true), which will trigger events to update the file list and the view to reflect that state.

Complex stuff... navigating through spaghetti legacy code without breaking any existing APIs...

@PVince81

Copy link
Copy Markdown
Contributor Author

Ah yes, and the problem with setHighlightedFile() idea is that we currently have several highlight states and in some cases two could be activated at the same time, which will break the event logic in that case. Raised #18210 to discuss reducing the highlight states.

@PVince81

Copy link
Copy Markdown
Contributor Author

Raised #18211 to port the FileList and its arrays to backbone.

I realize that the most problematic is the FileActions class for which I'm trying to keep the API stable, which makes it more difficult to modify event handlers to also pass models.

I am still not clear whether we should call FileActions.triggerAction(fileInfoModel) or the reverse FileInfoModel.triggerAction() combined with FileInfoModel.setFileActions(fileActions) (to have access to the action list). The latter makes it possible to pass a single model everywhere and trigger actions on it. The drawback is that we need to inject the FileActions object into it.
The problem with the former is that we need to pass both FileInfoModel and FileActions everywhere, including the sub-views of the sidebar.

So now I'm still trying to think of a good code design for this.

@PVince81

Copy link
Copy Markdown
Contributor Author

Decoupling FileActions from the file list and DOM is close to impossible as it requires rewriting every action handler. And some action handlers are registered by third party apps. So, regardless of the clean solution, we still need to provide a fallback for the legacy action handlers.

I'd still like to decouple FileActions.display() from the file list, because at the time we render the actions we don't have a model for the row, so we can't bind the model to the action handler. But also, binding the model/context to the action handler is a bad approach because it means every file row will have several closures. The best is if the FileList would trigger the action on click and then pass the matching row + model + context to the action handler instead of having the FileActions do it through the closure.

@PVince81

Copy link
Copy Markdown
Contributor Author

Well, or we make the filelist work with backbone collections #18211, this way we'd already have a model for each row so we could just pass it along in the FileActions.display() to be bound to the action handler with the other parameters through context...

But there is still the problem of invoking file actions outside of the file list like in the sidebar. I don't want the sidebar to know anything about the FileList object as it needs to be independent eventually and work in other contexts.

@PVince81

Copy link
Copy Markdown
Contributor Author

Arghh, now I realize that since we want the thumbnail to trigger a default action, it means the action handler for that must also support working with file models instead of the file list object. This will be impossible. Seems like for now there is no way around, we need to pass the FileList and FileActions objects to DetailsView, or embed them into the FileInfoModel, which is super-ugly...

@PVince81

Copy link
Copy Markdown
Contributor Author

Raised #18230 to redesign FileActions.

I give up for now and will pass the FileList object to the sidebar, which will make the sidebar less portable. This problem will need to be addressed before the sidebar moves to the core API.

@PVince81

Copy link
Copy Markdown
Contributor Author

Let's focus on the short term now: inject the filelist in the sidebar components.

Vincent Petry added 3 commits August 12, 2015 17:28
FileInfoModel is a backbone model that will make it possible to track
changes and update views accordingly
The favorite icon in the sidebar now triggers the file action and also
updates itself according to the model's state when triggered from the
file row.

The thumbnail triggers the default action.

Currently only one FileInfoModel is used for the selection and state
synchronization between views.

FileList reload now auto-closes the sidebar.
@PVince81
PVince81 force-pushed the files-sidebar-actions branch from b1e8ecc to c964eff Compare August 12, 2015 15:32
@scrutinizer-notifier

Copy link
Copy Markdown

A new inspection was created.

@PVince81 PVince81 changed the title [WIP] Sidebar file actions Sidebar file actions Aug 12, 2015
@PVince81

Copy link
Copy Markdown
Contributor Author

The solution was actually to pass FileList and FileActions to the MainFileInfoDetailsView before it gets registered into the sidebar. This only couples that panel with the filelist, not the whole sidebar.

This PR is ready for review:

  • TEST: clicking star in sidebar also updates row star
  • TEST: clicking row star also updates sidebar star
  • TEST: clicking thumbnail triggers default action: folder opens, picture opens slideshow, etc

Please review @blizzz @jancborchardt @rullzer

@PVince81

Copy link
Copy Markdown
Contributor Author

@ghost

ghost commented Aug 12, 2015

Copy link
Copy Markdown

🚀 Test PASSed.🚀
chuck

@MorrisJobke

Copy link
Copy Markdown
Contributor

Tested and works 👍

code looks good

@PVince81

Copy link
Copy Markdown
Contributor Author

Needs a second review. This is blocking other tasks.
Thanks.

@jancborchardt

Copy link
Copy Markdown
Contributor

Nice, everything works! 👍

jancborchardt added a commit that referenced this pull request Aug 13, 2015
@jancborchardt
jancborchardt merged commit 4e53b59 into master Aug 13, 2015
@jancborchardt
jancborchardt deleted the files-sidebar-actions branch August 13, 2015 15:17
@PVince81

Copy link
Copy Markdown
Contributor Author

Thanks 😄

@lock lock Bot locked as resolved and limited conversation to collaborators Aug 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants