Skip to content

Commit

Permalink
Merge pull request #5604 from jay-hodgson/SWC-7203
Browse files Browse the repository at this point in the history
SWC-7203: change to a project search query object
  • Loading branch information
jay-hodgson authored Dec 10, 2024
2 parents c225240 + dd32d0f commit 0f07fa5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ private SearchQuery checkForJson(String queryString) {
SearchQuery query = getBaseSearchQuery();

query.setQueryTerm(
Arrays.asList(queryString.replace("%20", " ").split(" "))
Arrays.asList(queryString.replace("%20", " ").split("\\s+"))
);

// if query parses into SearchQuery, use that, otherwise use it as a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;
import java.util.Arrays;
import java.util.Collections;
import org.gwtbootstrap3.client.ui.Alert;
import org.gwtbootstrap3.client.ui.AnchorListItem;
import org.gwtbootstrap3.client.ui.Button;
Expand All @@ -29,6 +31,11 @@
import org.sagebionetworks.repo.model.Team;
import org.sagebionetworks.repo.model.UserProfile;
import org.sagebionetworks.repo.model.entity.query.SortDirection;
import org.sagebionetworks.repo.model.search.query.KeyValue;
import org.sagebionetworks.repo.model.search.query.SearchQuery;
import org.sagebionetworks.schema.adapter.JSONObjectAdapter;
import org.sagebionetworks.schema.adapter.JSONObjectAdapterException;
import org.sagebionetworks.web.client.DisplayConstants;
import org.sagebionetworks.web.client.DisplayUtils;
import org.sagebionetworks.web.client.context.SynapseReactClientFullContextPropsProvider;
import org.sagebionetworks.web.client.cookie.CookieProvider;
Expand All @@ -48,6 +55,7 @@
import org.sagebionetworks.web.client.widget.header.Header;
import org.sagebionetworks.web.client.widget.table.v2.results.SortableTableHeaderImpl;
import org.sagebionetworks.web.client.widget.team.OpenTeamInvitationsWidget;
import org.sagebionetworks.web.shared.SearchQueryUtils;

public class ProfileViewImpl extends Composite implements ProfileView {

Expand Down Expand Up @@ -220,20 +228,23 @@ public interface ProfileViewImplUiBinder

CookieProvider cookies;
SynapseReactClientFullContextPropsProvider propsProvider;
JSONObjectAdapter jsonObjectAdapter;

@Inject
public ProfileViewImpl(
ProfileViewImplUiBinder binder,
Header headerWidget,
CookieProvider cookies,
SynapseReactClientFullContextPropsProvider propsProvider,
OrientationBanner orientationBanner
OrientationBanner orientationBanner,
JSONObjectAdapter jsonObjectAdapter
) {
initWidget(binder.createAndBindUi(this));
this.headerWidget = headerWidget;
this.cookies = cookies;
this.propsProvider = propsProvider;
this.orientationBanner = orientationBanner;
this.jsonObjectAdapter = jsonObjectAdapter;
headerWidget.configure();
projectSearchTextBox
.getElement()
Expand All @@ -257,7 +268,7 @@ public ProfileViewImpl(
presenter.goTo(new TeamSearch(teamSearchTextBox.getValue()))
);
projectSearchButton.addClickHandler(event ->
presenter.goTo(new Search(projectSearchTextBox.getValue()))
presenter.goTo(new Search(getCurrentProjectSearchJSON()))
);

moreChallengesButton.addClickHandler(event -> presenter.getMoreChallenges()
Expand Down Expand Up @@ -288,6 +299,27 @@ public ProfileViewImpl(
);
}

private String getCurrentProjectSearchJSON() {
String searchJSON = "";
JSONObjectAdapter adapter = jsonObjectAdapter.createNew();
try {
SearchQuery query = SearchQueryUtils.getDefaultSearchQuery();
KeyValue projectsOnly = new KeyValue();
projectsOnly.setKey("node_type");
projectsOnly.setValue("project");
query.getBooleanQuery().add(projectsOnly);

query.setQueryTerm(
Arrays.asList(projectSearchTextBox.getValue().split("\\s+"))
);
query.writeToJSONObject(adapter);
searchJSON = adapter.toJSONString();
} catch (JSONObjectAdapterException e) {
showErrorMessage(DisplayConstants.ERROR_GENERIC);
}
return searchJSON;
}

@Override
public void setSortDirection(
ProjectListSortColumn column,
Expand Down

0 comments on commit 0f07fa5

Please sign in to comment.