Skip to content

Commit

Permalink
feat: Migrate datasets and deposition filter values to use V2 data (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
bchu1 authored Jan 23, 2025
1 parent 4b8f40b commit f338feb
Showing 1 changed file with 33 additions and 36 deletions.
69 changes: 33 additions & 36 deletions frontend/packages/data-portal/app/hooks/useDatasetsFilterData.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,40 @@
import { isString } from 'lodash-es'
import { useMemo } from 'react'
import { useTypedLoaderData } from 'remix-typedjson'

import { GetDatasetsFilterDataQuery } from 'app/__generated__/graphql'
import {
GetDatasetsV2Query,
GetDepositionByIdV2Query,
} from 'app/__generated_v2__/graphql'
import { isDefined } from 'app/utils/nullish'

export function useDatasetsFilterData() {
const { v1FilterValues: v1 } = useTypedLoaderData<{
v1FilterValues: GetDatasetsFilterDataQuery
const { v2 } = useTypedLoaderData<{
v2: GetDatasetsV2Query | GetDepositionByIdV2Query // TODO: Move this data into props.
}>()

return useMemo(
() => ({
organismNames: v1.organism_names
.map((value) => value.organism_name)
.filter(isString),

cameraManufacturers: v1.camera_manufacturers.map(
(value) => value.camera_manufacturer,
),

reconstructionMethods: v1.reconstruction_methods.map(
(value) => value.reconstruction_method,
),

reconstructionSoftwares: v1.reconstruction_softwares.map(
(value) => value.reconstruction_software,
),

objectNames: v1.object_names.map((value) => value.object_name),

objectShapeTypes: v1.object_shape_types.map((value) => value.shape_type),
}),
[
v1.organism_names,
v1.camera_manufacturers,
v1.reconstruction_methods,
v1.reconstruction_softwares,
v1.object_names,
v1.object_shape_types,
],
)
return {
organismNames:
v2.distinctOrganismNames.aggregate
?.map((aggregate) => aggregate.groupBy?.organismName)
.filter(isDefined) ?? [],
cameraManufacturers:
v2.distinctCameraManufacturers.aggregate
?.map((aggregate) => aggregate.groupBy?.cameraManufacturer)
.filter(isDefined) ?? [],
reconstructionMethods:
v2.distinctReconstructionMethods.aggregate
?.map((aggregate) => aggregate.groupBy?.reconstructionMethod)
.filter(isDefined) ?? [],
reconstructionSoftwares:
v2.distinctReconstructionSoftwares.aggregate
?.map((aggregate) => aggregate.groupBy?.reconstructionSoftware)
.filter(isDefined) ?? [],
objectNames:
v2.distinctObjectNames.aggregate
?.map((aggregate) => aggregate.groupBy?.objectName)
.filter(isDefined) ?? [],
objectShapeTypes:
v2.distinctShapeTypes.aggregate
?.map((aggregate) => aggregate.groupBy?.shapeType)
.filter(isDefined) ?? [],
}
}

0 comments on commit f338feb

Please sign in to comment.