@@ -14,9 +14,7 @@ import { useInstrumentInfoQuery } from '@/hooks/useInstrumentInfoQuery';
1414import { summaryQueryOptions , useSummaryQuery } from '@/hooks/useSummaryQuery' ;
1515import { useAppStore } from '@/store' ;
1616import { useUsersQuery } from '@/hooks/useUsersQuery' ;
17- import type { InstrumentRecordsExport } from '@opendatacapture/schemas/instrument-records' ;
18- import axios from 'axios' ;
19- import { useInstrumentRecordsExportQuery } from '@/hooks/useInstrumentRecordExportQuery' ;
17+ import { useInstrumentRecords } from '@/hooks/useInstrumentRecords' ;
2018
2119const RouteComponent = ( ) => {
2220 const changeGroup = useAppStore ( ( store ) => store . changeGroup ) ;
@@ -31,12 +29,36 @@ const RouteComponent = () => {
3129 const instrumentInfoQuery = useInstrumentInfoQuery ( ) ;
3230 const userInfoQuery = useUsersQuery ( ) ;
3331
34- const recordsExportQuery = useInstrumentRecordsExportQuery ( currentGroup ?. id ) ;
32+ const recordsQuery = useInstrumentRecords ( {
33+ enabled : true ,
34+ params : {
35+ groupId : currentGroup ?. id
36+ }
37+ } ) ;
38+
39+ const instrumentData = currentGroup
40+ ? instrumentInfoQuery . data ?. filter ( ( instrument ) => {
41+ return currentGroup . accessibleInstrumentIds . includes ( instrument . id ) ;
42+ } )
43+ : instrumentInfoQuery . data ;
44+
45+ const instrumentInfo = instrumentData ?. map ( ( instrument ) => {
46+ return {
47+ kind : instrument . kind ,
48+ title : instrument . details . title ,
49+ id : instrument . id
50+ } ;
51+ } ) ;
3552
36- const recordsData =
37- recordsExportQuery . data ?. map ( ( record ) => ( {
38- title : record . instrumentName
39- } ) ) ?? [ ] ;
53+ const recordIds = recordsQuery . data ?. map ( ( record ) => record . instrumentId ) ;
54+
55+ const recordCounter =
56+ instrumentInfo ?. map ( ( title ) => {
57+ return {
58+ instrumentTitle : title . title ,
59+ count : recordIds ?. filter ( ( val ) => val === title . id ) . length ?? 0
60+ } ;
61+ } ) ?? [ ] ;
4062
4163 const chartColors = {
4264 records : {
@@ -108,19 +130,6 @@ const RouteComponent = () => {
108130 } ) ;
109131 }
110132
111- const instrumentData = currentGroup
112- ? instrumentInfoQuery . data ?. filter ( ( instrument ) => {
113- return currentGroup . accessibleInstrumentIds . includes ( instrument . id ) ;
114- } )
115- : instrumentInfoQuery . data ;
116-
117- const instrumentInfo = instrumentData ?. map ( ( record ) => {
118- return {
119- kind : record . kind ,
120- title : record . details . title
121- } ;
122- } ) ;
123-
124133 // should never happen, as data is ensured in loader, but avoid crashing the app if someone changes this
125134 if ( ! summaryQuery . data ) {
126135 return null ;
0 commit comments