Skip to content

Commit

Permalink
Merge pull request #5451 from jay-hodgson/SWC-6930
Browse files Browse the repository at this point in the history
SWC-6930: replace synapse footer and homepage
  • Loading branch information
jay-hodgson authored Jul 25, 2024
2 parents fb41d8b + 7c6e869 commit 9b693ca
Show file tree
Hide file tree
Showing 13 changed files with 204 additions and 462 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"react-transition-group": "2.6.0",
"sass": "^1.63.6",
"spark-md5": "^3.0.2",
"synapse-react-client": "3.3.3",
"synapse-react-client": "3.3.4",
"universal-cookie": "^4.0.4",
"xss": "^1.0.15"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public static class SynapseComponents {
public static ReactComponentType<EmptyProps> OAuthManagement;
public static ReactComponentType TrashCanList;
public static ReactComponentType<SynapseHomepageProps> SynapseHomepage;
public static ReactComponentType<SynapseHomepageV2Props> SynapseHomepageV2;
public static ReactComponentType<SynapseFooterProps> SynapseFooter;
public static ReactComponentType<ErrorPageProps> ErrorPage;
public static ReactComponentType<LoginPageProps> LoginPage;
public static ReactComponentType<HasAccessProps> HasAccess;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
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 SynapseFooterProps extends ReactComponentProps {

String portalVersion;
String srcVersion;
String repoVersion;

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

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

public Callback reportViolationCallback;
public Callback2 gotoPlace;

@JsOverlay
public static SynapseFooterProps create(
String portalVersion,
String srcVersion,
String repoVersion,
Callback reportViolationCallback,
Callback2 gotoPlace
) {
SynapseFooterProps props = new SynapseFooterProps();
props.portalVersion = portalVersion;
props.srcVersion = srcVersion;
props.repoVersion = repoVersion;
props.reportViolationCallback = reportViolationCallback;
props.gotoPlace = gotoPlace;
return props;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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 SynapseHomepageV2Props extends ReactComponentProps {

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

public Callback gotoPlace;

@JsOverlay
public static SynapseHomepageV2Props create(Callback gotoPlace) {
SynapseHomepageV2Props props = new SynapseHomepageV2Props();
props.gotoPlace = gotoPlace;
return props;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,28 @@
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.user.client.ui.AcceptsOneWidget;
import com.google.inject.Inject;
import org.sagebionetworks.web.client.GlobalApplicationState;
import org.sagebionetworks.web.client.place.Home;
import org.sagebionetworks.web.client.place.Profile;
import org.sagebionetworks.web.client.security.AuthenticationController;
import org.sagebionetworks.web.client.view.HomeView;

public class HomePresenter extends AbstractActivity implements Presenter<Home> {

private Home place;
private HomeView view;
private AuthenticationController authController;
private GlobalApplicationState globalAppState;

@Inject
public HomePresenter(HomeView view) {
public HomePresenter(
HomeView view,
AuthenticationController authController,
GlobalApplicationState globalAppState
) {
this.view = view;
this.authController = authController;
this.globalAppState = globalAppState;
view.scrollToTop();
}

Expand All @@ -29,5 +40,10 @@ public void start(AcceptsOneWidget panel, EventBus eventBus) {
public void setPlace(Home place) {
this.place = place;
view.refresh();
if (authController.isLoggedIn()) {
globalAppState
.getPlaceChanger()
.goTo(new Profile(Profile.VIEW_PROFILE_TOKEN + "/projects/all"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,8 @@ public void onSuccess(Void result) {

private void afterCall() {
resetQueryClientCache();
ginInjector.getFooter().refresh();
ginInjector.getHeader().refresh();
ginInjector.getGlobalApplicationState().refreshPage();
}
}
Expand Down Expand Up @@ -432,6 +434,9 @@ public void onFailure(Throwable caught) {
@Override
public void onSuccess(UserProfile result) {
// is this a user session change? if so, refresh the page.
ginInjector.getFooter().refresh();
ginInjector.getHeader().refresh();

if (!Objects.equals(currentUserAccessToken, oldUserAccessToken)) {
// we've reinitialized the app with the correct session, refresh the page (do not get rid of js state)!
if (webAppInitializationCallback != null) {
Expand All @@ -441,7 +446,6 @@ public void onSuccess(UserProfile result) {
}
checkForQuarantinedEmail();
} else {
ginInjector.getHeader().refresh();
// we've determined that the session has not changed
if (webAppInitializationCallback != null) {
webAppInitializationCallback.invoke();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;
import org.sagebionetworks.web.client.GlobalApplicationState;
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.SRC;
import org.sagebionetworks.web.client.jsinterop.SynapseHomepageProps;
import org.sagebionetworks.web.client.jsinterop.SynapseHomepageV2Props;
import org.sagebionetworks.web.client.widget.ReactComponent;
import org.sagebionetworks.web.client.widget.header.Header;

Expand All @@ -22,31 +23,34 @@ public interface HomeViewImplUiBinder
@UiField
ReactComponent container;

private static final String PROJECT_VIEW_ID = "syn23593547.3";

private Header headerWidget;
private SynapseReactClientFullContextPropsProvider propsProvider;
private GlobalApplicationState globalAppState;

@Inject
public HomeViewImpl(
HomeViewImplUiBinder binder,
Header headerWidget,
final SynapseReactClientFullContextPropsProvider propsProvider
final SynapseReactClientFullContextPropsProvider propsProvider,
GlobalApplicationState globalAppState
) {
initWidget(binder.createAndBindUi(this));

this.headerWidget = headerWidget;
this.propsProvider = propsProvider;
this.globalAppState = globalAppState;

headerWidget.configure();
}

@Override
public void render() {
scrollToTop();
SynapseHomepageProps props = SynapseHomepageProps.create(PROJECT_VIEW_ID);
SynapseHomepageV2Props props = SynapseHomepageV2Props.create(href -> {
globalAppState.handleRelativePathClick(href);
});
ReactNode component = React.createElementWithSynapseContext(
SRC.SynapseComponents.SynapseHomepage,
SRC.SynapseComponents.SynapseHomepageV2,
props,
propsProvider.getJsInteropContextProps()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ public Widget asWidget() {
return view.asWidget();
}

public void refresh() {
view.refresh();
}

@Override
public void onReportAbuseClicked() {
// report abuse via Jira issue collector
Expand Down
Loading

0 comments on commit 9b693ca

Please sign in to comment.