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

IQSS / dataverse-frontend / 7478270980

08 Jan 2024 03:20PM CUT coverage: 97.854% (-0.07%) from 97.922%
7478270980

Pull #260

github

web-flow
Merge pull request #271 from IQSS/feature/262-file-labels-section-of-the-file-page

262 - File labels section of the File page
Pull Request #260: 249 - File Page boilerplate

471 of 486 branches covered (0.0%)

Branch coverage included in aggregate %.

1535 of 1564 relevant lines covered (98.15%)

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

18
  const fetchTotalDatasetsCount: () => Promise<TotalDatasetsCount> = () => {
68✔
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) => {
68✔
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(() => {
68✔
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 {
68✔
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