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

chore: Refactor datasets filter values fragment #1456

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
@@ -1,58 +1,70 @@
import { gql } from 'app/__generated_v2__'

/**
* Shares filter options queries between datasets and deposition pages (filters are near identical).
* Shares aggregate queries between datasets and deposition pages (the 2 pages are very similar).
*
* Parent query must define $depositionFilter.
* Parent query must define the following variables:
* - $datasetsFilter
* - $datasetsByDepositionFilter
* - $tiltseriesByDepositionFilter
* - $tomogramsByDepositionFilter
* - $annotationsByDepositionFilter
* - $annotationShapesByDepositionFilter
*/
export const GET_DATASETS_FILTER_VALUES_FRAGMENT = gql(`
fragment DatasetsFilterValues on Query {
distinctOrganismNames: datasetsAggregate(where: { depositionId: $depositionFilter }) {
export const GET_DATASETS_AGGREGATES_FRAGMENT = gql(`
fragment DatasetsAggregates on Query {
filteredDatasetsCount: datasetsAggregate(where: $datasetsFilter) {
aggregate {
count
}
}
totalDatasetsCount: datasetsAggregate(where: $datasetsByDepositionFilter) {
aggregate {
count
}
}

distinctOrganismNames: datasetsAggregate(where: $datasetsByDepositionFilter) {
aggregate {
count
groupBy {
organismName
}
}
}

distinctCameraManufacturers: tiltseriesAggregate(where: { depositionId: $depositionFilter }) {
distinctCameraManufacturers: tiltseriesAggregate(where: $tiltseriesByDepositionFilter) {
aggregate {
count
groupBy {
cameraManufacturer
}
}
}

distinctReconstructionMethods: tomogramsAggregate(where: { depositionId: $depositionFilter }) {
distinctReconstructionMethods: tomogramsAggregate(where: $tomogramsByDepositionFilter) {
aggregate {
count
groupBy {
reconstructionMethod
}
}
}

distinctReconstructionSoftwares: tomogramsAggregate(where: { depositionId: $depositionFilter }) {
distinctReconstructionSoftwares: tomogramsAggregate(where: $tomogramsByDepositionFilter) {
aggregate {
count
groupBy {
reconstructionSoftware
}
}
}

distinctObjectNames: annotationsAggregate(where: { depositionId: $depositionFilter }) {
distinctObjectNames: annotationsAggregate(where: $annotationsByDepositionFilter) {
aggregate {
count
groupBy {
objectName
}
}
}

distinctShapeTypes: annotationShapesAggregate(where: { annotation: { depositionId: $depositionFilter } }) {
distinctShapeTypes: annotationShapesAggregate(where: $annotationShapesByDepositionFilter) {
aggregate {
count
groupBy {
Expand Down
26 changes: 10 additions & 16 deletions frontend/packages/data-portal/app/graphql/getDatasetsV2.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,16 @@ const GET_DATASETS_QUERY = gql(`
$limit: Int,
$offset: Int,
$orderBy: [DatasetOrderByClause!]!,
$filter: DatasetWhereClause!,
$depositionFilter: IntComparators # Unused, but must be defined because DatasetsFilterValues references it.
$datasetsFilter: DatasetWhereClause!,
# Unused, but must be defined because DatasetsAggregates references them:
$datasetsByDepositionFilter: DatasetWhereClause,
$tiltseriesByDepositionFilter: TiltseriesWhereClause,
$tomogramsByDepositionFilter: TomogramWhereClause,
$annotationsByDepositionFilter: AnnotationWhereClause,
$annotationShapesByDepositionFilter: AnnotationShapeWhereClause
) {
datasets(
where: $filter
where: $datasetsFilter
orderBy: $orderBy,
limitOffset: {
limit: $limit,
Expand Down Expand Up @@ -69,18 +74,7 @@ const GET_DATASETS_QUERY = gql(`
}
}

totalDatasetsCount: datasetsAggregate {
aggregate {
count
}
}
filteredDatasetsCount: datasetsAggregate(where: $filter) {
aggregate {
count
}
}

...DatasetsFilterValues
...DatasetsAggregates
}
`)

Expand Down Expand Up @@ -337,7 +331,7 @@ export async function getDatasetsV2({
return client.query({
query: GET_DATASETS_QUERY,
variables: {
filter: getFilter(getFilterState(params), searchText),
datasetsFilter: getFilter(getFilterState(params), searchText),
limit: MAX_PER_PAGE,
offset: (page - 1) * MAX_PER_PAGE,
// Default order primarily by release date.
Expand Down
Loading