Skip to content

Commit

Permalink
fix: Don't add annotation rows for shape types that are filtered out (#…
Browse files Browse the repository at this point in the history
…892)

Resolves #891 

In order to display a separate annotation row for each shape type, we
expand the list of annotations on the frontend. This adds a check to the
expansion function for whether the shape type is filtered out.


![filter-fix](https://github.com/user-attachments/assets/e41bebbd-1edc-45e8-8cb4-b2f36a6e51d6)
  • Loading branch information
ehoops-cz authored Jul 18, 2024
1 parent f65fa0c commit 6a38f11
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,11 @@ export function AnnotationTable() {
data.annotations.flatMap((annotation) => {
const shapeTypeSet = new Set<string>()

// Some annotations have files with different shape types. We display each shape type as a separate row.
// This loops through the files and adds an annotation for each shape type.
// If the shape type is filtered out, the files will not be returned in the 'run' object
const files = annotation.files.filter((file) => {
// If the shape type has already been added, don't add another annotation for it
if (shapeTypeSet.has(file.shape_type)) {
return false
}
Expand Down
28 changes: 25 additions & 3 deletions frontend/packages/data-portal/app/graphql/getRunById.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ import type { ApolloClient, NormalizedCacheObject } from '@apollo/client'
import { URLSearchParams } from 'url'

import { gql } from 'app/__generated__'
import { Annotations_Bool_Exp } from 'app/__generated__/graphql'
import {
Annotation_Files_Bool_Exp,
Annotations_Bool_Exp,
} from 'app/__generated__/graphql'
import { MAX_PER_PAGE } from 'app/constants/pagination'
import { FilterState, getFilterState } from 'app/hooks/useFilter'

const GET_RUN_BY_ID_QUERY = gql(`
query GetRunById($id: Int, $limit: Int, $offset: Int, $filter: annotations_bool_exp) {
query GetRunById($id: Int, $limit: Int, $offset: Int, $filter: annotations_bool_exp, $fileFilter: annotation_files_bool_exp) {
runs(where: { id: { _eq: $id } }) {
id
name
Expand Down Expand Up @@ -147,7 +150,9 @@ const GET_RUN_BY_ID_QUERY = gql(`
object_state
release_date
files {
files(
where: $fileFilter,
) {
format
https_path
s3_path
Expand Down Expand Up @@ -314,6 +319,22 @@ function getFilter(filterState: FilterState) {
return { _and: filters } as Annotations_Bool_Exp
}

function getFileFilter(filterState: FilterState) {
const filters: Annotation_Files_Bool_Exp[] = []

const { objectShapeTypes } = filterState.annotation

if (objectShapeTypes.length > 0) {
filters.push({
shape_type: {
_in: objectShapeTypes,
},
})
}

return { _and: filters } as Annotation_Files_Bool_Exp
}

export async function getRunById({
client,
id,
Expand All @@ -332,6 +353,7 @@ export async function getRunById({
limit: MAX_PER_PAGE,
offset: (page - 1) * MAX_PER_PAGE,
filter: getFilter(getFilterState(params)),
fileFilter: getFileFilter(getFilterState(params)),
},
})
}

0 comments on commit 6a38f11

Please sign in to comment.