Skip to content

Commit

Permalink
Merge pull request #5502 from jay-hodgson/SWC-6763
Browse files Browse the repository at this point in the history
SWC-6763: integrate reworked SRC error page
  • Loading branch information
jay-hodgson committed Aug 28, 2024
2 parents 932d692 + 21fa165 commit e6d3c1e
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 58 deletions.
Original file line number Diff line number Diff line change
@@ -1,26 +1,40 @@
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 ErrorPageProps extends ReactComponentProps {

String image;
String title;
String type;
String message;
String entityId;
Double entityVersionNumber;

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

public Callback gotoPlace;

@JsOverlay
public static ErrorPageProps create(
String image,
String title,
String message
String type,
String message,
String entityId,
Long entityVersion,
Callback gotoPlace
) {
ErrorPageProps props = new ErrorPageProps();
props.image = image;
props.title = title;
props.type = type;
props.message = message;
props.entityId = entityId;
props.entityVersionNumber =
entityVersion != null ? entityVersion.doubleValue() : null;
props.gotoPlace = gotoPlace;
return props;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ public void onError(Throwable caught) {

public void show403() {
if (entityId != null) {
synAlert.show403(entityId);
synAlert.show403(entityId, versionNumber);
}
view.setLoadingVisible(false);
view.setEntityPageTopVisible(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;
import org.sagebionetworks.web.client.GlobalApplicationState;
import org.sagebionetworks.web.client.PlaceChanger;
import org.sagebionetworks.web.client.context.SynapseReactClientFullContextPropsProvider;
import org.sagebionetworks.web.client.jsinterop.ErrorPageProps;
import org.sagebionetworks.web.client.jsinterop.React;
Expand All @@ -25,20 +27,22 @@ public class DownViewImpl implements DownView {
String message;

public static enum ErrorPageType {
maintenance,
noAccess,
unavailable,
DOWN,
ACCESS_DENIED,
NOT_FOUND,
}

public interface Binder extends UiBinder<Widget, DownViewImpl> {}

GlobalApplicationState globalAppState;
Widget widget;

@Inject
public DownViewImpl(
Binder uiBinder,
Header headerWidget,
final SynapseReactClientFullContextPropsProvider propsProvider
final SynapseReactClientFullContextPropsProvider propsProvider,
GlobalApplicationState globalAppState
) {
widget = uiBinder.createAndBindUi(this);
this.headerWidget = headerWidget;
Expand All @@ -49,6 +53,7 @@ public DownViewImpl(
renderMaintenancePage();
}
});
this.globalAppState = globalAppState;
}

@Override
Expand Down Expand Up @@ -77,9 +82,13 @@ public boolean isAttached() {

public void renderMaintenancePage() {
ErrorPageProps props = ErrorPageProps.create(
ErrorPageType.maintenance.name(),
SYNAPSE_DOWN_MAINTENANCE_TITLE,
message
ErrorPageType.DOWN.name(),
message,
null, //entity ID
null, //entity version
href -> {
globalAppState.handleRelativePathClick(href);
}
);
ReactNode component = React.createElementWithSynapseContext(
SRC.SynapseComponents.ErrorPage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class StuAlert {

StuAlertView view;
String entityId;
Long entityVersion;
SynapseAlert synAlert;
GWTWrapper gwt;
AuthenticationController authController;
Expand All @@ -37,24 +38,29 @@ public void clear() {
synAlert.clear();
view.clearState();
entityId = null;
entityVersion = null;
}

public void show403() {
clear();
view.show403();
show403(null, null);
}

public void show403(String entityId) {
show403();
public void show403(String entityId, Long entityVersion) {
clear();
this.entityId = entityId;
if (!authController.isLoggedIn()) {
synAlert.showLogin();
}
this.entityVersion = entityVersion;
view.show403(entityId, entityVersion, authController.isLoggedIn());
}

public void show404() {
show404(null, null);
}

public void show404(String entityId, Long entityVersion) {
clear();
view.show404();
this.entityId = entityId;
this.entityVersion = entityVersion;
view.show404(entityId, entityVersion, authController.isLoggedIn());
}

public String getEntityId() {
Expand All @@ -65,13 +71,9 @@ public void handleException(Throwable ex) {
clear();
// if it's something that Stu recognizes, then he should handle it.
if (ex instanceof ForbiddenException) {
if (!authController.isLoggedIn()) {
synAlert.showLogin();
} else {
view.show403();
}
view.show403(null, null, authController.isLoggedIn());
} else if (ex instanceof NotFoundException) {
view.show404();
view.show404(null, null, authController.isLoggedIn());
} else {
synAlert.handleException(ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ public interface StuAlertView extends IsWidget {
*/
void clearState();

void show403();
void show403(String entityId, Long entityVersion, boolean isLoggedIn);

void show404();
void show404(String entityId, Long entityVersion, boolean isLoggedIn);

void setSynAlert(Widget w);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.google.inject.Inject;
import org.gwtbootstrap3.client.ui.html.Div;
import org.sagebionetworks.web.client.DisplayUtils;
import org.sagebionetworks.web.client.GlobalApplicationState;
import org.sagebionetworks.web.client.context.SynapseReactClientFullContextPropsProvider;
import org.sagebionetworks.web.client.jsinterop.ErrorPageProps;
import org.sagebionetworks.web.client.jsinterop.React;
Expand All @@ -31,12 +32,18 @@ public interface Binder extends UiBinder<Widget, StuAlertViewImpl> {}
Widget synAlertWidget;
Div container = new Div();
boolean is404, is403;
String entityId;
Long entityVersion;
boolean isLoggedIn;
GlobalApplicationState globalAppState;

@Inject
public StuAlertViewImpl(
SynapseReactClientFullContextPropsProvider propsProvider
SynapseReactClientFullContextPropsProvider propsProvider,
GlobalApplicationState globalAppState
) {
this.propsProvider = propsProvider;
this.globalAppState = globalAppState;
}

@Override
Expand All @@ -53,6 +60,8 @@ public Widget asWidget() {
public void clearState() {
container.setVisible(false);
if (widget != null) {
entityId = null;
entityVersion = null;
is404 = false;
is403 = false;
errorPageContainer.setVisible(false);
Expand All @@ -73,12 +82,16 @@ private void lazyConstruct() {
}
}

private void renderErrorPage(
ErrorPageType type,
String title,
String message
) {
ErrorPageProps props = ErrorPageProps.create(type.name(), title, message);
private void renderErrorPage(ErrorPageType type) {
ErrorPageProps props = ErrorPageProps.create(
type.name(),
null, //custom message
entityId,
entityVersion,
href -> {
globalAppState.handleRelativePathClick(href);
}
);
ReactNode component = React.createElementWithSynapseContext(
SRC.SynapseComponents.ErrorPage,
props,
Expand All @@ -90,32 +103,30 @@ private void renderErrorPage(

private void updateErrorPage() {
if (is404) {
renderErrorPage(
ErrorPageType.unavailable,
"Sorry, this page isn’t available.",
"The link you followed may be broken, or the page may have been removed."
);
renderErrorPage(ErrorPageType.NOT_FOUND);
}
if (is403) {
renderErrorPage(
ErrorPageType.noAccess,
"Sorry, no access to this page.",
"You are not authorized to access the page requested."
);
renderErrorPage(ErrorPageType.ACCESS_DENIED);
}
}

@Override
public void show403() {
public void show403(String entityId, Long entityVersion, boolean isLoggedIn) {
is403 = true;
this.isLoggedIn = isLoggedIn;
this.entityId = entityId;
this.entityVersion = entityVersion;
lazyConstruct();
container.setVisible(true);
updateErrorPage();
}

@Override
public void show404() {
public void show404(String entityId, Long entityVersion, boolean isLoggedIn) {
is404 = true;
this.isLoggedIn = isLoggedIn;
this.entityId = entityId;
this.entityVersion = entityVersion;
lazyConstruct();
container.setVisible(true);
updateErrorPage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui"
xmlns:b="urn:import:org.gwtbootstrap3.client.ui"
xmlns:a="urn:import:org.sagebionetworks.web.client.widget.entity.menu.v2"
xmlns:bg="urn:import:org.gwtbootstrap3.client.ui.gwt"
xmlns:bh="urn:import:org.gwtbootstrap3.client.ui.html"
xmlns:t="urn:import:org.sagebionetworks.web.client.view.bootstrap.table"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<ui:UiBinder
xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:b="urn:import:org.gwtbootstrap3.client.ui"
xmlns:MUI="urn:import:org.sagebionetworks.web.client.jsinterop.mui"
xmlns:bh="urn:import:org.gwtbootstrap3.client.ui.html"
xmlns:g="urn:import:com.google.gwt.user.client.ui"
xmlns:w="urn:import:org.sagebionetworks.web.client.widget"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
xmlns:g="urn:import:com.google.gwt.user.client.ui"
xmlns:c="urn:import:com.google.gwt.user.cellview.client"
xmlns:b="urn:import:org.gwtbootstrap3.client.ui"
xmlns:MUI="urn:import:org.sagebionetworks.web.client.jsinterop.mui"
xmlns:a="urn:import:org.sagebionetworks.web.client.widget.table.v2"
xmlns:bg="urn:import:org.gwtbootstrap3.client.ui.gwt"
xmlns:bh="urn:import:org.gwtbootstrap3.client.ui.html"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ public void testClear() {
public void testShow403() {
entityPresenter.setEntityId("123");
entityPresenter.show403();
verify(mockSynAlert).show403(anyString());
verify(mockSynAlert).show403(anyString(), anyLong());
verify(mockView).setEntityPageTopVisible(false);
verify(mockView).setOpenTeamInvitesVisible(true);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package org.sagebionetworks.web.unitclient.widget.entity.controller;

import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.anyLong;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -69,7 +72,7 @@ public void testHandleServiceExceptionForbiddenLoggedIn() {
widget.handleException(new ForbiddenException());
verify(mockSynapseAlert).clear();
verify(mockView).clearState();
verify(mockView).show403();
verify(mockView).show403(anyString(), anyLong(), eq(true));
verify(mockView).setVisible(true);
}

Expand All @@ -78,15 +81,15 @@ public void testHandleServiceExceptionForbiddenNotLoggedIn() {
when(mockAuthenticationController.isLoggedIn()).thenReturn(false);
widget.handleException(new ForbiddenException());
verify(mockView).clearState();
verify(mockSynapseAlert).showLogin();
verify(mockView).show403(anyString(), anyLong(), eq(false));
verify(mockView).setVisible(true);
}

@Test
public void testHandleServiceExceptionNotFound() {
widget.handleException(new NotFoundException());
verify(mockView).clearState();
verify(mockView).show404();
verify(mockView).show404(anyString(), anyLong(), eq(true));
verify(mockView).setVisible(true);
}

Expand Down Expand Up @@ -126,7 +129,9 @@ public void testShowError() {
@Test
public void testShowEntity403() {
String entityId = "syn123";
widget.show403(entityId);
Long entityVersion = 4L;
widget.show403(entityId, entityVersion);
verify(mockView).show403(entityId, entityVersion, true);
verify(mockView).clearState();
assertEquals(entityId, widget.getEntityId());
}
Expand Down

0 comments on commit e6d3c1e

Please sign in to comment.