-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
259 additions
and
413 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,97 @@ | ||
import { useDataQuery } from '@dhis2/app-runtime' | ||
import i18n from '@dhis2/d2-i18n' | ||
import { Button, NoticeBox } from '@dhis2/ui' | ||
import { CenteredContent, CircularLoader, Button, NoticeBox } from '@dhis2/ui' | ||
import PropTypes from 'prop-types' | ||
import React from 'react' | ||
import React, { useState } from 'react' | ||
import PageHeader from '../../components/PageHeader/PageHeader' | ||
import { i18nKeys } from '../../i18n-keys' | ||
import Issues from './Issues/Issues' | ||
import { useDataIntegrity } from './use-data-integrity' | ||
import styles from './DataIntegrity.module.css' | ||
import Section from './Section' | ||
|
||
const DataIntegrity = ({ sectionKey }) => { | ||
const { | ||
startDataIntegrityCheck, | ||
loading, | ||
error, | ||
issues, | ||
} = useDataIntegrity() | ||
const query = { | ||
checks: { | ||
resource: 'dataIntegrity', | ||
}, | ||
} | ||
|
||
const groupChecks = checks => | ||
checks.reduce((groupedChecks, check) => { | ||
if (!(check.section in groupedChecks)) { | ||
groupedChecks[check.section] = [] | ||
} | ||
groupedChecks[check.section].push(check) | ||
return groupedChecks | ||
}, {}) | ||
|
||
const DataIntegrity = () => { | ||
const { loading, error, data } = useDataQuery(query) | ||
const [selectedChecks, setSelectedChecks] = useState(new Set()) | ||
// XXX | ||
const [submitting, setSubmitting] = useState(false) | ||
|
||
const startDataIntegrityCheck = () => { | ||
setSubmitting(true) | ||
} | ||
|
||
if (loading) { | ||
return ( | ||
<CenteredContent> | ||
<CircularLoader /> | ||
</CenteredContent> | ||
) | ||
} | ||
|
||
if (error) { | ||
return ( | ||
<NoticeBox | ||
title={i18n.t('Failed to load available data integrity checks')} | ||
error | ||
className={styles.noticeBox} | ||
> | ||
{error.message} | ||
</NoticeBox> | ||
) | ||
} | ||
|
||
const groupedChecks = groupChecks(data.checks) | ||
|
||
return ( | ||
<> | ||
<PageHeader | ||
sectionKey={sectionKey} | ||
title={i18nKeys.dataIntegrity.title} | ||
/> | ||
{error && <NoticeBox error>{error.message}</NoticeBox>} | ||
{issues && <Issues issues={issues} />} | ||
<Button primary loading={loading} onClick={startDataIntegrityCheck}> | ||
{loading | ||
{Object.entries(groupedChecks).map(([section, checks]) => ( | ||
<Section | ||
key={section} | ||
name={section} | ||
checks={checks} | ||
selectedChecks={selectedChecks} | ||
setSelectedChecks={setSelectedChecks} | ||
/> | ||
))} | ||
<Button | ||
primary | ||
disabled={selectedChecks.size === 0} | ||
loading={submitting} | ||
onClick={startDataIntegrityCheck} | ||
> | ||
{submitting | ||
? i18n.t('Checking data integrity...') | ||
: i18n.t('Run integrity checks')} | ||
</Button> | ||
</> | ||
) | ||
} | ||
|
||
DataIntegrity.propTypes = { | ||
const DataIntegrityPage = ({ sectionKey }) => ( | ||
<> | ||
<PageHeader | ||
sectionKey={sectionKey} | ||
title={i18nKeys.dataIntegrity.title} | ||
/> | ||
<DataIntegrity /> | ||
</> | ||
) | ||
|
||
DataIntegrityPage.propTypes = { | ||
sectionKey: PropTypes.string.isRequired, | ||
} | ||
|
||
export default DataIntegrity | ||
export default DataIntegrityPage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.noticeBox { | ||
max-width: 400px; | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.