Skip to content

Commit

Permalink
feat: Add Legacy Report View
Browse files Browse the repository at this point in the history
* Add new brancher to control legacy vs non-legacy view
* Split HistoryCard to its own component for re-usability and add tests
* Update legacy view with legacy assessment card
* Sent legacy_id to the front end
  • Loading branch information
dhaselhan committed Dec 18, 2024
1 parent 38c46c1 commit 9f529de
Show file tree
Hide file tree
Showing 18 changed files with 1,103 additions and 246 deletions.
2 changes: 1 addition & 1 deletion backend/lcfs/web/api/compliance_report/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class CompliancePeriodSchema(BaseSchema):
display_order: Optional[int] = None



class SummarySchema(BaseSchema):
summary_id: int
is_locked: bool
Expand Down Expand Up @@ -154,6 +153,7 @@ class ComplianceReportBaseSchema(BaseSchema):
update_date: Optional[datetime] = None
history: Optional[List[ComplianceReportHistorySchema]] = None
has_supplemental: bool
legacy_id: Optional[int] = None


class ChainedComplianceReportSchema(BaseSchema):
Expand Down
1 change: 1 addition & 0 deletions frontend/public/config/config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export const config = {
api_base: 'http://localhost:8000/api',
tfrs_base: 'http://localhost:3001',
keycloak: {
REALM: 'standard',
CLIENT_ID: 'low-carbon-fuel-standard-5147',
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import { AddEditFuelExports } from './views/FuelExports/AddEditFuelExports'
import { AddEditAllocationAgreements } from './views/AllocationAgreements/AddEditAllocationAgreements'
import { logout } from '@/utils/keycloak.js'
import { CompareReports } from '@/views/CompareReports/CompareReports'
import { ViewLegacyComplianceReport } from '@/views/ComplianceReports/ViewLegacyComplianceReport.jsx'
import { ViewComplianceReportBrancher } from '@/views/ComplianceReports/ViewComplianceReportBrancher.jsx'

const router = createBrowserRouter([
{
Expand Down Expand Up @@ -196,7 +198,7 @@ const router = createBrowserRouter([
},
{
path: ROUTES.REPORTS_VIEW,
element: <EditViewComplianceReport />,
element: <ViewComplianceReportBrancher />,
handle: { title: '' }
},
{
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/assets/locales/en/reports.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,5 +158,6 @@
"totalValue": "Total Value"
},
"summaryLoadingMsg": "Loading compliance report summary...",
"noSigningAuthorityTooltip": "Signing authority role required."
"noSigningAuthorityTooltip": "Signing authority role required.",
"viewLegacyBtn": "View Full Historical Report in TFRS"
}
1 change: 1 addition & 0 deletions frontend/src/constants/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const FEATURE_FLAGS = {

export const CONFIG = {
API_BASE: getApiBaseUrl(),
TFRS_BASE: window.lcfs_config.tfrs_base,
KEYCLOAK: {
REALM: window.lcfs_config.keycloak.REALM ?? 'standard',
CLIENT_ID:
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/constants/routes/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ export const ORGANIZATIONS_EDITUSER = `${ORGANIZATIONS_VIEWUSER}/edit-user`

export const REPORTS = '/compliance-reporting'
export const REPORTS_VIEW = `${REPORTS}/:compliancePeriod/:complianceReportId`
export const REPORTS_COMPARE = `/compare-reporting`
export const REPORTS_ADD_SUPPLY_OF_FUEL = `${REPORTS_VIEW}/supply-of-fuel`
export const REPORTS_ADD_FINAL_SUPPLY_EQUIPMENTS = `${REPORTS_VIEW}/final-supply-equipments`
export const REPORTS_ADD_ALLOCATION_AGREEMENTS = `${REPORTS_VIEW}/allocation-agreements`
export const REPORTS_ADD_NOTIONAL_TRANSFERS = `${REPORTS_VIEW}/notional-transfers`
export const REPORTS_ADD_OTHER_USE_FUELS = `${REPORTS_VIEW}/fuels-other-use`
export const REPORTS_ADD_FUEL_EXPORTS = `${REPORTS_VIEW}/fuel-exports`
export const REPORTS_COMPARE = '/compare-reporting'

export const NOTIFICATIONS = '/notifications'
export const NOTIFICATIONS_SETTINGS = `${NOTIFICATIONS}/configure`
Expand Down
18 changes: 8 additions & 10 deletions frontend/src/views/ComplianceReports/ComplianceReports.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ import BCBox from '@/components/BCBox'
import BCAlert from '@/components/BCAlert'
import BCDataGridServer from '@/components/BCDataGrid/BCDataGridServer'
// react components
import { useEffect, useMemo, useRef, useState, useCallback } from 'react'
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { useLocation, useNavigate } from 'react-router-dom'
// Services
import { Role } from '@/components/Role'
// constants
import { roles } from '@/constants/roles'
import { ROUTES, apiRoutes } from '@/constants/routes'
import { apiRoutes, ROUTES } from '@/constants/routes'
import { COMPLIANCE_REPORT_STATUSES } from '@/constants/statuses'
// hooks
import { useCurrentUser } from '@/hooks/useCurrentUser'
import { useCreateComplianceReport } from '@/hooks/useComplianceReports'
// internal components
import { reportsColDefs, defaultSortModel } from './components/_schema'
import { defaultSortModel, reportsColDefs } from './components/_schema'
import { NewComplianceReportButton } from './components/NewComplianceReportButton'
import BCTypography from '@/components/BCTypography'

Expand All @@ -44,15 +44,13 @@ export const ComplianceReports = () => {
(params) => params.data.complianceReportId.toString(),
[]
)
// eslint-disable-next-line react-hooks/exhaustive-deps
const handleRowClicked = useCallback(
({ data }) => {
navigate(
ROUTES.REPORTS_VIEW.replace(
':compliancePeriod',
data.compliancePeriod.description
).replace(':complianceReportId', data.complianceReportId)
)
const mappedRoute = ROUTES.REPORTS_VIEW.replace(
':compliancePeriod',
data.compliancePeriod.description
).replace(':complianceReportId', data.complianceReportId)
navigate(mappedRoute)
},
[navigate]
)
Expand Down
18 changes: 3 additions & 15 deletions frontend/src/views/ComplianceReports/EditViewComplianceReport.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ import { useTranslation } from 'react-i18next'
import { useCurrentUser } from '@/hooks/useCurrentUser'
import { useOrganization } from '@/hooks/useOrganization'
import { Introduction } from './components/Introduction'
import {
useGetComplianceReport,
useUpdateComplianceReport
} from '@/hooks/useComplianceReports'
import { useUpdateComplianceReport } from '@/hooks/useComplianceReports'
import ComplianceReportSummary from './components/ComplianceReportSummary'
import ReportDetails from './components/ReportDetails'
import { buttonClusterConfigFn } from './buttonConfigs'
Expand All @@ -35,7 +32,7 @@ const iconStyle = {
height: '2rem',
color: colors.white.main
}
export const EditViewComplianceReport = () => {
export const EditViewComplianceReport = ({ reportData, isError, error }) => {
const { t } = useTranslation(['common', 'report'])
const location = useLocation()
const [modalData, setModalData] = useState(null)
Expand Down Expand Up @@ -83,15 +80,6 @@ export const EditViewComplianceReport = () => {
hasRoles
} = useCurrentUser()
const isGovernmentUser = currentUser?.isGovernmentUser
const {
data: reportData,
isLoading: isReportLoading,
isError,
error
} = useGetComplianceReport(
currentUser?.organization?.organizationId,
complianceReportId
)

const currentStatus = reportData?.report.currentStatus?.status
const { data: orgData, isLoading } = useOrganization(
Expand Down Expand Up @@ -158,7 +146,7 @@ export const EditViewComplianceReport = () => {
}
}, [location.state, isError, error])

if (isLoading || isReportLoading || isCurrentUserLoading) {
if (isLoading || isCurrentUserLoading) {
return <Loading />
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { useGetComplianceReport } from '@/hooks/useComplianceReports.js'
import { useCurrentUser } from '@/hooks/useCurrentUser.js'
import Loading from '@/components/Loading.jsx'
import { ViewLegacyComplianceReport } from '@/views/ComplianceReports/ViewLegacyComplianceReport.jsx'
import { useParams } from 'react-router-dom'
import { EditViewComplianceReport } from '@/views/ComplianceReports/EditViewComplianceReport.jsx'

export const ViewComplianceReportBrancher = () => {
const { complianceReportId } = useParams()
const { data: currentUser, isLoading: isCurrentUserLoading } =
useCurrentUser()

const {
data: reportData,
isLoading: isReportLoading,
isError,
error
} = useGetComplianceReport(
currentUser?.organization?.organizationId,
complianceReportId
)

if (isReportLoading || isCurrentUserLoading) {
return <Loading />
}

return reportData.report.legacyId ? (
<ViewLegacyComplianceReport
reportData={reportData}
error={error}
isError={isError}
/>
) : (
<EditViewComplianceReport
reportData={reportData}
error={error}
isError={isError}
/>
)
}
143 changes: 143 additions & 0 deletions frontend/src/views/ComplianceReports/ViewLegacyComplianceReport.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import { useCallback, useEffect, useRef, useState } from 'react'
import { FloatingAlert } from '@/components/BCAlert'
import BCBox from '@/components/BCBox'
import BCModal from '@/components/BCModal'
import Loading from '@/components/Loading'
import { Fab, Stack, Tooltip } from '@mui/material'
import BCTypography from '@/components/BCTypography'
import KeyboardArrowUpIcon from '@mui/icons-material/KeyboardArrowUp'
import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown'
import colors from '@/themes/base/colors.js'
import { useTranslation } from 'react-i18next'
import { useCurrentUser } from '@/hooks/useCurrentUser'
import { useOrganization } from '@/hooks/useOrganization'
import { LegacyAssessmentCard } from '@/views/ComplianceReports/components/LegacyAssessmentCard.jsx'

const iconStyle = {
width: '2rem',
height: '2rem',
color: colors.white.main
}
export const ViewLegacyComplianceReport = ({ reportData, error, isError }) => {
const { t } = useTranslation(['common', 'report'])
const [modalData, setModalData] = useState(null)
const alertRef = useRef()

const [isScrollingUp, setIsScrollingUp] = useState(false)
const [lastScrollTop, setLastScrollTop] = useState(0)

const scrollToTopOrBottom = () => {
if (isScrollingUp) {
window.scrollTo({
top: 0,
behavior: 'smooth'
})
} else {
window.scrollTo({
top: document.documentElement.scrollHeight,
behavior: 'smooth'
})
}
}

const handleScroll = useCallback(() => {
const scrollTop = window.pageYOffset || document.documentElement.scrollTop
setIsScrollingUp(scrollTop < lastScrollTop || scrollTop === 0)
setLastScrollTop(scrollTop)
}, [lastScrollTop])

useEffect(() => {
window.addEventListener('scroll', handleScroll)
return () => window.removeEventListener('scroll', handleScroll)
}, [handleScroll])

const { data: currentUser, isLoading: isCurrentUserLoading } =
useCurrentUser()
const isGovernmentUser = currentUser?.isGovernmentUser

const currentStatus = reportData.report.currentStatus?.status
const { data: orgData, isLoading } = useOrganization(
reportData.report.organizationId
)

if (isLoading || isCurrentUserLoading) {
return <Loading />
}

if (isError) {
return (
<>
<FloatingAlert ref={alertRef} data-test="alert-box" delay={10000} />
<BCTypography color="error">{t('report:errorRetrieving')}</BCTypography>
</>
)
}

return (
<>
<FloatingAlert ref={alertRef} data-test="alert-box" delay={10000} />
<BCBox pl={2} pr={2}>
<BCModal
open={!!modalData}
onClose={() => setModalData(null)}
data={modalData}
/>
<BCBox pb={2}>
<BCTypography
data-test="compliance-report-header"
variant="h5"
color="primary"
>
{reportData?.report.compliancePeriod.description}&nbsp;
{t('report:complianceReport')}&#32;-&#32;
{reportData?.report.nickname}
</BCTypography>
<BCTypography
variant="h6"
color="primary"
style={{ marginLeft: '0.25rem' }}
data-test="compliance-report-status"
>
Status: {currentStatus}
</BCTypography>
</BCBox>
<Stack direction="column" mt={2}>
<LegacyAssessmentCard
orgData={orgData}
history={reportData?.report.history}
isGovernmentUser={isGovernmentUser}
currentStatus={currentStatus}
legacyReportId={reportData?.report.legacyId}
hasSupplemental={reportData?.report.hasSupplemental}
chain={reportData.chain}
/>
</Stack>
<Tooltip
title={
isScrollingUp ? t('common:scrollToTop') : t('common:scrollToBottom')
}
placement="left"
arrow
>
<Fab
color="secondary"
size="large"
aria-label={isScrollingUp ? 'scroll to top' : 'scroll to bottom'}
onClick={scrollToTopOrBottom}
sx={{
position: 'fixed',
bottom: 75,
right: 24
}}
>
{isScrollingUp ? (
<KeyboardArrowUpIcon sx={iconStyle} />
) : (
<KeyboardArrowDownIcon sx={iconStyle} />
)}
</Fab>
</Tooltip>
</BCBox>
</>
)
}
Loading

0 comments on commit 9f529de

Please sign in to comment.