From c806d07d448aefc8fb990cde592d56d8cc1e44e5 Mon Sep 17 00:00:00 2001 From: Nick Grosenbacher Date: Fri, 26 Jul 2024 10:50:21 -0400 Subject: [PATCH] SWC-6943 - Use sessionStorage to store feature flag information --- .../web/client/FeatureFlagConfig.java | 5 +++-- .../web/client/FeatureFlagConfigProvider.java | 14 +++++++++++--- .../org/sagebionetworks/web/client/Portal.java | 6 +++--- .../web/client/PortalGinInjector.java | 3 +++ .../sagebionetworks/web/shared/WebConstants.java | 3 ++- 5 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/sagebionetworks/web/client/FeatureFlagConfig.java b/src/main/java/org/sagebionetworks/web/client/FeatureFlagConfig.java index fdbf3fcb33..20450c145c 100644 --- a/src/main/java/org/sagebionetworks/web/client/FeatureFlagConfig.java +++ b/src/main/java/org/sagebionetworks/web/client/FeatureFlagConfig.java @@ -3,12 +3,13 @@ import com.google.gwt.json.client.JSONObject; import com.google.gwt.json.client.JSONParser; import com.google.gwt.json.client.JSONValue; +import org.sagebionetworks.web.client.cache.SessionStorage; import org.sagebionetworks.web.client.cookie.CookieProvider; public class FeatureFlagConfig { - CookieProvider cookieProvider; - private JSONObject config; + private final CookieProvider cookieProvider; + private final JSONObject config; public FeatureFlagConfig(String json, CookieProvider cookieProvider) { JSONValue parsed = JSONParser.parseStrict(json); diff --git a/src/main/java/org/sagebionetworks/web/client/FeatureFlagConfigProvider.java b/src/main/java/org/sagebionetworks/web/client/FeatureFlagConfigProvider.java index 3aa0e9cd4c..c429f64065 100644 --- a/src/main/java/org/sagebionetworks/web/client/FeatureFlagConfigProvider.java +++ b/src/main/java/org/sagebionetworks/web/client/FeatureFlagConfigProvider.java @@ -2,22 +2,30 @@ import com.google.inject.Inject; import com.google.inject.Provider; +import org.sagebionetworks.web.client.cache.SessionStorage; import org.sagebionetworks.web.client.cookie.CookieProvider; import org.sagebionetworks.web.shared.WebConstants; public class FeatureFlagConfigProvider implements Provider { - CookieProvider cookieProvider; + private final CookieProvider cookieProvider; + private final SessionStorage sessionStorage; @Inject - public FeatureFlagConfigProvider(CookieProvider cookieProvider) { + public FeatureFlagConfigProvider( + CookieProvider cookieProvider, + SessionStorage sessionStorage + ) { this.cookieProvider = cookieProvider; + this.sessionStorage = sessionStorage; } @Override public FeatureFlagConfig get() { return new FeatureFlagConfig( - cookieProvider.getCookie(WebConstants.PORTAL_FEATURE_FLAG), + sessionStorage.getItem( + WebConstants.PORTAL_FEATURE_FLAG_SESSION_STORAGE_KEY + ), cookieProvider ); } diff --git a/src/main/java/org/sagebionetworks/web/client/Portal.java b/src/main/java/org/sagebionetworks/web/client/Portal.java index 4f477d8718..046fdf6ec8 100644 --- a/src/main/java/org/sagebionetworks/web/client/Portal.java +++ b/src/main/java/org/sagebionetworks/web/client/Portal.java @@ -89,9 +89,9 @@ public void onSuccess() { @Override public void onSuccess(JSONObjectAdapter config) { ginjector - .getCookieProvider() - .setCookie( - WebConstants.PORTAL_FEATURE_FLAG, + .getSessionStorage() + .setItem( + WebConstants.PORTAL_FEATURE_FLAG_SESSION_STORAGE_KEY, config.toString() ); } diff --git a/src/main/java/org/sagebionetworks/web/client/PortalGinInjector.java b/src/main/java/org/sagebionetworks/web/client/PortalGinInjector.java index 7771d99b62..b53bd9aca5 100644 --- a/src/main/java/org/sagebionetworks/web/client/PortalGinInjector.java +++ b/src/main/java/org/sagebionetworks/web/client/PortalGinInjector.java @@ -4,6 +4,7 @@ import com.google.gwt.inject.client.GinModules; import com.google.gwt.inject.client.Ginjector; import org.sagebionetworks.schema.adapter.JSONObjectAdapter; +import org.sagebionetworks.web.client.cache.SessionStorage; import org.sagebionetworks.web.client.context.QueryClientProvider; import org.sagebionetworks.web.client.cookie.CookieProvider; import org.sagebionetworks.web.client.presenter.ACTAccessApprovalsPresenter; @@ -585,6 +586,8 @@ public interface PortalGinInjector extends Ginjector { CookieProvider getCookieProvider(); + SessionStorage getSessionStorage(); + Header getHeader(); Footer getFooter(); diff --git a/src/main/java/org/sagebionetworks/web/shared/WebConstants.java b/src/main/java/org/sagebionetworks/web/shared/WebConstants.java index 347ddfa8ff..d8b533e040 100644 --- a/src/main/java/org/sagebionetworks/web/shared/WebConstants.java +++ b/src/main/java/org/sagebionetworks/web/shared/WebConstants.java @@ -411,7 +411,8 @@ public class WebConstants { "User requests that the Synapse Access and Compliance Team send them information on how to access this data."; public static final String ISSUE_PRIORITY_MINOR = "4"; public static final String ANONYMOUS = "Anonymous"; - public static final String PORTAL_FEATURE_FLAG = "portal_feature_flag"; + public static final String PORTAL_FEATURE_FLAG_SESSION_STORAGE_KEY = + "portal_feature_flag"; // report Synapse error public static final String SWC_ISSUE_COLLECTOR_URL =