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

IQSS / dataverse-frontend / 8687895133

15 Apr 2024 10:56AM UTC coverage: 97.694% (+0.2%) from 97.494%
8687895133

Pull #362

github

ekraffmiller
merge latest from develop, resolve merge conflicts
Pull Request #362: Refactor/276 avoid multiple api calls

606 of 630 branches covered (96.19%)

Branch coverage included in aggregate %.

13 of 15 new or added lines in 1 file covered. (86.67%)

1724 of 1755 relevant lines covered (98.23%)

3632.56 hits per line

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

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

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

20
  const fetchDatasetsWithCount = () => {
250✔
21
    return getDatasetsWithCount(datasetRepository, collectionId, paginationInfo).then(
83✔
22
      (datasetsWithCount: DatasetsWithCount) => {
23
        setTotalDatasetsCount(totalDatasetsCount)
83✔
24
        if (datasetsWithCount.totalCount === 0) {
83✔
25
          setIsLoading(false)
6✔
26
          return Promise.resolve()
6✔
27
        }
28
        if (totalDatasetsCount !== paginationInfo.totalItems) {
77✔
29
          paginationInfo = paginationInfo.withTotal(datasetsWithCount.totalCount)
77✔
30
          onPaginationInfoChange(paginationInfo)
77✔
31

32
          if (paginationInfo.page > paginationInfo.totalPages) {
77✔
33
            setPageNumberNotFound(true)
2✔
34
            setIsLoading(false)
2✔
35
            return Promise.resolve()
2✔
36
          }
37
          setDatasets(datasetsWithCount.datasetPreviews)
75✔
38
          setIsLoading(false)
75✔
39
        }
40
      }
41
    )
42
  }
43

44
  useEffect(() => {
250✔
45
    setIsLoading(true)
83✔
46
    fetchDatasetsWithCount().catch(() => {
83✔
NEW
47
      console.error('There was an error getting the datasets')
×
NEW
48
      setIsLoading(false)
×
49
    })
50
  }, [datasetRepository, paginationInfo.page])
51

52
  return {
250✔
53
    datasets,
54
    totalDatasetsCount,
55
    isLoading,
56
    pageNumberNotFound
57
  }
58
}
17✔
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