Skip to content

Commit

Permalink
feat: refine report history display to show only meaningful entries
Browse files Browse the repository at this point in the history
  • Loading branch information
hamed-valiollahi committed Jan 6, 2025
1 parent 6049bb1 commit afbc672
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 18 deletions.
45 changes: 27 additions & 18 deletions frontend/src/views/ComplianceReports/components/AssessmentCard.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useMemo } from 'react'
import BCButton from '@/components/BCButton'
import BCTypography from '@/components/BCTypography'
import BCWidgetCard from '@/components/BCWidgetCard/BCWidgetCard'
Expand All @@ -23,7 +24,7 @@ export const AssessmentCard = ({
currentStatus,
complianceReportId,
alertRef,
chain
chain = []
}) => {
const { t } = useTranslation(['report'])
const navigate = useNavigate()
Expand Down Expand Up @@ -52,6 +53,14 @@ export const AssessmentCard = ({
}
})

const filteredChain = useMemo(() => {
return chain.filter((report) => {
const isDraft = report.currentStatus.status === COMPLIANCE_REPORT_STATUSES.DRAFT
const hasHistory = report.history && report.history.length > 0
return !isDraft && hasHistory
})
}, [chain])

return (
<BCWidgetCard
component="div"
Expand Down Expand Up @@ -108,13 +117,13 @@ export const AssessmentCard = ({
<StyledListItem>
<ListItemText primaryTypographyProps={{ variant: 'body4' }}>
<span
dangerouslySetInnerHTML={{
__html: t('report:assessmentLn1', {
name: orgData.name,
hasMet: hasMet ? 'has met' : 'has not met'
})
}}
/>
dangerouslySetInnerHTML={{
__html: t('report:assessmentLn1', {
name: orgData.name,
hasMet: hasMet ? 'has met' : 'has not met'
})
}}
/>
</ListItemText>
</StyledListItem>
</List>
Expand All @@ -129,19 +138,19 @@ export const AssessmentCard = ({
<StyledListItem>
<ListItemText primaryTypographyProps={{ variant: 'body4' }}>
<span
dangerouslySetInnerHTML={{
__html: t('report:assessmentLn2', {
name: orgData.name,
hasMet: hasMet ? 'has met' : 'has not met'
})
}}
/>
dangerouslySetInnerHTML={{
__html: t('report:assessmentLn2', {
name: orgData.name,
hasMet: hasMet ? 'has met' : 'has not met'
})
}}
/>
</ListItemText>
</StyledListItem>
</List>
</>
)}
{!!chain.length && (
{filteredChain.length > 0 && (
<>
<BCTypography
sx={{ paddingTop: '16px' }}
Expand All @@ -151,7 +160,7 @@ export const AssessmentCard = ({
>
{t('report:reportHistory')}
</BCTypography>
{chain.map((report) => (
{filteredChain.map((report) => (
<HistoryCard key={report.version} report={report} />
))}
</>
Expand All @@ -165,7 +174,7 @@ export const AssessmentCard = ({
sx={{ paddingTop: '16px' }}
component="div"
variant="body4"
>
>
{t('report:supplementalWarning')}
</BCTypography>
<Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ export const HistoryCard = ({ report }) => {
})
.filter((item) => item.status.status !== COMPLIANCE_REPORT_STATUSES.DRAFT)
}, [isGovernmentUser, report.history])

// If there's no content to show, return null
if (filteredHistory.length === 0) {
return null
}

return (
<Accordion>
<AccordionSummary
Expand Down

0 comments on commit afbc672

Please sign in to comment.