Skip to content

Commit

Permalink
Merge pull request #5612 from nickgros/SWC-4693
Browse files Browse the repository at this point in the history
  • Loading branch information
nickgros authored Jan 9, 2025
2 parents 3617cc9 + 9e3857a commit 206fd6c
Show file tree
Hide file tree
Showing 10 changed files with 239 additions and 423 deletions.
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"),

// 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() {
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());

//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 @@ -136,7 +136,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 @@ -733,9 +732,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;

@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;

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

0 comments on commit 206fd6c

Please sign in to comment.