Skip to content

Commit

Permalink
Merge pull request #5398 from jay-hodgson/SWC-6829
Browse files Browse the repository at this point in the history
  • Loading branch information
jay-hodgson authored May 31, 2024
2 parents 0f40248 + 23194b0 commit 25afeaf
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ public class DisplayConstants {
"Link successfully updated in Synapse";
public static final String TEXT_LINK_FAILED =
"An error occurred while creating the link. ";
public static final String TEXT_UPLOAD_MULTIPLE_FILES_SUCCESS =
"Files successfully uploaded";
public static final String TEXT_UPLOAD_SUCCESS = "File successfully uploaded";
public static final String ERROR_UPLOAD_TITLE = "Upload Error";
public static final String ERROR_SFTP_DOWNLOAD_TITLE = "SFTP Download Error";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
import com.google.inject.Inject;
import org.sagebionetworks.repo.model.Entity;
import org.sagebionetworks.repo.model.Folder;
import org.sagebionetworks.web.client.DisplayUtils;
import org.sagebionetworks.web.client.GlobalApplicationState;
import org.sagebionetworks.web.client.PopupUtilsView;
import org.sagebionetworks.web.client.SynapseJavascriptClient;
import org.sagebionetworks.web.client.jsinterop.ToastMessageOptions;
import org.sagebionetworks.web.client.place.Synapse;
import org.sagebionetworks.web.client.widget.SynapseWidgetPresenter;
import org.sagebionetworks.web.client.widget.entity.SharingAndDataUseConditionWidget;
import org.sagebionetworks.web.client.widget.entity.controller.SynapseAlert;
Expand Down Expand Up @@ -70,7 +73,21 @@ public void createFolder(String newFolderName) {
@Override
public void onSuccess(Entity result) {
view.hide();
popupUtils.showInfo("Folder '" + newFolderName + "' Added");
String message = "Folder '" + newFolderName + "' Added";
ToastMessageOptions toastOptions = new ToastMessageOptions.Builder()
.setPrimaryButton(
"View Folder",
() ->
globalAppState
.getPlaceChanger()
.goTo(new Synapse(result.getId()))
)
.build();
popupUtils.notify(
message,
DisplayUtils.NotificationVariant.INFO,
toastOptions
);
globalAppState.refreshPage();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,6 @@ private void processNextFile() {

private void postUpload() {
if (currIndex + 1 == fileNames.length) {
// to new file handle id, or create new file entity with this file handle id
view.hideLoading();
refreshAfterSuccessfulUpload(entityId);
} else {
Expand All @@ -714,6 +713,7 @@ public void setFileEntityFileHandle(String fileHandleId) {
if (fileHandleId == null) {
postUpload();
} else if (entityId != null || currentFileParentEntityId != null) {
// to new file handle id, or create new file entity with this file handle id
synapseClient.setFileEntityFileHandle(
fileHandleId,
entityId,
Expand All @@ -722,6 +722,7 @@ public void setFileEntityFileHandle(String fileHandleId) {
@Override
public void onSuccess(String entityId) {
fileHasBeenUploaded = true;
Uploader.this.entityId = entityId;
postUpload();
}

Expand Down Expand Up @@ -998,7 +999,12 @@ private void fireCancelEvent() {
}

private void uploadSuccess() {
view.showInfo(DisplayConstants.TEXT_UPLOAD_SUCCESS);
int fileCount = fileNames.length;
if (fileCount == 1) {
view.showSingleFileUploaded(entityId);
} else {
view.showInfo(DisplayConstants.TEXT_UPLOAD_MULTIPLE_FILES_SUCCESS);
}
view.clear();
view.resetToInitialState();
resetUploadProgress();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.gwt.event.logical.shared.HasAttachHandlers;
import com.google.gwt.user.client.ui.IsWidget;
import org.sagebionetworks.repo.model.Entity;
import org.sagebionetworks.web.client.SynapseView;
import org.sagebionetworks.web.client.utils.Callback;

Expand Down Expand Up @@ -100,4 +101,5 @@ public interface Presenter {
}

void disableSelectionDuringUpload();
void showSingleFileUploaded(String entityId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,19 @@
import org.gwtbootstrap3.client.ui.html.Div;
import org.gwtbootstrap3.client.ui.html.Italic;
import org.gwtbootstrap3.client.ui.html.Span;
import org.sagebionetworks.repo.model.Entity;
import org.sagebionetworks.web.client.DisplayConstants;
import org.sagebionetworks.web.client.DisplayUtils;
import org.sagebionetworks.web.client.EventHandlerUtils;
import org.sagebionetworks.web.client.PortalGinInjector;
import org.sagebionetworks.web.client.SageImageBundle;
import org.sagebionetworks.web.client.SynapseJSNIUtils;
import org.sagebionetworks.web.client.jsinterop.ToastMessageOptions;
import org.sagebionetworks.web.client.place.Synapse;
import org.sagebionetworks.web.client.utils.Callback;
import org.sagebionetworks.web.client.utils.JavaScriptCallback;
import org.sagebionetworks.web.client.widget.entity.SharingAndDataUseConditionWidget;
import org.sagebionetworks.web.client.widget.entity.menu.v3.Action;

/**
* Note on the form submission. This supports two form submission use cases. 1. Submit to Portal
Expand Down Expand Up @@ -350,6 +354,25 @@ public void showInfo(String message) {
DisplayUtils.showInfo(message);
}

@Override
public void showSingleFileUploaded(String entityId) {
ToastMessageOptions toastOptions = new ToastMessageOptions.Builder()
.setPrimaryButton(
"View File",
() ->
ginInjector
.getGlobalApplicationState()
.getPlaceChanger()
.goTo(new Synapse(entityId))
)
.build();
DisplayUtils.notify(
DisplayConstants.TEXT_UPLOAD_SUCCESS,
DisplayUtils.NotificationVariant.INFO,
toastOptions
);
}

@Override
public void clear() {
super.clear();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.sagebionetworks.web.unitclient.widget.entity.download;

import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
Expand All @@ -13,10 +14,12 @@
import org.mockito.MockitoAnnotations;
import org.sagebionetworks.repo.model.Entity;
import org.sagebionetworks.repo.model.Folder;
import org.sagebionetworks.web.client.DisplayUtils;
import org.sagebionetworks.web.client.GlobalApplicationState;
import org.sagebionetworks.web.client.PopupUtilsView;
import org.sagebionetworks.web.client.SynapseClientAsync;
import org.sagebionetworks.web.client.SynapseJavascriptClient;
import org.sagebionetworks.web.client.jsinterop.ToastMessageOptions;
import org.sagebionetworks.web.client.widget.entity.SharingAndDataUseConditionWidget;
import org.sagebionetworks.web.client.widget.entity.controller.SynapseAlert;
import org.sagebionetworks.web.client.widget.entity.download.AddFolderDialogWidget;
Expand Down Expand Up @@ -99,6 +102,12 @@ public void testShow() {
verify(mockSynapseJavascriptClient)
.createEntity(any(Folder.class), any(AsyncCallback.class));
verify(mockView).hide();
verify(mockPopupUtils)
.notify(
anyString(),
any(DisplayUtils.NotificationVariant.class),
any(ToastMessageOptions.class)
);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,8 @@ public void testDirectUploadHappyCase() throws Exception {
verify(mockView).hideLoading();
assertEquals(UploadType.S3, uploader.getCurrentUploadType());
// verify upload success
verify(mockView).showInfo(DisplayConstants.TEXT_UPLOAD_SUCCESS);

verify(mockView).showSingleFileUploaded("entityID");
verify(mockView).clear();
verify(mockView, times(2)).resetToInitialState();
verify(mockUploadSuccessHandler).onSuccessfulUpload();
Expand Down Expand Up @@ -695,6 +696,10 @@ public void testMultipleFileUploads() throws Exception {
)
)
.thenReturn(fileNames);
AsyncMockStubber
.callSuccessWith(testEntity)
.when(mockSynapseJavascriptClient)
.getEntity(anyString(), any(OBJECT_TYPE.class), any(AsyncCallback.class));

uploader.handleUploads();

Expand All @@ -720,6 +725,9 @@ public void testMultipleFileUploads() throws Exception {
eq(parentEntityId),
any(AsyncCallback.class)
);

verify(mockView)
.showInfo(DisplayConstants.TEXT_UPLOAD_MULTIPLE_FILES_SUCCESS);
}

@Test
Expand Down

0 comments on commit 25afeaf

Please sign in to comment.