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

IQSS / dataverse-frontend / 7573388964

18 Jan 2024 04:54PM CUT coverage: 97.929% (+0.007%) from 97.922%
7573388964

push

github

MellyGray
feat(HomePagination): update the page query param when the page changes

473 of 488 branches covered (0.0%)

Branch coverage included in aggregate %.

1513 of 1540 relevant lines covered (98.25%)

4175.25 hits per line

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

78.13
/src/sections/home/datasets-list/useDatasets.tsx
1
import { useEffect, useState } from 'react'
2
import { DatasetRepository } from '../../../dataset/domain/repositories/DatasetRepository'
3
import { getDatasets } from '../../../dataset/domain/useCases/getDatasets'
4
import { getTotalDatasetsCount } from '../../../dataset/domain/useCases/getTotalDatasetsCount'
5
import { TotalDatasetsCount } from '../../../dataset/domain/models/TotalDatasetsCount'
6
import { DatasetPaginationInfo } from '../../../dataset/domain/models/DatasetPaginationInfo'
7
import { DatasetPreview } from '../../../dataset/domain/models/DatasetPreview'
8

9
export function useDatasets(
10
  datasetRepository: DatasetRepository,
11
  onPaginationInfoChange: (paginationInfo: DatasetPaginationInfo) => void,
12
  paginationInfo: DatasetPaginationInfo
13
) {
104✔
14
  const [datasets, setDatasets] = useState<DatasetPreview[]>([])
104✔
15
  const [isLoading, setIsLoading] = useState<boolean>(true)
104✔
16
  const [totalDatasetsCount, setTotalDatasetsCount] = useState<TotalDatasetsCount>()
104✔
17

18
  const fetchTotalDatasetsCount: () => Promise<TotalDatasetsCount> = () => {
104✔
19
    return getTotalDatasetsCount(datasetRepository)
32✔
20
      .then((totalDatasetsCount: TotalDatasetsCount) => {
21
        setTotalDatasetsCount(totalDatasetsCount)
32✔
22
        if (totalDatasetsCount !== paginationInfo.totalItems) {
32✔
23
          onPaginationInfoChange(paginationInfo.withTotal(totalDatasetsCount))
29✔
24
        }
25
        return totalDatasetsCount
32✔
26
      })
27
      .catch(() => {
28
        throw new Error('There was an error getting the datasets count info')
×
29
      })
30
  }
31
  const fetchDatasets = (totalDatasetsCount: TotalDatasetsCount) => {
104✔
32
    if (typeof totalDatasetsCount !== 'undefined') {
32✔
33
      if (totalDatasetsCount === 0) {
32!
34
        setIsLoading(false)
×
35
        return
×
36
      }
37
      return getDatasets(datasetRepository, paginationInfo.withTotal(totalDatasetsCount))
32✔
38
        .then((datasets: DatasetPreview[]) => {
39
          setDatasets(datasets)
32✔
40
          setIsLoading(false)
32✔
41
          return datasets
32✔
42
        })
43
        .catch(() => {
44
          throw new Error('There was an error getting the datasets')
×
45
        })
46
    }
47
  }
48

49
  useEffect(() => {
104✔
50
    setIsLoading(true)
32✔
51

52
    fetchTotalDatasetsCount()
32✔
53
      .then((totalDatasetsCount) => fetchDatasets(totalDatasetsCount))
32✔
54
      .catch(() => {
55
        console.error('There was an error getting the datasets')
×
56
        setIsLoading(false)
×
57
      })
58
  }, [datasetRepository, paginationInfo.page])
59

60
  return {
104✔
61
    datasets,
62
    totalDatasetsCount,
63
    isLoading
64
  }
65
}
10✔
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

© 2025 Coveralls, Inc