Skip to content

Commit

Permalink
Merge pull request #5447 from nickgros/SWC-6798
Browse files Browse the repository at this point in the history
  • Loading branch information
nickgros committed Jul 8, 2024
2 parents 76809d8 + 75ead07 commit af3e2c2
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import org.sagebionetworks.repo.model.download.MeetAccessRequirement;
import org.sagebionetworks.repo.model.download.RequestDownload;
import org.sagebionetworks.repo.model.entitybundle.v2.EntityBundle;
import org.sagebionetworks.repo.model.file.ExternalFileHandle;
import org.sagebionetworks.repo.model.file.FileHandle;
import org.sagebionetworks.repo.model.table.Dataset;
import org.sagebionetworks.repo.model.table.DatasetCollection;
Expand Down Expand Up @@ -800,9 +801,25 @@ public void onFailure(Throwable caught) {
);
}
}
actionMenu.setActionVisible(Action.DOWNLOAD_FILE, true);

actionMenu.setActionVisible(Action.ADD_TO_DOWNLOAD_CART, true);
boolean isExternalFileHandle =
entityBundle.getFileHandles() != null &&
!entityBundle.getFileHandles().isEmpty() &&
entityBundle.getFileHandles().get(0) instanceof ExternalFileHandle;

actionMenu.setActionVisible(Action.DOWNLOAD_FILE, !isExternalFileHandle);
actionMenu.setActionVisible(
Action.ADD_TO_DOWNLOAD_CART,
!isExternalFileHandle
);
actionMenu.setActionVisible(
Action.SHOW_PROGRAMMATIC_OPTIONS,
!isExternalFileHandle
);
actionMenu.setActionVisible(
Action.OPEN_EXTERNAL_FILE,
isExternalFileHandle
);
actionMenu.setActionListener(
Action.ADD_TO_DOWNLOAD_CART,
(action, e) -> {
Expand Down Expand Up @@ -843,7 +860,6 @@ public void onSuccess(
}
);

actionMenu.setActionVisible(Action.SHOW_PROGRAMMATIC_OPTIONS, true);
actionMenu.setActionListener(
Action.SHOW_PROGRAMMATIC_OPTIONS,
(action, e) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;
import java.util.Arrays;
import java.util.List;
import org.sagebionetworks.web.client.PortalGinInjector;
import org.sagebionetworks.web.client.jsinterop.ReactMouseEvent;
import org.sagebionetworks.web.client.jsinterop.ReactMouseEventHandler;
Expand Down Expand Up @@ -72,12 +74,18 @@ public void setIsUnauthenticatedS3DirectDownload() {
public void setIsDirectDownloadLink(String href) {
clearClickHandlers();
this.href = href;
actionMenu.setActionHref(Action.DOWNLOAD_FILE, href);
actionMenu.addActionListener(
List<Action> actionsToConfigure = Arrays.asList(
Action.DOWNLOAD_FILE,
(Action action, ReactMouseEvent event) ->
directDownloadClickHandler.onClick(event)
Action.OPEN_EXTERNAL_FILE
);
actionsToConfigure.forEach(action -> {
actionMenu.setActionHref(action, href);
actionMenu.addActionListener(
action,
(Action _action, ReactMouseEvent event) ->
directDownloadClickHandler.onClick(event)
);
});
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,5 @@ public enum Action {
ADD_TO_DOWNLOAD_CART,
SHOW_PROGRAMMATIC_OPTIONS,
PROJECT_HELP,
OPEN_EXTERNAL_FILE,
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ private static Map<Action, ActionConfiguration> createMap() {
"Add to Download Cart"
),
ActionConfiguration.create(Action.DOWNLOAD_FILE, "Download File"),
ActionConfiguration.create(Action.OPEN_EXTERNAL_FILE, "Open Link"),
ActionConfiguration.create(Action.REPORT_VIOLATION, "Report Violation")
);
Map<Action, ActionConfiguration> configurationMap = new EnumMap<>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,12 @@ public static EntityActionMenuLayout getLayout(EntityType entityType) {
);
layout.setDownloadMenuActions(
Arrays.asList(
Collections.singletonList(
ActionViewProps.create(Action.DOWNLOAD_FILE)
Arrays.asList(
ActionViewProps.create(Action.DOWNLOAD_FILE),
ActionViewProps.create(
Action.OPEN_EXTERNAL_FILE,
"openInNewWindow"
)
),
Arrays.asList(
ActionViewProps.create(Action.ADD_TO_DOWNLOAD_CART),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
import org.sagebionetworks.repo.model.download.MeetAccessRequirement;
import org.sagebionetworks.repo.model.download.RequestDownload;
import org.sagebionetworks.repo.model.entitybundle.v2.EntityBundle;
import org.sagebionetworks.repo.model.file.ExternalFileHandle;
import org.sagebionetworks.repo.model.file.FileHandle;
import org.sagebionetworks.repo.model.table.Dataset;
import org.sagebionetworks.repo.model.table.DatasetCollection;
Expand Down Expand Up @@ -5175,6 +5176,34 @@ public void testFileShowProgrammaticOptionsHandler() {
verify(mockFileClientsHelp).configureAndShow(entityId, 3L);
}

@Test
public void testConfigureExternalFileHandleDownload() {
ExternalFileHandle externalFileHandle = new ExternalFileHandle();
entityBundle.setFileHandles(Collections.singletonList(externalFileHandle));
entityBundle.setEntity(new FileEntity());

// Call under test
controller.configure(
mockActionMenu,
entityBundle,
true,
wikiPageId,
currentEntityArea,
mockAddToDownloadListWidget
);

verify(mockActionMenu).setDownloadMenuEnabled(true);
verify(mockActionMenu).setDownloadMenuTooltipText("");
verify(mockActionMenu).setActionVisible(Action.OPEN_EXTERNAL_FILE, true);
verify(mockActionMenu).setActionVisible(Action.DOWNLOAD_FILE, false);
verify(mockActionMenu).setActionVisible(Action.ADD_TO_DOWNLOAD_CART, false);
verify(mockActionMenu)
.setActionVisible(Action.SHOW_PROGRAMMATIC_OPTIONS, false);

verify(mockFileDownloadHandlerWidget)
.configure(mockActionMenu, entityBundle, mockRestrictionInformation);
}

@Test
public void testConfigureContainerDownload() {
EntityChildrenResponse fileChildrenResponse = new EntityChildrenResponse();
Expand Down

0 comments on commit af3e2c2

Please sign in to comment.