Skip to content

Commit

Permalink
fix: add proptypes
Browse files Browse the repository at this point in the history
  • Loading branch information
Birkbjo committed Feb 8, 2024
1 parent d7aeb85 commit 9bf677b
Show file tree
Hide file tree
Showing 11 changed files with 122 additions and 26 deletions.
11 changes: 10 additions & 1 deletion src/pages/data-integrity/details/CheckDetails.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { useConfig, useTimeZoneConversion } from '@dhis2/app-runtime'

Check failure on line 1 in src/pages/data-integrity/details/CheckDetails.js

View workflow job for this annotation

GitHub Actions / lint

'useConfig' is defined but never used
import i18n from '@dhis2/d2-i18n'
import { Button, IconSync16 } from '@dhis2/ui'
import PropTypes from 'prop-types'

Check failure on line 4 in src/pages/data-integrity/details/CheckDetails.js

View workflow job for this annotation

GitHub Actions / lint

'PropTypes' is defined but never used
import React, { useEffect, useState } from 'react'
import {
getDurationWithUnitFromDelta,
selectedLocale,
} from '../../../utils/relativeTime.js'
import { StatusIcon } from '../list/StatusIcon.js'
import css from './CheckDetails.module.css'
import { CheckIssues } from './DetailsIssues.js'
import { CheckIssues } from './CheckIssues.js'
import { checkProps } from './checkProps.js'
import { Notice } from './Notice.js'
import { useDataIntegrityDetails } from './use-data-integrity-details.js'

Expand Down Expand Up @@ -50,6 +52,10 @@ export const CheckDetails = ({ check }) => {
)
}

CheckDetails.propTypes = {
check: checkProps
}

