• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

CBIIT / bento-c3dc-frontend / 20466438594

23 Dec 2025 04:44PM UTC coverage: 0.168%. Remained the same
20466438594

push

github

web-flow
Merge pull request #448 from CBIIT/slider-fix

updated count logic + moved unknown ages clear logic to library

6 of 3645 branches covered (0.16%)

Branch coverage included in aggregate %.

0 of 2 new or added lines in 1 file covered. (0.0%)

20 existing lines in 3 files now uncovered.

10 of 5859 relevant lines covered (0.17%)

0.09 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/pages/CohortAnalyzer/HistogramPanel/useKmplot.js
1
import { useEffect, useState, useRef } from 'react';
×
2
import { gql } from '@apollo/client';
×
3
import { useApolloClient } from '@apollo/client';
4

5
const KM_PLOT_QUERY = gql`
×
6
  query kMPlot(
7
    $c1: [String],
8
    $c2: [String],
9
    $c3: [String]
10
  ) {
11
    kMPlot(
12
      c1: $c1,
13
      c2: $c2,
14
      c3: $c3
15
    ) {
16
      id
17
      time
18
      event
19
      group
20
      __typename
21
    }
22
  }
23
`;
24

25
/**
26
 * Custom hook to fetch and manage KM plot data
27
 * @param {Array} c1 - Cohort 1 array
28
 * @param {Array} c2 - Cohort 2 array
29
 * @param {Array} c3 - Cohort 3 array
30
 * @returns {Object} { data, loading, error }
31
 */
32
export default function useKmplot({ c1, c2, c3 }) {
33
  const [data, setData] = useState([]);
×
34
  const [loading, setLoading] = useState(false);
×
35
  const [error, setError] = useState(null);
×
36
  const client = useApolloClient();
×
37
  const isMountedRef = useRef(true);
×
38
  const fetchInProgressRef = useRef(false);
×
39

40
  useEffect(() => {
×
41
    isMountedRef.current = true;
×
42
    
43
    return () => {
×
44
      isMountedRef.current = false;
×
45
    };
46
  }, []);
47

48
  useEffect(() => {
×
49
    // Don't fetch if no cohorts are selected
50
    const hasCohorts = (c1 && c1.length > 0) || (c2 && c2.length > 0) || (c3 && c3.length > 0);
×
51
    
52
    if (!hasCohorts) {
×
53
      setData([]);
×
54
      setLoading(false);
×
55
      setError(null);
×
56
      return;
×
57
    }
58
    
59
    // Prevent double fetch calls
60
    if (fetchInProgressRef.current) {
×
61
      return;
×
62
    }
63
    
64
    const fetchKmPlot = async () => {
×
65
      fetchInProgressRef.current = true;
×
66
      setLoading(true);
×
67
      setError(null);
×
68
      
69
      try {
×
70
        const result = await client.query({
×
71
          query: KM_PLOT_QUERY,
72
          variables: { c1, c2, c3 },
73
          fetchPolicy: 'no-cache', 
74
        });
75

76
        // Only update state if component is still mounted
77
        if (!isMountedRef.current) {
×
UNCOV
78
          return;
×
79
        }
80

81
        if (result.errors) {
×
UNCOV
82
          throw new Error((result.errors[0] && result.errors[0].message) || 'Unknown error');
×
83
        }
84

85
        // Use the fetched data from GraphQL
86
        setData((result.data && result.data.kMPlot) || []);
×
UNCOV
87
        setError(null);
×
88
      } catch (err) {
89
        console.error('Error fetching KM plot data:', err);
×
90
        if (isMountedRef.current) {
×
91
          setError(err);
×
UNCOV
92
          setData([]);
×
93
        }
94
      } finally {
95
        if (isMountedRef.current) {
×
UNCOV
96
          setLoading(false);
×
97
        }
UNCOV
98
        fetchInProgressRef.current = false;
×
99
      }
100
    };
101

UNCOV
102
    fetchKmPlot();
×
103
  }, [c1, c2, c3, client]);
104

UNCOV
105
  return { data, loading, error };
×
106
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc