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

IQSS / dataverse-frontend / 7758268159

02 Feb 2024 03:46PM UTC coverage: 97.551% (+0.02%) from 97.529%
7758268159

Pull #297

github

MellyGray
feat(Breadcrumbs): add to pages skeleton
Pull Request #297: 265 - Add breadcrumbs

536 of 554 branches covered (0.0%)

Branch coverage included in aggregate %.

1615 of 1651 relevant lines covered (97.82%)

3854.4 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
) {
70✔
14
  const [datasets, setDatasets] = useState<DatasetPreview[]>([])
70✔
15
  const [isLoading, setIsLoading] = useState<boolean>(true)
70✔
16
  const [totalDatasetsCount, setTotalDatasetsCount] = useState<TotalDatasetsCount>()
70✔
17

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

49
  useEffect(() => {
70✔
50
    setIsLoading(true)
21✔
51

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

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