-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
9 changed files
with
183 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
src/main/java/org/sagebionetworks/web/client/SynapseJsInteropUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/main/java/org/sagebionetworks/web/client/jsinterop/EntityUploadHandle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/org/sagebionetworks/web/client/jsinterop/EntityUploadModalProps.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
...main/java/org/sagebionetworks/web/client/widget/entity/download/UploadDialogWidgetV2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |