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

Add sorting and filter functionality in PEPhub search. #100

Closed
khoroshevskyi opened this issue Feb 28, 2023 · 5 comments
Closed

Add sorting and filter functionality in PEPhub search. #100

khoroshevskyi opened this issue Feb 28, 2023 · 5 comments
Labels
enhancement New feature or request likely solved
Milestone

Comments

@khoroshevskyi
Copy link
Member

It will be useful to add filter and sort to PEPhub. This functionality can include:

  • Filter and sort by update/submission date
  • Filter and sort by number of samples
  • ...
@khoroshevskyi khoroshevskyi added the enhancement New feature or request label Feb 28, 2023
@nsheff
Copy link
Contributor

nsheff commented Feb 28, 2023

Related to #99

@nleroy917
Copy link
Member

Are we envisioning client-side or server-side filtering?

@khoroshevskyi
Copy link
Member Author

Sorting functionality is added to pepdbagent. Now we can add it to pephub

@nleroy917
Copy link
Member

I'm not positive that the pepdbagent sorting is working. I think there are two issues:

  1. The sort order seems incorrect for dates, and
  2. pagination exhibits weird behavior

An example for 1: Sort by last update (newest). I want most recently updated projects to show up:
The UI makes this call to the server: /projects?order_by=update_date&order_desc=true
And projects updated in April are showing before projects updated within the last day.

An example for 2: Sort by name (A-Z). I want projects that start with "A" to come before projects that start with "Z":
The UI makes this call to the server: /projects?order_by=name&order_desc=false

Everything seems ok from the get-go. My forked GSE's come before projects like scATAC-atlas and my-project. However, when I page over, I get projects with "B" in them (basic). I would expect that as I page over, I'd get things closer to Z.

Let me know if I am using things incorrectly. For specificity, here is the select I am using to make this request:

        <select
          value={`${orderBy}+${order}`}
          onChange={(e) => {
            const [orderBy, order] = e.target.value.split('+');
            setOrderBy(orderBy);
            setOrder(order);
          }}
          className="form-control form-select"
        >
          <option value={'name+asc'}>Name (A-Z)</option>
          <option value={'name+desc'}>Name (Z-A)</option>
          <option value={'update_date+desc'}>Last update (newest)</option>
          <option value={'update_date+asc'}>Last update (oldest)</option>
          <option value={'submission_date+desc'}>Submission date (newest)</option>
          <option value={'submission_date+asc'}>Submission date (oldest)</option>
        </select>

Then in the actual typescript to call the endpoint:

export const getNamespaceProjects = (
  namespace: string,
  token: string | null = null,
  { search, offset, limit, orderBy, order }: PaginationParams,
) => {
  // construct query based on search, offset, and limit
  const query = new URLSearchParams();
  if (search) {
    query.set('q', search);
  }
  if (offset) {
    query.set('offset', offset.toString());
  }
  if (limit) {
    query.set('limit', limit.toString());
  }
  if (orderBy) {
    query.set('order_by', orderBy);
  }
  if (order) {
    if (order === 'asc') {
      query.set('order_desc', 'false');
    } else {
      query.set('order_desc', 'true');
    }
  }
  const url = `${API_BASE}/namespaces/${namespace}/projects?${query.toString()}`;
  if (!token) {
    return axios.get<NamespaceProjectsResponse>(url).then((res) => res.data);
  } else {
    return axios
      .get<NamespaceProjectsResponse>(url, { headers: { Authorization: `Bearer ${token}` } })
      .then((res) => res.data);
  }
};

nleroy917 added a commit that referenced this issue Jun 8, 2023
@nleroy917
Copy link
Member

The latest pepdbagent updates seem to have fixed all this and I think it is working now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request likely solved
Projects
None yet
Development

No branches or pull requests

3 participants