Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SWC-6616: example of utilizing the new SRC redirect dialog in SWC #5232

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 43 additions & 4 deletions src/main/java/org/sagebionetworks/web/client/Portal.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.RunAsyncCallback;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.place.shared.PlaceController;
import com.google.gwt.place.shared.PlaceHistoryHandler;
Expand All @@ -12,9 +14,15 @@
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.SimplePanel;
import org.sagebionetworks.web.client.context.SynapseReactClientFullContextPropsProvider;
import org.sagebionetworks.web.client.jsinterop.React;
import org.sagebionetworks.web.client.jsinterop.ReactNode;
import org.sagebionetworks.web.client.jsinterop.RedirectDialogProps;
import org.sagebionetworks.web.client.jsinterop.SRC;
import org.sagebionetworks.web.client.mvp.AppActivityMapper;
import org.sagebionetworks.web.client.mvp.AppPlaceHistoryMapper;
import org.sagebionetworks.web.client.utils.Callback;
import org.sagebionetworks.web.client.widget.ReactComponentDiv;
import org.sagebionetworks.web.client.widget.footer.Footer;
import org.sagebionetworks.web.client.widget.header.Header;

Expand Down Expand Up @@ -98,9 +106,8 @@ public void onSuccess() {
AppPlaceHistoryMapper historyMapper = GWT.create(
AppPlaceHistoryMapper.class
);
final PlaceHistoryHandler historyHandler = new PlaceHistoryHandler(
historyMapper
);
final PlaceHistoryHandler historyHandler =
new PlaceHistoryHandler(historyMapper);
historyHandler.register(
placeController,
eventBus,
Expand All @@ -117,7 +124,8 @@ public void onSuccess() {
RootPanel.get("headerPanel"),
RootPanel.get("rootPanel")
);
final GlobalApplicationState globalApplicationState = ginjector.getGlobalApplicationState();
final GlobalApplicationState globalApplicationState =
ginjector.getGlobalApplicationState();
globalApplicationState.setPlaceController(placeController);
globalApplicationState.setAppPlaceHistoryMapper(
historyMapper
Expand Down Expand Up @@ -153,6 +161,11 @@ public void invoke() {
// start a timer to check to see if we're approaching the max allowable space in the web storage.
// clears out the web storage (cache) if this is the case.
ginjector.getWebStorageMaxSizeDetector().start();

//initialize a click handler that listens for events that take the user outside of synapse.org
addRedirectHandler(
ginjector.getSynapseReactClientFullContextPropsProvider()
);
}
}
);
Expand Down Expand Up @@ -224,4 +237,30 @@ private void registerOnPopStateHandler(
) {
globalApplicationState.initOnPopStateHandler();
}

public void addRedirectHandler(
SynapseReactClientFullContextPropsProvider propsProvider
) {
ClickHandler CLICK_HANDLER = event -> {
String targetUrl = event.getNativeEvent().getEventTarget().toString();
if (
targetUrl.startsWith("http") &&
!targetUrl.contains(Window.Location.getHostName())
) {
event.preventDefault();
ReactComponentDiv redirectDialogContainer = new ReactComponentDiv();
RootPanel.get().add(redirectDialogContainer);
ReactNode node = React.createElementWithSynapseContext(
SRC.SynapseComponents.RedirectDialog,
RedirectDialogProps.create(
targetUrl,
"You are currently being redirected to a site outside of Synapse"
),
propsProvider.getJsInteropContextProps()
);
redirectDialogContainer.render(node);
}
};
RootPanel.get().addDomHandler(CLICK_HANDLER, ClickEvent.getType());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.google.gwt.inject.client.Ginjector;
import org.sagebionetworks.schema.adapter.JSONObjectAdapter;
import org.sagebionetworks.web.client.context.QueryClientProvider;
import org.sagebionetworks.web.client.context.SynapseReactClientFullContextPropsProvider;
import org.sagebionetworks.web.client.cookie.CookieProvider;
import org.sagebionetworks.web.client.presenter.ACTAccessApprovalsPresenter;
import org.sagebionetworks.web.client.presenter.ACTDataAccessSubmissionDashboardPresenter;
Expand Down Expand Up @@ -887,4 +888,5 @@ public interface PortalGinInjector extends Ginjector {

ColumnModelsEditorV2Widget getColumnModelsEditorV2Widget();
ColumnModelsEditorV2WidgetView getColumnModelsEditorV2WidgetView();
SynapseReactClientFullContextPropsProvider getSynapseReactClientFullContextPropsProvider();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.sagebionetworks.web.client.jsinterop;

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

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

String redirectUrl;
String redirectInstructions;

@JsOverlay
public static RedirectDialogProps create(
String redirectUrl,
String redirectInstructions
) {
RedirectDialogProps props = new RedirectDialogProps();
props.redirectUrl = redirectUrl;
props.redirectInstructions = redirectInstructions;
return props;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public static class SynapseComponents {
public static ReactComponentType<EmptyProps> SubscriptionPage;
public static ReactComponentType<AccessRequirementListProps> AccessRequirementList;
public static ReactComponentType<TableColumnSchemaFormProps> TableColumnSchemaForm;
public static ReactComponentType<RedirectDialogProps> RedirectDialog;

/**
* Pushes a global toast message. In SWC, you should use {@link DisplayUtils#notify}, rather than calling this method directly.
Expand Down