Skip to content

Commit

Permalink
SWC-7203: change to a project search query object
Browse files Browse the repository at this point in the history
  • Loading branch information
jay-hodgson committed Dec 10, 2024
1 parent c225240 commit 3856500
Showing 1 changed file with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;
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 +30,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 +54,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 +227,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 +267,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 +298,26 @@ 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(
Collections.singletonList(projectSearchTextBox.getValue())
);
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 3856500

Please sign in to comment.