Skip to content

Commit

Permalink
Merge pull request #5403 from Sage-Bionetworks/release-500
Browse files Browse the repository at this point in the history
merge release 500 down to develop
  • Loading branch information
jay-hodgson authored May 31, 2024
2 parents 25afeaf + b1e512e commit a5bfa5f
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 39 deletions.
7 changes: 7 additions & 0 deletions src/main/java/org/sagebionetworks/web/client/Portal.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ public void onModuleLoad() {
if (initToken.length() > 0 && initToken.startsWith("!")) {
String fullUrl = Window.Location.getHref();
fullUrl = fullUrl.replace("#!", "");
// SWC-6854: Also detect a tables query in the hash fragment. If exist, move just the query to the hash fragment
if (
initToken.startsWith("!Synapse") && initToken.contains("/tables/query/")
) {
fullUrl = fullUrl.replace("/tables/query/", "/tables/#query/");
}

Window.Location.assign(fullUrl);
} else {
// This is a split point where the browser can download the first large code file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,8 @@ void showJiraIssueCollector(
long getLastModified(JavaScriptObject blob);

void setIsInnerProgrammaticHistoryChange();

String setHash(String hash);

String getHash();
}
Original file line number Diff line number Diff line change
Expand Up @@ -921,4 +921,22 @@ public static native void _showJiraIssueCollector(
console.error(err);
}
}-*/;

@Override
public String setHash(String hash) {
return _setHash(hash);
}

private static final native String _setHash(String hash) /*-{
$wnd.history.pushState('', '', hash)
}-*/;

@Override
public String getHash() {
return _getHash();
}

