Skip to content

Commit

Permalink
Merge pull request #5581 from nickgros/SWC-7064a
Browse files Browse the repository at this point in the history
  • Loading branch information
nickgros authored Nov 15, 2024
2 parents baf4b1b + 539863e commit 2168d31
Show file tree
Hide file tree
Showing 9 changed files with 183 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ 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"),

// Last flag is used only for tests
TEST_FLAG_ONLY("TEST_FLAG_ONLY");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
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;
import org.sagebionetworks.web.client.widget.entity.editor.AttachmentConfigEditor;
Expand Down Expand Up @@ -731,6 +732,8 @@ public interface PortalGinInjector extends Ginjector {

UploadDialogWidget getUploadDialogWidget();

UploadDialogWidgetV2 getUploadDialogWidgetV2();

WikiMarkdownEditor getWikiMarkdownEditor();

AddFolderDialogWidget getAddFolderDialogWidget();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package org.sagebionetworks.web.client;

import com.google.gwt.dom.client.Element;
import elemental2.dom.Blob;
import elemental2.dom.FileList;
import org.sagebionetworks.web.client.callback.MD5Callback;

public interface SynapseJsInteropUtils {
FileList getFileList(String fileFieldId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Element;
import elemental2.dom.Blob;
import elemental2.dom.DomGlobal;
import elemental2.dom.File;
import elemental2.dom.FileList;
import elemental2.dom.HTMLInputElement;
import jsinterop.base.Js;
import org.sagebionetworks.web.client.callback.MD5Callback;

public class SynapseJsInteropUtilsImpl implements SynapseJsInteropUtils {

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

import elemental2.dom.FileList;
import jsinterop.annotations.JsPackage;
import jsinterop.annotations.JsType;

@JsType(isNative = true, namespace = JsPackage.GLOBAL, name = "Object")
public class EntityUploadHandle {

/**
* The EntityUploadModal component exposes an imperative handle to programmatically upload files.
*/
public native void handleUploads(FileList fileList);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.sagebionetworks.web.client.jsinterop;

import jsinterop.annotations.JsFunction;
import jsinterop.annotations.JsOverlay;
import jsinterop.annotations.JsPackage;
import jsinterop.annotations.JsType;

@JsType(isNative = true, namespace = JsPackage.GLOBAL, name = "Object")
public class EntityUploadModalProps extends ReactComponentProps {

@FunctionalInterface
@JsFunction
public interface Callback {
void run();
}

public String entityId;

public boolean open;

public Callback onClose;

public ReactRef<EntityUploadHandle> ref;

@JsOverlay
public static EntityUploadModalProps create(
String containerId,
boolean open,
Callback onClose,
ReactRef<EntityUploadHandle> ref
) {
EntityUploadModalProps props = new EntityUploadModalProps();
props.entityId = containerId;
props.open = open;
props.onClose = onClose;
props.ref = ref;
return props;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public static class SynapseComponents {
public static ReactComponentType<
ProjectDataAvailabilityProps
> ProjectDataAvailability;
public static ReactComponentType<EntityUploadModalProps> EntityUploadModal;

/**
* Pushes a global toast message. In SWC, you should use {@link DisplayUtils#notify}, rather than calling this method directly.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
import org.sagebionetworks.web.client.widget.entity.browse.EntityFinderWidget;
import org.sagebionetworks.web.client.widget.entity.download.AddFolderDialogWidget;
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.file.AddToDownloadListV2;
import org.sagebionetworks.web.client.widget.entity.menu.v3.Action;
import org.sagebionetworks.web.client.widget.entity.menu.v3.ActionListener;
Expand Down Expand Up @@ -555,6 +556,13 @@ private UploadDialogWidget getNewUploadDialogWidget() {
return uploadDialogWidget;
}

private UploadDialogWidgetV2 getNewUploadDialogWidgetV2() {
UploadDialogWidgetV2 uploadDialogWidgetV2 =
ginInjector.getUploadDialogWidgetV2();
view.setUploadDialogWidget(uploadDialogWidgetV2.asWidget());
return uploadDialogWidgetV2;
}

private WikiMarkdownEditor getWikiMarkdownEditor() {
if (wikiEditor == null) {
wikiEditor = ginInjector.getWikiMarkdownEditor();
Expand Down Expand Up @@ -2049,16 +2057,23 @@ private void postCheckCreateTableOrView(TableType table) {

private void onUploadNewFileEntity() {
checkUploadEntity(() -> {
UploadDialogWidget uploader = getNewUploadDialogWidget();
uploader.configure(
DisplayConstants.TEXT_UPLOAD_FILE_OR_LINK,
null,
entityBundle.getEntity().getId(),
null,
true
);
uploader.setUploaderLinkNameVisible(true);
uploader.show();
if (featureFlagConfig.isFeatureEnabled(FeatureFlagKey.UPLOADER_V2)) {
UploadDialogWidgetV2 uploadDialogWidgetV2 =
getNewUploadDialogWidgetV2();
uploadDialogWidgetV2.configure(entityBundle.getEntity().getId());
uploadDialogWidgetV2.show();
} else {
UploadDialogWidget uploader = getNewUploadDialogWidget();
uploader.configure(
DisplayConstants.TEXT_UPLOAD_FILE_OR_LINK,
null,
entityBundle.getEntity().getId(),
null,
true
);
uploader.setUploaderLinkNameVisible(true);
uploader.show();
}
});
}

Expand Down Expand Up @@ -2122,17 +2137,23 @@ private void onUploadFile() {
}

private void postCheckUploadFile() {
UploadDialogWidget uploadDialogWidget = getNewUploadDialogWidget();
uploadDialogWidget.configure(
DisplayConstants.TEXT_UPLOAD_FILE_OR_LINK,
entityBundle.getEntity(),
null,
null,
true
);
uploadDialogWidget.disableMultipleFileUploads();
uploadDialogWidget.setUploaderLinkNameVisible(false);
uploadDialogWidget.show();
if (featureFlagConfig.isFeatureEnabled(FeatureFlagKey.UPLOADER_V2)) {
UploadDialogWidgetV2 uploadDialogWidgetV2 = getNewUploadDialogWidgetV2();
uploadDialogWidgetV2.configure(entityBundle.getEntity().getId());
uploadDialogWidgetV2.show();
} else {
UploadDialogWidget uploadDialogWidget = getNewUploadDialogWidget();
uploadDialogWidget.configure(
DisplayConstants.TEXT_UPLOAD_FILE_OR_LINK,
entityBundle.getEntity(),
null,
null,
true
);
uploadDialogWidget.disableMultipleFileUploads();
uploadDialogWidget.setUploaderLinkNameVisible(false);
uploadDialogWidget.show();
}
}

private void onSubmit() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package org.sagebionetworks.web.client.widget.entity.download;

import com.google.gwt.event.shared.EventBus;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;
import org.sagebionetworks.web.client.GlobalApplicationState;
import org.sagebionetworks.web.client.GlobalApplicationStateImpl;
import org.sagebionetworks.web.client.context.SynapseReactClientFullContextPropsProvider;
import org.sagebionetworks.web.client.events.EntityUpdatedEvent;
import org.sagebionetworks.web.client.jsinterop.EntityUploadHandle;
import org.sagebionetworks.web.client.jsinterop.EntityUploadModalProps;
import org.sagebionetworks.web.client.jsinterop.React;
import org.sagebionetworks.web.client.jsinterop.ReactRef;
import org.sagebionetworks.web.client.jsinterop.SRC;
import org.sagebionetworks.web.client.widget.ReactComponent;

public class UploadDialogWidgetV2 extends Widget {

private final GlobalApplicationState globalApplicationState;
private final EventBus eventBus;
private final SynapseReactClientFullContextPropsProvider contextProvider;

private final ReactComponent reactComponent;

private String entityId;
private ReactRef<EntityUploadHandle> ref;

@Inject
public UploadDialogWidgetV2(
GlobalApplicationStateImpl globalApplicationState,
EventBus eventBus,
SynapseReactClientFullContextPropsProvider contextProvider
) {
this.globalApplicationState = globalApplicationState;
this.eventBus = eventBus;
this.contextProvider = contextProvider;

this.reactComponent = new ReactComponent();
}

public void configure(String entityId) {
this.entityId = entityId;
globalApplicationState.setDropZoneHandler(fileList ->
this.ref.current.handleUploads(fileList)
);

renderComponent(false);
}

private void renderComponent(boolean open) {
this.ref = React.createRef();
reactComponent.render(
React.createElementWithSynapseContext(
SRC.SynapseComponents.EntityUploadModal,
EntityUploadModalProps.create(entityId, open, this::onClose, this.ref),
contextProvider.getJsInteropContextProps()
)
);
}

public void show() {
renderComponent(true);
}

private void onClose() {
eventBus.fireEvent(new EntityUpdatedEvent(entityId));
renderComponent(false);
}

@Override
public Widget asWidget() {
return reactComponent.asWidget();
}

@Override
public void onUnload() {
globalApplicationState.clearDropZoneHandler();

super.onUnload();
}
}

0 comments on commit 2168d31

Please sign in to comment.