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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ public enum FeatureFlagKey {
// If enabled, sharing settings will appear in a dialog immediately after uploading one or more files.
SHOW_SHARING_SETTINGS_AFTER_UPLOAD("SHOW_SHARING_SETTINGS_AFTER_UPLOAD"),

// If enabled, uses the v2 uploader (react implementation) for file entity uploads.
UPLOADER_V2("UPLOADER_V2"),

Comment on lines -43 to -45
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!

// If enabled, uses the file browser react implementation
REACT_FILE_BROWSER("REACT_FILE_BROWSER"),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.datepicker.client.CalendarUtil;
import com.google.inject.Inject;
import elemental2.dom.DomGlobal;
import elemental2.dom.DragEvent;
import elemental2.dom.EventListener;
import elemental2.dom.FileList;
import elemental2.dom.HTMLDivElement;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
Expand Down Expand Up @@ -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

if (!isDragDropInitialized) {
isDragDropInitialized = true;
Element dropZoneElement = RootPanel.get("dropzone").getElement();
Element rootPanelElement = RootPanel.get("rootPanel").getElement();
_initializeDragDrop(this, dropZoneElement, rootPanelElement);
HTMLDivElement dropZoneElement =
(HTMLDivElement) DomGlobal.document.querySelector("[id=\"dropzone\"]");
HTMLDivElement rootPanelElement =
(HTMLDivElement) DomGlobal.document.querySelector("[id=\"rootPanel\"]");
initializeDragDrop(this, dropZoneElement, rootPanelElement);
}
}

private static final native void _initializeDragDrop(
private static void initializeDragDrop(
GlobalApplicationStateImpl globalAppState,
Element dropZone,
Element rootPanel
) /*-{
try {
function showDropZone() {
dropZone.style.display = "block";
}

function hideDropZone() {
dropZone.style.display = "none";
}

$wnd
.addEventListener(
'dragenter',
function(e) {
if (globalAppState.@org.sagebionetworks.web.client.GlobalApplicationStateImpl::isDragAndDropListenerSet()()) {
showDropZone();
}
});

function allowDrag(e) {
e.dataTransfer.dropEffect = 'copy';
e.preventDefault();
}

function handleDrop(e) {
e.preventDefault();
hideDropZone();
globalAppState.@org.sagebionetworks.web.client.GlobalApplicationStateImpl::onDrop(Lelemental2/dom/FileList;)(e.dataTransfer.files);
}

dropZone.addEventListener('dragenter', allowDrag);
dropZone.addEventListener('dragover', allowDrag);

dropZone.addEventListener('drop', handleDrop);

//if files are dropped into the root panel, then ignore the event (do not open file contents if user does not have the upload dialog open).
rootPanel.addEventListener('drop', function(e) {
e.preventDefault();
});
rootPanel.addEventListener('dragenter', allowDrag);
rootPanel.addEventListener('dragover', allowDrag);
} catch (err) {
console.error(err);
}
}-*/;
HTMLDivElement dropZone,
HTMLDivElement rootPanel
) {
try {
Runnable showDropZone = () -> dropZone.style.set("display", "block");
Runnable hideDropZone = () -> dropZone.style.set("display", "none");

DomGlobal.window.addEventListener(
"dragenter",
e -> {
if (globalAppState.isDragAndDropListenerSet()) {
showDropZone.run();
}
}
);

EventListener allowDrag = e -> {
if (e instanceof DragEvent) {
((DragEvent) e).dataTransfer.dropEffect = "copy";
e.preventDefault();
}
};
EventListener handleDrop = e -> {
if (e instanceof DragEvent) {
e.preventDefault();
hideDropZone.run();
globalAppState.onDrop(((DragEvent) e).dataTransfer.files);
}
};

dropZone.addEventListener("dragenter", allowDrag);
dropZone.addEventListener("dragover", allowDrag);

dropZone.addEventListener("drop", handleDrop);
dropZone.addEventListener("dragend", e -> hideDropZone.run());
dropZone.addEventListener("dragleave", e -> hideDropZone.run());
Comment on lines +534 to +535
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.


//if files are dropped into the root panel, then ignore the event (do not open file contents if user does not have the upload dialog open).
rootPanel.addEventListener("drop", elemental2.dom.Event::preventDefault);
rootPanel.addEventListener("dragenter", allowDrag);
rootPanel.addEventListener("dragover", allowDrag);
} catch (Exception e) {
DomGlobal.console.error("Error on drag-and-drop initialization", e);
}
}

@Override
public void setDropZoneHandler(CallbackP<FileList> fileListCallback) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@
import org.sagebionetworks.web.client.widget.entity.controller.URLProvEntryView;
import org.sagebionetworks.web.client.widget.entity.download.AddFolderDialogWidget;
import org.sagebionetworks.web.client.widget.entity.download.QuizInfoDialog;
import org.sagebionetworks.web.client.widget.entity.download.UploadDialogWidget;
import org.sagebionetworks.web.client.widget.entity.download.UploadDialogWidgetV2;
import org.sagebionetworks.web.client.widget.entity.editor.APITableColumnConfigView;
import org.sagebionetworks.web.client.widget.entity.editor.APITableConfigEditor;
Expand Down Expand Up @@ -730,9 +729,7 @@ public interface PortalGinInjector extends Ginjector {

EntityFinderWidgetView getEntityFinderWidgetView();

UploadDialogWidget getUploadDialogWidget();

UploadDialogWidgetV2 getUploadDialogWidgetV2();
UploadDialogWidgetV2 getUploadDialogWidget();

WikiMarkdownEditor getWikiMarkdownEditor();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.sagebionetworks.web.client.jsinterop;

import jsinterop.annotations.JsFunction;
import jsinterop.annotations.JsNullable;
import jsinterop.annotations.JsOverlay;
import jsinterop.annotations.JsPackage;
import jsinterop.annotations.JsType;
Expand All @@ -20,20 +21,26 @@ public interface Callback {

public Callback onClose;

@JsNullable
public Callback onUploadReady;
Comment on lines +24 to +25
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


@JsNullable
public ReactRef<EntityUploadHandle> ref;

@JsOverlay
public static EntityUploadModalProps create(
String containerId,
boolean open,
Callback onClose,
ReactRef<EntityUploadHandle> ref
ReactRef<EntityUploadHandle> ref,
Callback onUploadReady
) {
EntityUploadModalProps props = new EntityUploadModalProps();
props.entityId = containerId;
props.open = open;
props.onClose = onClose;
props.ref = ref;
props.onUploadReady = onUploadReady;
return props;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.gwt.dom.client.Element;
import jsinterop.annotations.JsConstructor;
import jsinterop.annotations.JsFunction;
import jsinterop.annotations.JsNullable;
import jsinterop.annotations.JsPackage;
import jsinterop.annotations.JsType;

Expand All @@ -17,6 +18,10 @@ public interface CallbackRef {
void run(Element element);
}

@JsNullable
public String key;

Comment on lines +21 to +23
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

// Either a ComponentRef or CallbackRef may be passed. A CallbackRef will be invoked when the ref is set.
@JsNullable
public Object ref;
}
Loading
Loading