From 33f0a077ba16b83325daf47f296b1e5a7d6e5a86 Mon Sep 17 00:00:00 2001 From: Birk Johansson Date: Fri, 9 Feb 2024 15:05:10 +0100 Subject: [PATCH] fix: refactor - expandable run summary --- .../data-integrity/details/CheckDetails.js | 11 -- .../details/CheckDetails.module.css | 18 ++- .../details/CheckRunCompleted.js | 109 ++++++++++++++++++ .../data-integrity/details/CheckRunContent.js | 55 +-------- 4 files changed, 127 insertions(+), 66 deletions(-) create mode 100644 src/pages/data-integrity/details/CheckRunCompleted.js diff --git a/src/pages/data-integrity/details/CheckDetails.js b/src/pages/data-integrity/details/CheckDetails.js index ec559f50..9e3d285e 100644 --- a/src/pages/data-integrity/details/CheckDetails.js +++ b/src/pages/data-integrity/details/CheckDetails.js @@ -62,17 +62,6 @@ CheckDetails.propTypes = { check: checkProps, } -export const DetailsHeader = ({ name, description }) => { - return ( -
-

{name}

-

{description}

-
- ) -} - -DetailsHeader.propTypes = {} - const DetailsError = () => { return ( diff --git a/src/pages/data-integrity/details/CheckDetails.module.css b/src/pages/data-integrity/details/CheckDetails.module.css index 538af648..e502ebc3 100644 --- a/src/pages/data-integrity/details/CheckDetails.module.css +++ b/src/pages/data-integrity/details/CheckDetails.module.css @@ -7,6 +7,7 @@ flex-direction: column; gap: var(--spacers-dp12); } + .checkInfo header button { flex-shrink: 0; flex-grow: 0; @@ -30,6 +31,7 @@ display: flex; gap: 80px; } + .keyInfo { display: flex; flex-direction: column; @@ -90,7 +92,10 @@ } .runCompletedWrapper { - padding: 16px 0px 8px 0px; + display: flex; + flex-direction: column; + gap: var(--spacers-dp8); + padding: var(--spacers-dp16) 0px var(--spacers-dp8); } .runCompletedWrapper header { @@ -100,14 +105,21 @@ gap: 16px; } -.runCompletedContent { +.runSummary { display: flex; flex-direction: column; gap: 8px; padding: 12px; } -.completedTime { +.completedTimeWrapper { + display: flex; + align-items: center; + justify-content: space-between; + transition: all 0.3s; +} + +.completedDuration { color: var(--colors-grey700); font-size: 12px; } diff --git a/src/pages/data-integrity/details/CheckRunCompleted.js b/src/pages/data-integrity/details/CheckRunCompleted.js new file mode 100644 index 00000000..d51a85c7 --- /dev/null +++ b/src/pages/data-integrity/details/CheckRunCompleted.js @@ -0,0 +1,109 @@ +import { useTimeZoneConversion } from '@dhis2/app-runtime' +import i18n from '@dhis2/d2-i18n' +import { IconChevronDown24, IconChevronUp24, NoticeBox } from '@dhis2/ui' +import PropTypes from 'prop-types' +import React, { 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 './CheckIssues.js' +import { checkProps } from './checkProps.js' +import { Notice } from './Notice.js' + +export const CheckRunCompleted = ({ detailsCheck }) => { + const [expandSummary, setExpandSummary] = useState(true) + + const passed = detailsCheck.issues.length === 0 + + return ( +
+ {!passed && ( + {detailsCheck.recommendation} + )} +
setExpandSummary((prev) => !prev)} + > + + {expandSummary ? : } +
+ {expandSummary && } +
+ ) +} + +CheckRunCompleted.propTypes = { + detailsCheck: checkProps, +} + +const RunSummary = ({ detailsCheck }) => { + const jobDurationMs = + new Date(detailsCheck.finishedTime).getTime() - + new Date(detailsCheck.startTime).getTime() + + const passed = detailsCheck.issues.length === 0 + + return ( +
+ {passed ? ( + + ) : ( + + )} +
+ {i18n.t('Completed in {{time}}', { + time: getDurationWithUnitFromDelta(jobDurationMs), + })} +
+
+ ) +} + +RunSummary.propTypes = { + detailsCheck: checkProps, +} + +const CompletedTime = ({ issuesCount, finishedTime }) => { + const { fromServerDate } = useTimeZoneConversion() + + const latestRun = fromServerDate(finishedTime) + const formattedLatestRun = Intl.DateTimeFormat([selectedLocale], { + dateStyle: 'short', + timeStyle: 'short', + }).format(latestRun) + + return ( +
+ {i18n.t('Latest run completed {{time}}', { + time: formattedLatestRun, + interpolation: { escapeValue: false }, + })} + +
+ ) +} + +CompletedTime.propTypes = { + finishedTime: PropTypes.string, + issuesCount: PropTypes.number, +} + +const CheckRunSuccess = () => { + return {i18n.t('Passed with 0 errors.')} +} + +const Recommendation = ({ children }) => ( + {children} +) + +Recommendation.propTypes = { + children: PropTypes.node, +} diff --git a/src/pages/data-integrity/details/CheckRunContent.js b/src/pages/data-integrity/details/CheckRunContent.js index d18bf235..09ab24bd 100644 --- a/src/pages/data-integrity/details/CheckRunContent.js +++ b/src/pages/data-integrity/details/CheckRunContent.js @@ -3,13 +3,10 @@ import i18n from '@dhis2/d2-i18n' import PropTypes from 'prop-types' import React, { useEffect, useState } from 'react' import { - getDurationWithUnitFromDelta, - selectedLocale, + getDurationWithUnitFromDelta } from '../../../utils/relativeTime.js' -import { StatusIcon } from '../list/StatusIcon.js' -import css from './CheckDetails.module.css' -import { CheckIssues } from './CheckIssues.js' import { checkProps } from './checkProps.js' +import { CheckRunCompleted } from './CheckRunCompleted.js' import { Notice } from './Notice.js' export const CheckRunContent = ({ @@ -34,7 +31,7 @@ export const CheckRunContent = ({ return } - return + return } CheckRunContent.propTypes = { @@ -44,52 +41,6 @@ CheckRunContent.propTypes = { summaryCheck: checkProps, } -const DetailsRunCompleted = ({ detailsCheck }) => { - const { fromServerDate } = useTimeZoneConversion() - - const latestRun = fromServerDate(detailsCheck.finishedTime) - - const formattedLatestRun = Intl.DateTimeFormat([selectedLocale], { - dateStyle: 'short', - timeStyle: 'short', - }).format(latestRun) - - const durationMs = - fromServerDate(detailsCheck.finishedTime).getTime() - - fromServerDate(detailsCheck.startTime).getTime() - - return ( -
-
- {i18n.t('Latest run completed {{time}}', { - time: formattedLatestRun, - interpolation: { escapeValue: false }, - })} - -
-
- {detailsCheck.issues.length === 0 ? ( - - ) : ( - - )} -
- {i18n.t('Completed in {{time}}', { - time: getDurationWithUnitFromDelta(durationMs), - })} -
-
-
- ) -} - -DetailsRunCompleted.propTypes = { - detailsCheck: checkProps, -} - -const DetailsRunSuccess = () => { - return {i18n.t('Passed with 0 errors.')} -} const DetailsRunLoading = ({ detailsCheck, summaryCheck, currentJob }) => { const [, setTime] = useState(Date.now())