export const DetailsHeader = ({ name, description }) => {

Check failure on line 59 in src/pages/data-integrity/details/CheckDetails.js

View workflow job for this annotation

GitHub Actions / lint

'name' is missing in props validation

Check failure on line 59 in src/pages/data-integrity/details/CheckDetails.js

View workflow job for this annotation

GitHub Actions / lint

'description' is missing in props validation
return (
<header>
Expand All @@ -59,6 +65,9 @@ export const DetailsHeader = ({ name, description }) => {
)
}

DetailsHeader.propTypes = {
}

const DetailsContent = ({
detailsCheck,

Check failure on line 72 in src/pages/data-integrity/details/CheckDetails.js

View workflow job for this annotation

GitHub Actions / lint

'detailsCheck' is missing in props validation
summaryCheck,

Check failure on line 73 in src/pages/data-integrity/details/CheckDetails.js

View workflow job for this annotation

GitHub Actions / lint

'summaryCheck' is missing in props validation
Expand Down
6 changes: 6 additions & 0 deletions src/pages/data-integrity/details/CheckDetailsView.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import i18n from '@dhis2/d2-i18n'
import React from 'react'
import { CheckDetails } from './CheckDetails.js'
import css from './CheckDetails.module.css'

Expand All @@ -10,10 +11,15 @@ export const CheckDetailsView = ({ selectedCheck }) => {
)
}

CheckDetailsView.propTypes = {
selectedCheck: CheckDetails.propTypes.check,
}

const ChooseCheck = () => (
<div className={css.chooseCheckMessage}>
{i18n.t(
'Choose a check to run from the list, or run all checks from the toolbar above'
)}
</div>
)

Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { useConfig } from '@dhis2/app-runtime'
import i18n from '@dhis2/d2-i18n'
import PropTypes from 'prop-types'
import React from 'react'
import css from './CheckDetails.module.css'
import { checkProps } from './checkProps.js'
import { getIssueLink } from './getIssueLink.js'
import { Notice } from './Notice.js'

export const CheckIssues = ({ detailsCheck }) => {
const { baseUrl } = useConfig()
// const maintenance

const numberOfErrors = detailsCheck.issues.length
return (
<Notice
Expand All @@ -28,6 +30,10 @@ export const CheckIssues = ({ detailsCheck }) => {
)
}

CheckIssues.propTypes = {
detailsCheck: checkProps
}

const Issue = ({ issue, issuesIdType, baseUrl }) => {
const { id, name } = issue

Expand All @@ -44,6 +50,12 @@ const Issue = ({ issue, issuesIdType, baseUrl }) => {
)
}

Issue.propTypes = {
baseUrl: PropTypes.string,
issue: PropTypes.shape({ id: PropTypes.string, name: PropTypes.string }),
issuesIdType: PropTypes.string
}

const IssueLink = ({ href, children }) => {
if (!href) {
return children
Expand All @@ -54,3 +66,8 @@ const IssueLink = ({ href, children }) => {
</a>
)
}

IssueLink.propTypes = {
children: PropTypes.node,
href: PropTypes.string,
}
21 changes: 15 additions & 6 deletions src/pages/data-integrity/details/checkProps.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
import propTypes from 'prop-types'

export const checkProps = {
name: propTypes.string.isRequired,
export const checkProps = propTypes.shape({
displayName: propTypes.string.isRequired,
name: propTypes.string.isRequired,
description: propTypes.string,
finishedTime: propTypes.string,
intoduction: propTypes.string,
isSlow: propTypes.bool,
issues: propTypes.arrayOf(
propTypes.shape({
comment: propTypes.string,
id: propTypes.string,
name: propTypes.string,
refs: propTypes.array,
})
),
issuesIdType: propTypes.string,
recommendation: propTypes.string,
section: propTypes.string,
startTime: propTypes.string,
finishedTime: propTypes.string,
Selection: propTypes.string,
isSlow: propTypes.bool,
}
})
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useDataMutation, useDataQuery } from '@dhis2/app-runtime'
import React, { useEffect, useMemo, useCallback } from 'react'
import React, { useEffect, useCallback } from 'react'
import { useLazyInterval } from '../../../hooks/use-poll.js'

const detailsQuery = {
Expand Down
10 changes: 9 additions & 1 deletion src/pages/data-integrity/list/DataIntegrityList.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import PropTypes from 'prop-types'
import React, { useState, useMemo } from 'react'
import { CircularLoaderCentered } from '../../../components/Loading/CircularLoaderCentered.js'
import { CheckDetailsView } from '../details/CheckDetailsView.js'
Expand Down Expand Up @@ -52,7 +53,10 @@ export const DataIntegrityList = () => {
checks={filteredChecks}
/>
)}
<CheckDetailsView key={selectedCheck?.name} selectedCheck={selectedCheck} />
<CheckDetailsView
key={selectedCheck?.name}
selectedCheck={selectedCheck}
/>
</ListDetailsLayout>
</div>
)
Expand All @@ -61,3 +65,7 @@ export const DataIntegrityList = () => {
const ListDetailsLayout = ({ children }) => {
return <div className={css.listDetailsWrapper}>{children}</div>
}

ListDetailsLayout.propTypes = {
children: PropTypes.node,
}
6 changes: 6 additions & 0 deletions src/pages/data-integrity/list/LastRunTime.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useTimeZoneConversion } from '@dhis2/app-runtime'
import i18n from '@dhis2/d2-i18n'
import PropTypes from 'prop-types'
import React from 'react'
import { getRelativeTime } from '../../../utils/relativeTime.js'

Expand All @@ -21,3 +22,8 @@ export const LastRunTime = ({ className, value }) => {
</span>
)
}

LastRunTime.propTypes = {
className: PropTypes.string,
value: PropTypes.string,
}
33 changes: 24 additions & 9 deletions src/pages/data-integrity/list/List.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
import cx from 'classnames'
import PropTypes from 'prop-types'
import React from 'react'
import { LastRunTime } from './LastRunTime.js'
import css from './List.module.css'
import { StatusIcon } from './StatusIcon.js'

export const List = ({ setSelectedCheck, selectedCheck, checks }) => {

return (
<div className={css.list}>
{checks?.map((check) => (
<ListItem
key={check.name}
setSelectedCheck={setSelectedCheck}
check={check}
selected={check.name === selectedCheck?.name}
/>
))}
<ListItem
key={check.name}
setSelectedCheck={setSelectedCheck}
check={check}
selected={check.name === selectedCheck?.name}
/>
))}
</div>
)
}

List.propTypes = {
setSelectedCheck: PropTypes.func.isRequired,
checks: PropTypes.array,
selectedCheck: PropTypes.object,
}

