Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SWC-7203: change to a project search query object #5604

Merged
merged 2 commits into from
Dec 10, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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())
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we split up the text into multiple query terms? I am indifferent and prefer whatever yields "better" results, but if we don't, otherwise you get this sequence where search doesn't "feel" idempotent:

  1. Search from the project dashboard "my search terms"
  2. Search place opens with query "my search terms" + "project" filter
  3. Click "Search" again, and the results populate with the query ["my", "search", "terms"] + "project filter".

query.writeToJSONObject(adapter);
searchJSON = adapter.toJSONString();
} catch (JSONObjectAdapterException e) {
showErrorMessage(DisplayConstants.ERROR_GENERIC);
}
return searchJSON;
}

@Override
public void setSortDirection(
ProjectListSortColumn column,
Expand Down
Loading