11import React , {
2- useEffect , useState , useCallback , useMemo ,
2+ useState , useCallback , useMemo ,
33} from 'react' ;
44import { useParams , useHistory } from 'react-router-dom' ;
55import {
@@ -19,7 +19,7 @@ import { ActionCellRenderer } from '@/components/DataTable/components/ActionCell
1919import AlertDialog from '@/components/AlertDialog' ;
2020import snackbar from '@/services/SnackbarUtils' ;
2121import { GermlineReportType , VariantType } from '@/context/GermlineReportContext/types' ;
22- import withLoading , { WithLoadingInjectedProps } from '@/hoc/WithLoading ' ;
22+ import { useGermlineSmallMutationReportsGermline } from '@/queries/get ' ;
2323import { getDate } from '@/utils/date' ;
2424import StrikethroughCell from './components/StrikethroughCell' ;
2525import EditDialog from './components/EditDialog' ;
@@ -28,16 +28,13 @@ import columnDefs from './columnDefs';
2828import './index.scss' ;
2929import LinkoutCellRenderer from '../LinkoutCellRenderer' ;
3030
31- type GermlineReportProps = WithLoadingInjectedProps ;
32-
33- const GermlineReport = ( {
34- isLoading,
35- setIsLoading,
36- } : GermlineReportProps ) : JSX . Element => {
31+ const GermlineReport = ( ) : JSX . Element => {
3732 const { ident } = useParams < { ident : string } > ( ) ;
3833 const { gridApi, colApi, onGridReady } = useGrid ( ) ;
3934 const history = useHistory ( ) ;
40- const [ report , setReport ] = useState < GermlineReportType > ( ) ;
35+ const {
36+ data : report , isLoading, refetch : refetchReport ,
37+ } = useGermlineSmallMutationReportsGermline < GermlineReportType > ( ident ) ;
4138
4239 const [ showAllColumns , setShowAllColumns ] = useState ( false ) ;
4340 const [ showEditDialog , setShowEditDialog ] = useState ( false ) ;
@@ -46,25 +43,7 @@ const GermlineReport = ({
4643
4744 const [ menuAnchor , setMenuAnchor ] = useState < HTMLElement > ( ) ;
4845
49- const germlineReportContextValue = useMemo ( ( ) => ( { report, setReport } ) , [ report ] ) ;
50-
51- useEffect ( ( ) => {
52- if ( ident ) {
53- const getData = async ( ) => {
54- try {
55- const reportResp = await api . get (
56- `/germline-small-mutation-reports/${ ident } ` ,
57- ) . request ( ) ;
58- setReport ( reportResp ) ;
59- } catch ( err ) {
60- snackbar . error ( `Network error: ${ err } ` ) ;
61- } finally {
62- setIsLoading ( false ) ;
63- }
64- } ;
65- getData ( ) ;
66- }
67- } , [ ident , setReport , setIsLoading ] ) ;
46+ const germlineReportContextValue = useMemo ( ( ) => ( { report, refetchReport } ) , [ report , refetchReport ] ) ;
6847
6948 const handleGridReady = useCallback ( ( params ) => {
7049 const { columnApi } = params ;
@@ -92,13 +71,10 @@ const GermlineReport = ({
9271
9372 const handleEditClose = useCallback ( ( newRow ) => {
9473 if ( newRow ) {
95- const newVariants = [ ...report . variants ] ;
96- const index = newVariants . findIndex ( ( variant ) => variant . ident === newRow . ident ) ;
97- newVariants [ index ] = newRow ;
98- setReport ( ( prevVal ) => ( { ...prevVal , variants : newVariants } ) ) ;
74+ refetchReport ( ) ;
9975 }
10076 setShowEditDialog ( false ) ;
101- } , [ report ] ) ;
77+ } , [ refetchReport ] ) ;
10278
10379 const RowActionCellRenderer = useCallback ( ( row ) => (
10480 < ActionCellRenderer
@@ -248,4 +224,4 @@ const GermlineReport = ({
248224 ) ;
249225} ;
250226
251- export default withLoading ( GermlineReport ) ;
227+ export default GermlineReport ;
0 commit comments