Skip to content

Commit

Permalink
Merge pull request #1482 from bcgov/feat/daniel-legacy-report-view-1396
Browse files Browse the repository at this point in the history
feat: Add Legacy Report View
  • Loading branch information
dhaselhan authored Dec 19, 2024
2 parents 2dca338 + 60b16dd commit a98abf4
Show file tree
Hide file tree
Showing 22 changed files with 1,155 additions and 267 deletions.
3 changes: 3 additions & 0 deletions backend/lcfs/services/rabbitmq/report_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ async def handle_message(
)
user = await UserRepository(db=session).get_user_by_id(user_id)

if not user:
logger.error(f"Cannot parse Report {legacy_id} from TFRS, no user with ID {user_id}")

if action == "Created":
await self._handle_created(
org_id,
Expand Down
2 changes: 1 addition & 1 deletion backend/lcfs/tests/fuel_export/test_fuel_exports_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ async def test_update_fuel_export_success(fuel_export_repo, mock_db):
)
updated_fuel_export = FuelExport(fuel_export_id=1)

mock_db.merge = MagicMock(return_value=updated_fuel_export)
mock_db.merge = AsyncMock(return_value=updated_fuel_export)
mock_db.flush = AsyncMock()
mock_db.refresh = AsyncMock()

Expand Down
66 changes: 47 additions & 19 deletions backend/lcfs/web/api/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,6 @@ def validate_pagination(pagination: PaginationRequestSchema):
Args:
pagination (PaginationRequestSchema): The pagination object to validate.
"""
logger.info("Validating pagination")
logger.debug("Pagination details", pagination=pagination)

if not pagination.page or pagination.page < 1:
pagination.page = 1
if not pagination.size or pagination.size < 1:
Expand Down Expand Up @@ -373,24 +370,55 @@ async def lcfs_cache_key_builder(
# Return the cache key
return cache_key


class NotificationTypeEnum(Enum):
BCEID__COMPLIANCE_REPORT__DIRECTOR_ASSESSMENT = "BCEID__COMPLIANCE_REPORT__DIRECTOR_ASSESSMENT"
BCEID__INITIATIVE_AGREEMENT__DIRECTOR_APPROVAL = "BCEID__INITIATIVE_AGREEMENT__DIRECTOR_APPROVAL"
BCEID__COMPLIANCE_REPORT__DIRECTOR_ASSESSMENT = (
"BCEID__COMPLIANCE_REPORT__DIRECTOR_ASSESSMENT"
)
BCEID__INITIATIVE_AGREEMENT__DIRECTOR_APPROVAL = (
"BCEID__INITIATIVE_AGREEMENT__DIRECTOR_APPROVAL"
)
BCEID__TRANSFER__DIRECTOR_DECISION = "BCEID__TRANSFER__DIRECTOR_DECISION"
BCEID__TRANSFER__PARTNER_ACTIONS = "BCEID__TRANSFER__PARTNER_ACTIONS"
IDIR_ANALYST__COMPLIANCE_REPORT__DIRECTOR_DECISION = "IDIR_ANALYST__COMPLIANCE_REPORT__DIRECTOR_DECISION"
IDIR_ANALYST__COMPLIANCE_REPORT__MANAGER_RECOMMENDATION = "IDIR_ANALYST__COMPLIANCE_REPORT__MANAGER_RECOMMENDATION"
IDIR_ANALYST__COMPLIANCE_REPORT__SUBMITTED_FOR_REVIEW = "IDIR_ANALYST__COMPLIANCE_REPORT__SUBMITTED_FOR_REVIEW"
IDIR_ANALYST__INITIATIVE_AGREEMENT__RETURNED_TO_ANALYST = "IDIR_ANALYST__INITIATIVE_AGREEMENT__RETURNED_TO_ANALYST"
IDIR_ANALYST__TRANSFER__DIRECTOR_RECORDED = "IDIR_ANALYST__TRANSFER__DIRECTOR_RECORDED"
IDIR_ANALYST__TRANSFER__RESCINDED_ACTION = "IDIR_ANALYST__TRANSFER__RESCINDED_ACTION"
IDIR_ANALYST__TRANSFER__SUBMITTED_FOR_REVIEW = "IDIR_ANALYST__TRANSFER__SUBMITTED_FOR_REVIEW"
IDIR_COMPLIANCE_MANAGER__COMPLIANCE_REPORT__ANALYST_RECOMMENDATION = "IDIR_COMPLIANCE_MANAGER__COMPLIANCE_REPORT__ANALYST_RECOMMENDATION"
IDIR_COMPLIANCE_MANAGER__COMPLIANCE_REPORT__DIRECTOR_ASSESSMENT = "IDIR_COMPLIANCE_MANAGER__COMPLIANCE_REPORT__DIRECTOR_ASSESSMENT"
IDIR_COMPLIANCE_MANAGER__COMPLIANCE_REPORT__SUBMITTED_FOR_REVIEW = "IDIR_COMPLIANCE_MANAGER__COMPLIANCE_REPORT__SUBMITTED_FOR_REVIEW"
IDIR_DIRECTOR__COMPLIANCE_REPORT__MANAGER_RECOMMENDATION = "IDIR_DIRECTOR__COMPLIANCE_REPORT__MANAGER_RECOMMENDATION"
IDIR_DIRECTOR__INITIATIVE_AGREEMENT__ANALYST_RECOMMENDATION = "IDIR_DIRECTOR__INITIATIVE_AGREEMENT__ANALYST_RECOMMENDATION"
IDIR_DIRECTOR__TRANSFER__ANALYST_RECOMMENDATION = "IDIR_DIRECTOR__TRANSFER__ANALYST_RECOMMENDATION"
IDIR_ANALYST__COMPLIANCE_REPORT__DIRECTOR_DECISION = (
"IDIR_ANALYST__COMPLIANCE_REPORT__DIRECTOR_DECISION"
)
IDIR_ANALYST__COMPLIANCE_REPORT__MANAGER_RECOMMENDATION = (
"IDIR_ANALYST__COMPLIANCE_REPORT__MANAGER_RECOMMENDATION"
)
IDIR_ANALYST__COMPLIANCE_REPORT__SUBMITTED_FOR_REVIEW = (
"IDIR_ANALYST__COMPLIANCE_REPORT__SUBMITTED_FOR_REVIEW"
)
IDIR_ANALYST__INITIATIVE_AGREEMENT__RETURNED_TO_ANALYST = (
"IDIR_ANALYST__INITIATIVE_AGREEMENT__RETURNED_TO_ANALYST"
)
IDIR_ANALYST__TRANSFER__DIRECTOR_RECORDED = (
"IDIR_ANALYST__TRANSFER__DIRECTOR_RECORDED"
)
IDIR_ANALYST__TRANSFER__RESCINDED_ACTION = (
"IDIR_ANALYST__TRANSFER__RESCINDED_ACTION"
)
IDIR_ANALYST__TRANSFER__SUBMITTED_FOR_REVIEW = (
"IDIR_ANALYST__TRANSFER__SUBMITTED_FOR_REVIEW"
)
IDIR_COMPLIANCE_MANAGER__COMPLIANCE_REPORT__ANALYST_RECOMMENDATION = (
"IDIR_COMPLIANCE_MANAGER__COMPLIANCE_REPORT__ANALYST_RECOMMENDATION"
)
IDIR_COMPLIANCE_MANAGER__COMPLIANCE_REPORT__DIRECTOR_ASSESSMENT = (
"IDIR_COMPLIANCE_MANAGER__COMPLIANCE_REPORT__DIRECTOR_ASSESSMENT"
)
IDIR_COMPLIANCE_MANAGER__COMPLIANCE_REPORT__SUBMITTED_FOR_REVIEW = (
"IDIR_COMPLIANCE_MANAGER__COMPLIANCE_REPORT__SUBMITTED_FOR_REVIEW"
)
IDIR_DIRECTOR__COMPLIANCE_REPORT__MANAGER_RECOMMENDATION = (
"IDIR_DIRECTOR__COMPLIANCE_REPORT__MANAGER_RECOMMENDATION"
)
IDIR_DIRECTOR__INITIATIVE_AGREEMENT__ANALYST_RECOMMENDATION = (
"IDIR_DIRECTOR__INITIATIVE_AGREEMENT__ANALYST_RECOMMENDATION"
)
IDIR_DIRECTOR__TRANSFER__ANALYST_RECOMMENDATION = (
"IDIR_DIRECTOR__TRANSFER__ANALYST_RECOMMENDATION"
)

def __str__(self):
return self.value
return self.value
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
2 changes: 1 addition & 1 deletion backend/lcfs/web/api/fuel_export/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ async def update_fuel_export(self, fuel_export: FuelExport) -> FuelExport:
"""
Update an existing fuel supply row in the database.
"""
updated_fuel_export = self.db.merge(fuel_export)
updated_fuel_export = await self.db.merge(fuel_export)
await self.db.flush()
await self.db.refresh(
updated_fuel_export,
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:3000',
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 { ComplianceReportViewSelector } from '@/views/ComplianceReports/ComplianceReportViewSelector.jsx'

const router = createBrowserRouter([
{
Expand Down Expand Up @@ -196,7 +198,7 @@ const router = createBrowserRouter([
},
{
path: ROUTES.REPORTS_VIEW,
element: <EditViewComplianceReport />,
element: <ComplianceReportViewSelector />,
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
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 ComplianceReportViewSelector = () => {
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}
/>
)
}
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
Loading

0 comments on commit a98abf4

Please sign in to comment.