export const ListItem = ({ setSelectedCheck, check, selected }) => {
return (
<div
Expand All @@ -34,8 +40,17 @@ export const ListItem = ({ setSelectedCheck, check, selected }) => {
</div>
</div>
<span className={css.statusIcon}>
<StatusIcon count={check?.runInfo?.count} loading={check.loading} />
<StatusIcon
count={check?.runInfo?.count}
loading={check.loading}
/>
</span>
</div>
)
}

ListItem.propTypes = {
check: PropTypes.object.isRequired,
selected: PropTypes.bool.isRequired,
setSelectedCheck: PropTypes.func.isRequired,
}
10 changes: 10 additions & 0 deletions src/pages/data-integrity/list/ListToolbar.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import i18n from '@dhis2/d2-i18n'
import { Button, Input, SingleSelect, SingleSelectOption } from '@dhis2/ui'
import PropTypes from 'prop-types'
import React from 'react'
import css from './List.module.css'
import { SORT_OPTIONS } from './sorter.js'
Expand Down Expand Up @@ -44,3 +45,12 @@ export const ListToolbar = ({
</div>
)
}

ListToolbar.propTypes = {
filter: PropTypes.string.isRequired,
runningAll: PropTypes.bool.isRequired,
setFilter: PropTypes.func.isRequired,
setSort: PropTypes.func.isRequired,
sort: PropTypes.string.isRequired,
onRunAll: PropTypes.func.isRequired,
}
10 changes: 10 additions & 0 deletions src/pages/data-integrity/list/StatusIcon.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
CircularLoader, IconCheckmarkCircle16, IconErrorFilled16
} from '@dhis2/ui'
import PropTypes from 'prop-types'
import React from 'react'
import css from './List.module.css'

Expand All @@ -13,6 +14,10 @@ export const ErrorIcon = ({ numberOfErrors }) => {
)
}

ErrorIcon.propTypes = {
numberOfErrors: PropTypes.number.isRequired,
}

export const SuccessIcon = () => <IconCheckmarkCircle16 color="green" />

export const LoadingIcon = () => <CircularLoader small />
Expand All @@ -31,3 +36,8 @@ export const StatusIcon = ({ count, loading }) => {
}
return null
}

StatusIcon.propTypes = {
count: PropTypes.number,
loading: PropTypes.bool,
}
20 changes: 13 additions & 7 deletions src/pages/data-integrity/use-data-integrity-summary.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useDataMutation, useDataQuery } from '@dhis2/app-runtime'
import React, { useMemo, useEffect } from 'react'
import React, { useMemo, useEffect, useCallback } from 'react'
import { useLazyInterval } from '../../hooks/use-poll.js'
import { useDataIntegrityChecks } from './use-data-integrity-checks.js'

Expand Down Expand Up @@ -42,14 +42,19 @@ export const useDataIntegritySummary = () => {
} = useDataQuery(summaryQuery)

const { start, cancel, started: isPolling } = useLazyInterval(fetchSummary, 2000)
const [startDataIntegrityCheck, { loading: mutationLoading }] =
const [runMutation, { loading: mutationLoading }] =
useDataMutation(startDataIntegrityCheckMutation, {
onComplete: (data) => {
setLastJob(data.response)
start()
},
})

const startDataIntegrityCheck = useCallback(() => {
setLastJob(null)
runMutation()
}, [runMutation])

const formattedData = useMemo(() => {
if (!checks) {
return
Expand All @@ -58,22 +63,23 @@ export const useDataIntegritySummary = () => {
const mergedRunResult = summaryData ? mergeRunResult(checks, summaryData.result) : checks

return mergedRunResult.map((check) => {
let loading = isPolling
if(check.isSlow) {
return check
}
let loading = isPolling || mutationLoading
if (check.runInfo && lastJob) {
// if check was started after the last job was created, it was propably
// started by last job
const ranByLastJob =
check.runInfo.startTime >= lastJob.created
// slow checks are not run, so don't show loading
loading = !check.isSlow && !ranByLastJob
loading = !ranByLastJob
}

return {
...check,
loading
}
})
}, [summaryData, checks, lastJob, isPolling])
}, [summaryData, checks, lastJob, isPolling, mutationLoading])

useEffect(() => {
if (summaryError || formattedData?.every((check) => !check.loading)) {
Expand Down

0 comments on commit 9bf677b

Please sign in to comment.