From 661cf143aecbf3cc91d8e22705047878158e1137 Mon Sep 17 00:00:00 2001 From: Yash Pankhania Date: Wed, 5 Jun 2024 18:33:21 +1000 Subject: [PATCH] updated gql to use generated types --- web/src/pages/ourdna/OurDnaDashboard.tsx | 94 ++++++++++++------------ 1 file changed, 49 insertions(+), 45 deletions(-) diff --git a/web/src/pages/ourdna/OurDnaDashboard.tsx b/web/src/pages/ourdna/OurDnaDashboard.tsx index ecb7c3a38..b5988c4ce 100644 --- a/web/src/pages/ourdna/OurDnaDashboard.tsx +++ b/web/src/pages/ourdna/OurDnaDashboard.tsx @@ -1,6 +1,7 @@ import React from 'react' import { Container, Grid, GridRow, GridColumn } from 'semantic-ui-react' -import { gql, useQuery } from '@apollo/client' +import { useQuery } from '@apollo/client' +import { gql } from '../../__generated__' import Tile from '../../shared/components/ourdna/Tile' import TableTile from '../../shared/components/ourdna/TableTile' @@ -22,13 +23,38 @@ import ClockIcon from '../../shared/components/ourdna/dashboardIcons/ClockIcon' import RocketIcon from '../../shared/components/ourdna/dashboardIcons/RocketIcon' import AlarmIcon from '../../shared/components/ourdna/dashboardIcons/AlarmIcon' -const GET_OURDNA_DASHBOARD = gql` +const GET_OURDNA_DASHBOARD = gql(` query DashboardQuery($project: String!) { project(name: $project) { - ourdnaDashboard + ourdnaDashboard { + collectionToProcessEndTime + collectionToProcessEndTime24h + collectionToProcessEndTimeStatistics + participantsConsentedNotCollected + participantsSignedNotConsented + processingTimesBySite + samplesConcentrationGt1ug + samplesLostAfterCollection { + collectionLab + collectionTime + courier + courierActualDropoffTime + courierActualPickupTime + courierScheduledDropoffTime + courierScheduledPickupTime + courierTrackingNumber + processEndTime + processStartTime + receivedBy + receivedTime + sampleId + timeToProcessStart + } + totalSamplesByCollectionEventName + } } } -` +`) const iconStyle = { marginRight: '10px', @@ -36,27 +62,8 @@ const iconStyle = { height: '24px', } -type OurDNADashboardData = { - project: { - ourdnaDashboard: { - participants_signed_not_consented: number[] - participants_consented_not_collected: number[] - samples_lost_after_collection: Record> - collection_to_process_end_time: Record - collection_to_process_end_time_statistics: { - min: number - max: number - average: number - } - collection_to_process_end_time_24h: Record - total_samples_by_collection_event_name: Record - processing_times_by_site: Record> - samples_concentration_gt_1ug: Record - } - } -} const Dashboard = () => { - const { loading, error, data } = useQuery(GET_OURDNA_DASHBOARD, { + const { loading, error, data } = useQuery(GET_OURDNA_DASHBOARD, { variables: { project: import.meta.env.VITE_OURDNA_PROJECT_NAME || 'ourdna' }, }) @@ -64,12 +71,14 @@ const Dashboard = () => { if (loading) return if (error) return <>Error! {error.message} - const samplesLostAfterCollections = Object.entries( - data.project.ourdnaDashboard.samples_lost_after_collection - ).reduce((rr: Record, [key, sample]) => { - rr[key] = sample.time_to_process_start / 3600 - return rr - }, {}) + const samplesLostAfterCollections = + data.project.ourdnaDashboard.samplesLostAfterCollection.reduce( + (rr: Record, sample) => { + rr[sample.sampleId] = sample.timeToProcessStart / 3600 + return rr + }, + {} + ) return ( <> @@ -91,7 +100,7 @@ const Dashboard = () => { { { header="Samples Lost" stat={`${ Object.keys( - data.project.ourdnaDashboard - .samples_lost_after_collection + data.project.ourdnaDashboard.samplesLostAfterCollection ).length }`} units="samples" @@ -145,8 +153,7 @@ const Dashboard = () => { { value: `${( data.project.ourdnaDashboard - .collection_to_process_end_time_statistics.min / - 3600 + .collectionToProcessEndTimeStatistics.min / 3600 ).toFixed(1)}`, units: 'shortest (h)', unitsColour: 'ourdna-green-transparent', @@ -154,8 +161,7 @@ const Dashboard = () => { { value: `${( data.project.ourdnaDashboard - .collection_to_process_end_time_statistics.max / - 3600 + .collectionToProcessEndTimeStatistics.max / 3600 ).toFixed(1)}`, units: 'longest (h)', unitsColour: 'ourdna-red-transparent', @@ -163,8 +169,8 @@ const Dashboard = () => { { value: `${( data.project.ourdnaDashboard - .collection_to_process_end_time_statistics - .average / 3600 + .collectionToProcessEndTimeStatistics.average / + 3600 ).toFixed(1)}`, units: 'average (h)', unitsColour: 'ourdna-blue-transparent', @@ -184,9 +190,7 @@ const Dashboard = () => { } @@ -197,7 +201,7 @@ const Dashboard = () => { } @@ -208,7 +212,7 @@ const Dashboard = () => {