-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: api migration for browse all depositions page (#1357)
- Loading branch information
Showing
12 changed files
with
493 additions
and
81 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
frontend/packages/data-portal/app/apiNormalization/browseAllDepositionsV1.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { GetDepositionsDataQuery } from 'app/__generated__/graphql' | ||
import { AuthorInfoType } from 'app/types/authorInfo' | ||
import { | ||
BrowseAllDepositionsPageDataType, | ||
Deposition, | ||
} from 'app/types/PageData/browseAllDepositionsPageData' | ||
import { ObjectShapeType } from 'app/types/shapeTypes' | ||
import { remapAPI } from 'app/utils/apiMigration' | ||
|
||
const remapV1Author = remapAPI< | ||
GetDepositionsDataQuery['depositions'][number]['authors'][number], | ||
AuthorInfoType | ||
>({ | ||
name: 'name', | ||
primaryAuthorStatus: 'primary_author_status', | ||
correspondingAuthorStatus: 'corresponding_author_status', | ||
} as const) | ||
|
||
const remapV1Deposition = remapAPI< | ||
GetDepositionsDataQuery['depositions'][number], | ||
Deposition | ||
>({ | ||
id: 'id', | ||
title: 'title', | ||
keyPhotoThumbnailUrl: 'key_photo_thumbnail_url', | ||
depositionDate: 'deposition_date', | ||
authors: (deposition) => deposition.authors.map(remapV1Author), | ||
annotationCount: (deposition) => | ||
deposition.annotations_aggregate.aggregate?.count ?? 0, | ||
annotatedObjects: (deposition) => | ||
Array.from( | ||
new Set( | ||
deposition.annotations.map((annotation) => annotation.object_name), | ||
), | ||
).sort((a, b) => a.localeCompare(b, undefined, { sensitivity: 'base' })), | ||
objectShapeTypes: (deposition) => | ||
Array.from( | ||
new Set( | ||
deposition.shape_types.flatMap((annotation) => | ||
annotation.files.map((file) => file.shape_type as ObjectShapeType), | ||
), | ||
), | ||
).sort((a, b) => a.localeCompare(b)), | ||
acrossDatasets: () => 0, | ||
} as const) | ||
|
||
export const remapV1BrowseAllDepositions = remapAPI< | ||
GetDepositionsDataQuery, | ||
BrowseAllDepositionsPageDataType | ||
>({ | ||
totalDepositionCount: (data) => | ||
data.depositions_aggregate.aggregate?.count ?? 0, | ||
filteredDepositionCount: (data) => | ||
data.filtered_depositions_aggregate.aggregate?.count ?? 0, | ||
depositions: (data) => data.depositions.map(remapV1Deposition), | ||
allObjectNames: (data) => | ||
Array.from( | ||
new Set(data.object_names.map((annotation) => annotation.object_name)), | ||
).sort((a, b) => a.localeCompare(b, undefined, { sensitivity: 'base' })), | ||
allObjectShapeTypes: (data) => | ||
Array.from( | ||
new Set( | ||
data.object_shape_types.map( | ||
(annotation) => annotation.shape_type as ObjectShapeType, | ||
), | ||
), | ||
).sort((a, b) => a.localeCompare(b)), | ||
} as const) |
78 changes: 78 additions & 0 deletions
78
frontend/packages/data-portal/app/apiNormalization/browseAllDepositionsV2.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { GetDepositionsDataV2Query } from 'app/__generated_v2__/graphql' | ||
import { | ||
BrowseAllDepositionsPageDataType, | ||
Deposition, | ||
} from 'app/types/PageData/browseAllDepositionsPageData' | ||
import { ObjectShapeType } from 'app/types/shapeTypes' | ||
import { remapAPI } from 'app/utils/apiMigration' | ||
|
||
const remapV2Deposition = remapAPI< | ||
GetDepositionsDataV2Query['depositions'][number], | ||
Deposition | ||
>({ | ||
id: 'id', | ||
title: 'title', | ||
keyPhotoThumbnailUrl: 'keyPhotoThumbnailUrl', | ||
depositionDate: (deposition) => deposition.depositionDate.split('T')[0], | ||
authors: (deposition) => | ||
deposition.authors?.edges?.map((edge) => edge.node) ?? [], | ||
annotationCount: (deposition) => | ||
deposition.annotationsCount?.aggregate?.at(0)?.count ?? 0, | ||
annotatedObjects: (deposition) => | ||
Array.from( | ||
new Set( | ||
deposition.objectNames?.aggregate | ||
?.map((aggregate) => aggregate.groupBy?.objectName ?? '') | ||
.filter((value) => value !== '') ?? [], | ||
), | ||
).sort((a, b) => a.localeCompare(b, undefined, { sensitivity: 'base' })), | ||
// TODO: uncomment/remap when efficient query is available | ||
// objectShapeTypes: (deposition) => | ||
// Array.from( | ||
// new Set( | ||
// deposition.shapeTypes?.edges.flatMap( | ||
// (edge) => | ||
// edge.node.annotationShapes?.edges.flatMap( | ||
// (edge2) => edge2.node?.shapeType as ObjectShapeType, | ||
// ), | ||
// ), | ||
// ), | ||
// ).sort((a, b) => a.localeCompare(b)), | ||
objectShapeTypes: () => [], | ||
acrossDatasets: (deposition) => | ||
deposition.annotationDatasetCount?.aggregate?.length ?? 0, | ||
} as const) | ||
|
||
export const remapV2BrowseAllDepositions = remapAPI< | ||
GetDepositionsDataV2Query, | ||
BrowseAllDepositionsPageDataType | ||
>({ | ||
totalDepositionCount: (data) => | ||
data.totalDepositionCount?.aggregate?.at(0)?.count ?? 0, | ||
filteredDepositionCount: (data) => | ||
data.filteredDepositionCount?.aggregate?.at(0)?.count ?? 0, | ||
depositions: (data) => | ||
data.depositions.map(remapV2Deposition).sort((a, b) => { | ||
const dateDiff = | ||
new Date(b.depositionDate).getTime() - | ||
new Date(a.depositionDate).getTime() | ||
if (dateDiff !== 0) return dateDiff | ||
return b.id - a.id | ||
}), | ||
allObjectNames: (data) => | ||
Array.from( | ||
new Set( | ||
data.allObjectNames?.aggregate | ||
?.map((aggregate) => aggregate.groupBy?.objectName ?? '') | ||
.filter((value) => value !== '') ?? [], | ||
), | ||
).sort((a, b) => a.localeCompare(b, undefined, { sensitivity: 'base' })), | ||
allObjectShapeTypes: (data) => | ||
Array.from( | ||
new Set( | ||
data.allObjectShapeTypes?.aggregate?.map( | ||
(aggregate) => aggregate.groupBy?.shapeType as ObjectShapeType, | ||
) ?? [], | ||
), | ||
).sort((a, b) => a.localeCompare(b)), | ||
} as const) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './browseAllDepositionsV1' | ||
export * from './browseAllDepositionsV2' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.