private static final native String _getHash() /*-{
return $wnd.location.hash
}-*/;
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.sagebionetworks.web.client.FeatureFlagConfig;
import org.sagebionetworks.web.client.FeatureFlagKey;
import org.sagebionetworks.web.client.PortalGinInjector;
import org.sagebionetworks.web.client.SynapseJSNIUtils;
import org.sagebionetworks.web.client.SynapseJavascriptClient;
import org.sagebionetworks.web.client.events.EntityUpdatedEvent;
import org.sagebionetworks.web.client.place.Synapse;
Expand Down Expand Up @@ -57,7 +58,7 @@
public abstract class AbstractTablesTab
implements TablesTabView.Presenter, QueryChangeHandler {

public static final String TABLE_QUERY_PREFIX = "query/";
public static final String TABLE_QUERY_PREFIX = "#query/";

private static final String VERSION_ALERT_DRAFT_DATASET_TITLE =
"This is a Draft Version of the Dataset";
Expand Down Expand Up @@ -99,6 +100,7 @@ public abstract class AbstractTablesTab
Long latestSnapshotVersionNumber;
SynapseJavascriptClient jsClient;
FeatureFlagConfig featureFlagConfig;
SynapseJSNIUtils jsniUtils;

protected abstract EntityArea getTabArea();

Expand All @@ -116,11 +118,13 @@ public abstract class AbstractTablesTab
public AbstractTablesTab(
Tab tab,
PortalGinInjector ginInjector,
FeatureFlagConfig featureFlagConfig
FeatureFlagConfig featureFlagConfig,
SynapseJSNIUtils jsniUtils
) {
this.tab = tab;
this.ginInjector = ginInjector;
this.featureFlagConfig = featureFlagConfig;
this.jsniUtils = jsniUtils;
}

public void configure(
Expand Down Expand Up @@ -255,19 +259,20 @@ public void onQueryChange(Query newQuery) {
Long versionNumber = QueryBundleUtils.getTableVersion(newQuery.getSql());
String synId = QueryBundleUtils.getTableIdFromSql(newQuery.getSql());
Query defaultQuery = tableEntityWidget.getDefaultQuery();
// SWC-6854: update query value in the hash
if (token != null && !newQuery.equals(defaultQuery)) {
areaToken = TABLE_QUERY_PREFIX + token;
} else {
areaToken = "";
jsniUtils.setHash(TABLE_QUERY_PREFIX + token);
}
updateVersionAndAreaToken(synId, versionNumber, areaToken);
tab.showTab(true);
}
}

public Query getQueryString() {
if (areaToken != null && areaToken.startsWith(TABLE_QUERY_PREFIX)) {
String token = areaToken.substring(TABLE_QUERY_PREFIX.length());
// SWC-6854:read query from hash, if present
String hash = jsniUtils.getHash();
if (hash != null && hash.startsWith(TABLE_QUERY_PREFIX)) {
String token = hash.substring(TABLE_QUERY_PREFIX.length());
return queryTokenProvider.tokenToQuery(token);
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.sagebionetworks.web.client.DisplayConstants;
import org.sagebionetworks.web.client.FeatureFlagConfig;
import org.sagebionetworks.web.client.PortalGinInjector;
import org.sagebionetworks.web.client.SynapseJSNIUtils;
import org.sagebionetworks.web.client.place.Synapse.EntityArea;
import org.sagebionetworks.web.shared.WebConstants;

Expand All @@ -33,9 +34,10 @@ public class DatasetsTab extends AbstractTablesTab {
public DatasetsTab(
Tab tab,
PortalGinInjector ginInjector,
FeatureFlagConfig featureFlagConfig
FeatureFlagConfig featureFlagConfig,
SynapseJSNIUtils jsniUtils
) {
super(tab, ginInjector, featureFlagConfig);
super(tab, ginInjector, featureFlagConfig, jsniUtils);
this.tab = tab;
this.ginInjector = ginInjector;
this.featureFlagConfig = featureFlagConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.sagebionetworks.web.client.DisplayConstants;
import org.sagebionetworks.web.client.FeatureFlagConfig;
import org.sagebionetworks.web.client.PortalGinInjector;
import org.sagebionetworks.web.client.SynapseJSNIUtils;
import org.sagebionetworks.web.client.place.Synapse.EntityArea;
import org.sagebionetworks.web.shared.WebConstants;

Expand All @@ -27,9 +28,10 @@ public class TablesTab extends AbstractTablesTab {
public TablesTab(
Tab tab,
PortalGinInjector ginInjector,
FeatureFlagConfig featureFlagConfig
FeatureFlagConfig featureFlagConfig,
SynapseJSNIUtils jsniUtils
) {
super(tab, ginInjector, featureFlagConfig);
super(tab, ginInjector, featureFlagConfig, jsniUtils);
this.tab = tab;
this.ginInjector = ginInjector;
this.featureFlagConfig = featureFlagConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.sagebionetworks.web.client.GlobalApplicationState;
import org.sagebionetworks.web.client.PlaceChanger;
import org.sagebionetworks.web.client.PortalGinInjector;
import org.sagebionetworks.web.client.SynapseJSNIUtils;
import org.sagebionetworks.web.client.SynapseJavascriptClient;
import org.sagebionetworks.web.client.cookie.CookieProvider;
import org.sagebionetworks.web.client.place.Synapse;
Expand Down Expand Up @@ -167,12 +168,18 @@ public class DatasetsTabTest {
@Mock
FeatureFlagConfig mockFeatureFlagConfig;

@Mock
SynapseJSNIUtils mockJsniUtils;

@Captor
ArgumentCaptor<Map<String, String>> mapCaptor;

@Captor
ArgumentCaptor<Place> placeCaptor;

@Captor
ArgumentCaptor<String> stringCaptor;

DatasetsTab tab;
Query query;

Expand Down Expand Up @@ -204,7 +211,12 @@ public void setUp() {
.thenReturn(mockPlaceChanger);

tab =
new DatasetsTab(mockTab, mockPortalGinInjector, mockFeatureFlagConfig);
new DatasetsTab(
mockTab,
mockPortalGinInjector,
mockFeatureFlagConfig,
mockJsniUtils
);
tab.setEntitySelectedCallback(mockEntitySelectedCallback);

when(mockProjectEntityBundle.getEntity()).thenReturn(mockProjectEntity);
Expand Down Expand Up @@ -390,7 +402,8 @@ public void testSetTableQueryWithNoToken() {

Synapse place = getNewPlace(datasetName);
assertEquals(EntityArea.DATASETS, place.getArea());
assertTrue(place.getAreaToken().isEmpty());
assertNull(place.getAreaToken());
verify(mockJsniUtils, never()).setHash(anyString());
}

@Test
Expand Down Expand Up @@ -426,8 +439,9 @@ public void testSetTableQueryChangeVersion() {
verify(mockPlaceChanger).goTo(placeCaptor.capture());
Synapse place = (Synapse) placeCaptor.getValue();
assertEquals(EntityArea.DATASETS, place.getArea());
assertTrue(place.getAreaToken().isEmpty());
assertNull(place.getAreaToken());
assertEquals(newVersion, place.getVersionNumber());
verify(mockJsniUtils, never()).setHash(anyString());
}

@Test
Expand All @@ -446,7 +460,8 @@ public void testSetTableQueryChangeTableId() {
verify(mockPlaceChanger).goTo(placeCaptor.capture());
Synapse place = (Synapse) placeCaptor.getValue();
assertEquals(EntityArea.DATASETS, place.getArea());
assertTrue(place.getAreaToken().isEmpty());
assertNull(place.getAreaToken());
verify(mockJsniUtils, never()).setHash(anyString());
assertNull(place.getVersionNumber());
assertEquals("syn837874873843", place.getEntityId());
}
Expand Down Expand Up @@ -474,35 +489,37 @@ public void testSetTableQueryWithToken() {

Synapse place = getNewPlace(datasetName);
assertEquals(EntityArea.DATASETS, place.getArea());
assertTrue(place.getAreaToken().contains(encodedToken));
verify(mockJsniUtils).setHash(stringCaptor.capture());
assertTrue(stringCaptor.getValue().contains(encodedToken));
}

@Test
public void testGetTableQuery() {
Long version = null;
tab.setProject(projectEntityId, mockProjectEntityBundle, null);

String queryAreaToken;
String queryToken = null;
when(mockJsniUtils.getHash()).thenReturn(queryToken);
Query query1 = null;
queryAreaToken = null;
tab.configure(mockDatasetBundle, version, queryAreaToken);
tab.configure(mockDatasetBundle, version, null);
query1 = tab.getQueryString();
assertNull(query1);

queryAreaToken = "something else";
tab.configure(mockDatasetBundle, version, queryAreaToken);
tab.configure(mockDatasetBundle, version, null);
query1 = tab.getQueryString();
assertNull(query1);
String token = "encoded query token";
queryAreaToken = "query/" + token;
queryToken = "#query/" + token;
when(mockJsniUtils.getHash()).thenReturn(queryToken);
when(mockQueryTokenProvider.tokenToQuery(anyString())).thenReturn(query);
tab.configure(mockDatasetBundle, version, queryAreaToken);
tab.configure(mockDatasetBundle, version, null);
query1 = tab.getQueryString();
assertEquals(query, query1);
query.setSql("SELECT 'query/' FROM syn123 LIMIT 1");
token = "encoded query token 2";
queryAreaToken = "query/" + token;
tab.configure(mockDatasetBundle, version, queryAreaToken);
queryToken = "#query/" + token;
when(mockJsniUtils.getHash()).thenReturn(queryToken);
tab.configure(mockDatasetBundle, version, null);
query1 = tab.getQueryString();
assertEquals(query, query1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import org.sagebionetworks.web.client.GlobalApplicationState;
import org.sagebionetworks.web.client.PlaceChanger;
import org.sagebionetworks.web.client.PortalGinInjector;
import org.sagebionetworks.web.client.SynapseJSNIUtils;
import org.sagebionetworks.web.client.SynapseJavascriptClient;
import org.sagebionetworks.web.client.cookie.CookieProvider;
import org.sagebionetworks.web.client.place.Synapse;
Expand Down Expand Up @@ -146,6 +147,9 @@ public class TablesTabTest {
@Captor
ArgumentCaptor<CallbackP> callbackPCaptor;

@Captor
ArgumentCaptor<String> stringCaptor;

@Mock
EntityHeader mockEntityHeader;

Expand All @@ -158,6 +162,9 @@ public class TablesTabTest {
@Mock
PlaceChanger mockPlaceChanger;

@Mock
SynapseJSNIUtils mockJsniUtils;

String projectEntityId = "syn666666";
String projectName = "a test project";
String tableEntityId = "syn22";
Expand All @@ -184,7 +191,13 @@ public class TablesTabTest {

@Before
public void setUp() {
tab = new TablesTab(mockTab, mockPortalGinInjector, mockFeatureFlagConfig);
tab =
new TablesTab(
mockTab,
mockPortalGinInjector,
mockFeatureFlagConfig,
mockJsniUtils
);
when(mockTab.getEntityActionMenu()).thenReturn(mockActionMenuWidget);
when(mockPortalGinInjector.getCookieProvider()).thenReturn(mockCookies);
when(mockPortalGinInjector.getTablesTabView()).thenReturn(mockView);
Expand Down Expand Up @@ -416,7 +429,8 @@ public void testSetTableQueryWithNoToken() {

Synapse place = getNewPlace(tableName);
assertEquals(EntityArea.TABLES, place.getArea());
assertTrue(place.getAreaToken().isEmpty());
verify(mockJsniUtils, never()).setHash(anyString());
assertNull(place.getAreaToken());
}

@Test
Expand Down Expand Up @@ -456,7 +470,8 @@ public void testSetTableQueryChangeVersion() {
verify(mockPlaceChanger).goTo(placeCaptor.capture());
Synapse place = (Synapse) placeCaptor.getValue();
assertEquals(EntityArea.TABLES, place.getArea());
assertTrue(place.getAreaToken().isEmpty());
verify(mockJsniUtils, never()).setHash(anyString());
assertNull(place.getAreaToken());
assertEquals(newVersion, place.getVersionNumber());
}

Expand All @@ -476,7 +491,8 @@ public void testSetTableQueryChangeTableId() {
verify(mockPlaceChanger).goTo(placeCaptor.capture());
Synapse place = (Synapse) placeCaptor.getValue();
assertEquals(EntityArea.TABLES, place.getArea());
assertTrue(place.getAreaToken().isEmpty());
verify(mockJsniUtils, never()).setHash(anyString());
assertNull(place.getAreaToken());
assertNull(place.getVersionNumber());
assertEquals("syn837874873843", place.getEntityId());
}
Expand Down Expand Up @@ -504,35 +520,36 @@ public void testSetTableQueryWithToken() {

Synapse place = getNewPlace(tableName);
assertEquals(EntityArea.TABLES, place.getArea());
assertTrue(place.getAreaToken().contains(encodedToken));
verify(mockJsniUtils).setHash(stringCaptor.capture());
assertTrue(stringCaptor.getValue().contains(encodedToken));
}

@Test
public void testGetTableQuery() {
Long version = null;
tab.setProject(projectEntityId, mockProjectEntityBundle, null);

String queryAreaToken;
Query query1 = null;
queryAreaToken = null;
tab.configure(mockTableEntityBundle, version, queryAreaToken);
String queryToken = null;
tab.configure(mockTableEntityBundle, version, null);
query1 = tab.getQueryString();
assertNull(query1);

queryAreaToken = "something else";
tab.configure(mockTableEntityBundle, version, queryAreaToken);
tab.configure(mockTableEntityBundle, version, null);
query1 = tab.getQueryString();
assertNull(query1);
String token = "encoded query token";
queryAreaToken = "query/" + token;
queryToken = "#query/" + token;
when(mockJsniUtils.getHash()).thenReturn(queryToken);
when(mockQueryTokenProvider.tokenToQuery(anyString())).thenReturn(query);
tab.configure(mockTableEntityBundle, version, queryAreaToken);
tab.configure(mockTableEntityBundle, version, null);
query1 = tab.getQueryString();
assertEquals(query, query1);
query.setSql("SELECT 'query/' FROM syn123 LIMIT 1");
token = "encoded query token 2";
queryAreaToken = "query/" + token;
tab.configure(mockTableEntityBundle, version, queryAreaToken);
queryToken = "#query/" + token;
when(mockJsniUtils.getHash()).thenReturn(queryToken);
tab.configure(mockTableEntityBundle, version, null);
query1 = tab.getQueryString();
assertEquals(query, query1);
}
Expand Down

0 comments on commit a5bfa5f

Please sign in to comment.