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

Upload command always visible on browser #11756

Merged

Conversation

federicobozzini
Copy link
Contributor

What it does

This PR makes the Upload Files... menu entry always visible on a browser environment. At the moment the menu entry disappears if no folder is selected on the explorer and I think this might quite counter-intuitive for a lot of users as menu entries don't generally disappear if they are unusable but they just get disabled.

How to test

Just start Theia and check the menu entry for uploading files and the File menu. It should now always be visible.

Review checklist

Reminder for reviewers

Copy link
Member

@vince-fugnitto vince-fugnitto left a comment

Choose a reason for hiding this comment

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

@federicobozzini I'm not sure this change works as you intended, a selection of a directory is needed in order for the command to be added in the first place and is not always visible (I think this behavior is odd):

initially (perform a reset workbench layout)

Screen Shot 2022-10-12 at 8 17 16 AM

after a directory selection:

Screen Shot 2022-10-12 at 8 19 13 AM

@vince-fugnitto vince-fugnitto added filesystem issues related to the filesystem menus issues related to the menu labels Oct 12, 2022
@federicobozzini federicobozzini force-pushed the upload-command-visibility branch from 2805f53 to 35b0066 Compare October 12, 2022 13:33
@federicobozzini
Copy link
Contributor Author

@vince-fugnitto My mistake, it should now be fixed.

This weird behavior comes from the fact that the command handler is transformed by the FileSelection.CommandHandler (based on SelectionCommandHandler) which always check if a selection is currently active. Since not every component based on SelectionCommandHandler might need this behavior I've removed from there.

SelectionCommandHandler is currently used by:

@@ -33,7 +33,7 @@ export class SelectionCommandHandler<S> implements CommandHandler {

isVisible(...args: any[]): boolean {
const selection = this.getSelection(...args);
return !!selection && (!this.options.isVisible || (this.options.isVisible as any)(selection as any, ...args));
return !this.options.isVisible || (this.options.isVisible as any)(selection as any, ...args);
Copy link
Member

Choose a reason for hiding this comment

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

This is a breaking change that is problematic. We should not update isVisible for all selection command handlers to fix the minor bug. The isVisible would break downstream applications if used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've pushed a different solution, with no breaking changes.

Copy link
Member

Choose a reason for hiding this comment

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

I'm trying to think about this one a bit more, I'm not sure the proper or cleanest solution would be to force the selection-command-handler to suit our needs but maybe rather create a new handler, or even omit using the selection-command-handler and instead handle things ourselves with the selectionService.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree this issue can be fixed in different ways. My basic understanding is that there is no reason why SelectionCommandHandler should force the visibility of item to always consider a selection though. I don't think it's completely unreasonable to let this be decided for every specific command handler getting registered.

In any case I'm happy to change this PR if you have a better suggestion.

Copy link
Member

Choose a reason for hiding this comment

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

By definition and name the SelectionCommandHandler is based on selection so that makes sense. If we do not care about the selection like in this case then the handler shouldn't be used and we can instead handle it ourselves rather than try to fit it to our needs for this specific use-case.

@federicobozzini federicobozzini force-pushed the upload-command-visibility branch from 35b0066 to 3ecfa82 Compare October 12, 2022 14:11
@colin-grant-work
Copy link
Contributor

colin-grant-work commented Oct 12, 2022

I would recommend simply rewriting the handler for this item not to be a FileSelection.CommandHandler. Since we have access to the SelectionService locally, it would be possible to achieve similar behavior, with the desired modifications, without modifying the FileSelection.CommandHandler class. Though in principle, I agree that the FileSelection.CommandHandler likely shouldn't impose its own constraints on the handlers passed in - setting its own conditions before it runs the handler - but only handle the logic of extracting the selection.

@federicobozzini federicobozzini force-pushed the upload-command-visibility branch 2 times, most recently from c6366a9 to 0af9263 Compare October 12, 2022 16:12
@federicobozzini
Copy link
Contributor Author

@vince-fugnitto @colin-grant-work I've change this PR to only change the behavior of the upload button. There is some code repetition but I think that's unfortunately inevitable.

@vince-fugnitto vince-fugnitto dismissed their stale review October 13, 2022 16:57

Changes were updated

@federicobozzini
Copy link
Contributor Author

@colin-grant-work @vince-fugnitto Can this PR be merged?

Copy link
Member

@vince-fugnitto vince-fugnitto left a comment

Choose a reason for hiding this comment

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

The change looks good to me 👍

  • upload files... is always visible
  • upload files... is enabled if a folder is selected
  • upload files... is disabled if a file is selected
  • uploading files works as expected

@colin-grant-work
Copy link
Contributor

@federicobozzini, it looks like this is failing the Eclipse Contributor Agreement check because of the shared commits - would you mind pushing a squashed version?

@msujew
Copy link
Member

msujew commented Jan 18, 2023

@federicobozzini Do you mind squashing your commits to fix the ECA check?

@federicobozzini federicobozzini force-pushed the upload-command-visibility branch from f155a6d to a8791a9 Compare January 18, 2023 17:14
@federicobozzini
Copy link
Contributor Author

I've pushed a squashed version, thanks.

@paul-marechal paul-marechal merged commit ca59f1d into eclipse-theia:master Jan 22, 2023
@paul-marechal paul-marechal added this to the 1.34.0 milestone Jan 24, 2023
@federicobozzini federicobozzini deleted the upload-command-visibility branch March 31, 2023 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
filesystem issues related to the filesystem menus issues related to the menu
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants