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

SWC-4693 #5612

Merged
merged 2 commits into from
Jan 9, 2025
Merged

SWC-4693 #5612

merged 2 commits into from
Jan 9, 2025

Conversation

nickgros
Copy link
Contributor

@nickgros nickgros commented Jan 9, 2025

  • Update UploadDialogWidgetV2 to configure drag-and-drop on render, and to completely re-render when the modal is closed.

EntityActionControllerImpl

  • Configure the uploader when EntityActionControllerImpl is configured to prepare drag-and-drop

  • Use a single instance of UploadDialogWidgetV2 to ensure the same component instance used to configure drag-and-drop is used when the modal is opened.

  • Update Drag-and-Drop initialization code to use JsInterop instead of JSNI

  • Remove feature flag checks for UploadDialogWidgetV2

  • Delete UploadDialogWidget (v1)

- Update UploadDialogWidgetV2 to configure drag-and-drop on render, and
  to completely re-render when the modal is closed.

EntityActionControllerImpl
- Configure the uploader when EntityActionControllerImpl is configured
  to prepare drag-and-drop
- Use a single instance of UploadDialogWidgetV2 to ensure the same component instance used to configure drag-and-drop is used when the modal is opened.

- Update Drag-and-Drop initialization code to use JsInterop instead of
  JSNI
- Remove feature flag checks for UploadDialogWidgetV2
- Delete UploadDialogWidget (v1)
Comment on lines -43 to -45
// If enabled, uses the v2 uploader (react implementation) for file entity uploads.
UPLOADER_V2("UPLOADER_V2"),

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This has been enabled for weeks, let's remove it!

@@ -483,61 +487,61 @@ public void initializeToastContainer() {
public void initializeDropZone() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactored to JsInterop for easier debugging

Comment on lines +534 to +535
dropZone.addEventListener("dragend", e -> hideDropZone.run());
dropZone.addEventListener("dragleave", e -> hideDropZone.run());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Add dragend/dragleave handlers to fix bug where if you dragged into the window, then dragged out of the window, the dropzone wouldn't go away.

Comment on lines +21 to +23
@JsNullable
public String key;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All React components can take a key prop

Comment on lines +24 to +25
@JsNullable
public Callback onUploadReady;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Use new callback prop

Comment on lines +547 to +551
private UploadDialogWidgetV2 getUploadDialogWidget() {
if (uploadDialogWidgetV2 == null) {
uploadDialogWidgetV2 = ginInjector.getUploadDialogWidget();
view.setUploadDialogWidget(uploadDialogWidgetV2.asWidget());
}
Copy link
Contributor Author

@nickgros nickgros Jan 9, 2025

Choose a reason for hiding this comment

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

Use a single instance of the widget to prevent bugs where the widget instance that was configured for drag-and-drop was not the same instance of the widget that is shown to the user. I don't think the present code would have this bug, but I noticed it in an intermediate iteration of this feature and it would otherwise be very easy to reintroduce in a later refactor

Copy link
Member

Choose a reason for hiding this comment

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

We should do some extra testing with component initialization with this change. After uploading a file (or set of files), if you open the uploader to upload another set of files is the component state properly re-initialized?

Copy link
Member

Choose a reason for hiding this comment

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

(assume so with the call to configure())

Comment on lines +1349 to +1373
private boolean canUploadNewFileVersion() {
return (
entityBundle.getEntity() instanceof FileEntity &&
permissions.getCanCertifiedUserEdit()
);
}

private void configureFileUpload() {
if (entityBundle.getEntity() instanceof FileEntity) {
actionMenu.setActionVisible(
Action.UPLOAD_NEW_FILE,
permissions.getCanCertifiedUserEdit()
);
actionMenu.setActionListener(Action.UPLOAD_NEW_FILE, this);
} else {
actionMenu.setActionVisible(Action.UPLOAD_NEW_FILE, false);
}
actionMenu.setActionVisible(
Action.UPLOAD_NEW_FILE,
canUploadNewFileVersion()
);
actionMenu.setActionListener(Action.UPLOAD_NEW_FILE, this);
}

private boolean canUploadFileToContainer() {
return (
isContainerOnFilesTab(entityBundle.getEntity(), currentArea) &&
permissions.getCanCertifiedUserEdit()
);
}

private void configureUploadNewFileEntity() {
if (isContainerOnFilesTab(entityBundle.getEntity(), currentArea)) {
actionMenu.setActionVisible(
Action.UPLOAD_FILE,
permissions.getCanCertifiedUserEdit()
);
actionMenu.setActionListener(Action.UPLOAD_FILE, this);
} else {
actionMenu.setActionVisible(Action.UPLOAD_FILE, false);
}
actionMenu.setActionVisible(Action.UPLOAD_FILE, canUploadFileToContainer());
actionMenu.setActionListener(Action.UPLOAD_FILE, this);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactor to share logic for these checks

Comment on lines 1841 to 1843
case UPLOAD_NEW_FILE:
case UPLOAD_FILE:
onUploadFile();
Copy link
Contributor Author

@nickgros nickgros Jan 9, 2025

Choose a reason for hiding this comment

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

These were different at one point, but today they both open the same widget with identical arguments.

Comment on lines +78 to +80
DomGlobal.console.error(
"EntityUploadHandle ref is null, aborting handleDrop"
);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This should never happen, and user can recover by just opening the uploader, so I decided not to spend time on more sophisticated error handling.

Comment on lines +84 to +86
private void onUploadReady() {
globalApplicationState.setDropZoneHandler(this::handleDrop);
}
Copy link
Contributor Author

@nickgros nickgros Jan 9, 2025

Choose a reason for hiding this comment

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

Defer setting up drag-and-drop until the component tells us it's ready via callback

private void onClose() {
eventBus.fireEvent(new EntityUpdatedEvent(entityId));
// Re-render the component with a new key to reset the state so it no longer shows the previous set of uploads
keyCounter++;
Copy link
Member

Choose a reason for hiding this comment

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

Ah, there's the re-init. Ignore my previous comment :D

@nickgros nickgros merged commit 206fd6c into Sage-Bionetworks:develop Jan 9, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants