From f876f05365e1a83917e0bec5d0b69f4e8a38ceb2 Mon Sep 17 00:00:00 2001 From: prv-proton Date: Tue, 7 Jan 2025 18:23:05 -0800 Subject: [PATCH 1/4] Fix: LCFS BUG - Navigating directly to organization detail errors #1586 --- frontend/src/assets/locales/en/fuelCode.json | 2 +- frontend/src/components/Login.jsx | 2 ++ .../ViewOrganization/ViewOrganization.jsx | 13 +++++-------- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/frontend/src/assets/locales/en/fuelCode.json b/frontend/src/assets/locales/en/fuelCode.json index e1948199c..701a6231e 100644 --- a/frontend/src/assets/locales/en/fuelCode.json +++ b/frontend/src/assets/locales/en/fuelCode.json @@ -31,7 +31,7 @@ "company": "Company", "contactName": "Contact name", "contactEmail": "Contact email", - "carbonIntensity": "Carbon intensity (gCO²e/MJ)", + "carbonIntensity": "Carbon intensity (gCO₂e/MJ)", "edrms": "EDRMS#", "applicationDate": "Application date", "approvalDate": "Approval date", diff --git a/frontend/src/components/Login.jsx b/frontend/src/components/Login.jsx index 088561f4b..be325707a 100644 --- a/frontend/src/components/Login.jsx +++ b/frontend/src/components/Login.jsx @@ -188,6 +188,7 @@ export const Login = () => { { keycloak.login({ idpHint: IDENTITY_PROVIDERS.BCEID_BUSINESS, @@ -221,6 +222,7 @@ export const Login = () => { { keycloak.login({ idpHint: IDENTITY_PROVIDERS.IDIR, diff --git a/frontend/src/views/Organizations/ViewOrganization/ViewOrganization.jsx b/frontend/src/views/Organizations/ViewOrganization/ViewOrganization.jsx index 05fc5fbb6..bb7762a72 100644 --- a/frontend/src/views/Organizations/ViewOrganization/ViewOrganization.jsx +++ b/frontend/src/views/Organizations/ViewOrganization/ViewOrganization.jsx @@ -42,12 +42,9 @@ export const ViewOrganization = () => { orgID ?? currentUser?.organization?.organizationId ) - let orgBalance = {} - if (hasRoles(roles.government)) { - // eslint-disable-next-line react-hooks/rules-of-hooks - orgBalance = useOrganizationBalance(orgID) - } - const { data: orgBalaceInfo } = orgBalance + const { data: orgBalanceInfo } = useOrganizationBalance( + orgID ?? currentUser?.organization?.organizationId + ) const canEdit = hasRoles(roles.administrator) const editButtonRoute = canEdit @@ -174,9 +171,9 @@ export const ViewOrganization = () => { {t('org:complianceUnitBalance')}:{' '} - {orgBalaceInfo?.totalBalance.toLocaleString()} ( + {orgBalanceInfo?.totalBalance?.toLocaleString()} ( {Math.abs( - orgBalaceInfo?.reservedBalance + orgBalanceInfo?.reservedBalance || 0 ).toLocaleString()} ) From cf243cba130a758f782a1a09ec9b46bfe10a0b40 Mon Sep 17 00:00:00 2001 From: prv-proton Date: Tue, 7 Jan 2025 18:35:07 -0800 Subject: [PATCH 2/4] . --- frontend/src/hooks/useOrganization.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/frontend/src/hooks/useOrganization.js b/frontend/src/hooks/useOrganization.js index 2e095dfd6..b8a4c85b5 100644 --- a/frontend/src/hooks/useOrganization.js +++ b/frontend/src/hooks/useOrganization.js @@ -2,6 +2,7 @@ import { apiRoutes } from '@/constants/routes' import { useApiService } from '@/services/useApiService' import { useQuery } from '@tanstack/react-query' import { useCurrentUser } from './useCurrentUser' +import { roles } from '@/constants/roles' export const useOrganization = (orgID, options) => { const client = useApiService() @@ -29,14 +30,24 @@ export const useOrganizationUser = (orgID, userID, options) => { export const useOrganizationBalance = (orgID, options) => { const client = useApiService() + const { hasRoles } = useCurrentUser() + const hasAccess = hasRoles(roles.government) return useQuery({ queryKey: ['organization-balance', orgID], - queryFn: async () => - orgID ? (await client.get(`/organizations/balances/${orgID}`)).data : {}, + queryFn: async () => { + if (!hasAccess) { + return null + } + return orgID + ? (await client.get(`/organizations/balances/${orgID}`)).data + : {} + }, + enabled: hasAccess && !!orgID, ...options }) } + export const useCurrentOrgBalance = (options) => { const client = useApiService() From 76f2cda865f672a040ca779de84f152bb3cbb308 Mon Sep 17 00:00:00 2001 From: prv-proton Date: Tue, 7 Jan 2025 21:55:06 -0800 Subject: [PATCH 3/4] remove Header component --- frontend/src/components/BCDataGrid/BCDataGridServer.jsx | 2 +- frontend/src/components/BCDataGrid/BCGridViewer.jsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/components/BCDataGrid/BCDataGridServer.jsx b/frontend/src/components/BCDataGrid/BCDataGridServer.jsx index fea836178..df992bcea 100644 --- a/frontend/src/components/BCDataGrid/BCDataGridServer.jsx +++ b/frontend/src/components/BCDataGrid/BCDataGridServer.jsx @@ -289,7 +289,7 @@ const BCDataGridServer = ({ // Memorized default column definition parameters const defaultColDefParams = useMemo(() => ({ - headerComponent: AccessibleHeader, + // headerComponent: AccessibleHeader, suppressHeaderFilterButton: true, resizable: true, sortable: true, diff --git a/frontend/src/components/BCDataGrid/BCGridViewer.jsx b/frontend/src/components/BCDataGrid/BCGridViewer.jsx index 347270dcf..994e1660f 100644 --- a/frontend/src/components/BCDataGrid/BCGridViewer.jsx +++ b/frontend/src/components/BCDataGrid/BCGridViewer.jsx @@ -161,7 +161,7 @@ export const BCGridViewer = ({ const defaultColDefParams = useMemo( () => ({ - headerComponent: AccessibleHeader, + // headerComponent: AccessibleHeader, suppressHeaderFilterButton: true, resizable: true, sortable: true, From 420e3617679bc42f9d3996d191d412a9babbc57b Mon Sep 17 00:00:00 2001 From: prv-proton Date: Tue, 7 Jan 2025 22:08:01 -0800 Subject: [PATCH 4/4] . --- frontend/src/components/BCDataGrid/BCDataGridServer.jsx | 4 +++- frontend/src/components/BCDataGrid/BCGridViewer.jsx | 9 +++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/frontend/src/components/BCDataGrid/BCDataGridServer.jsx b/frontend/src/components/BCDataGrid/BCDataGridServer.jsx index df992bcea..ac84345c0 100644 --- a/frontend/src/components/BCDataGrid/BCDataGridServer.jsx +++ b/frontend/src/components/BCDataGrid/BCDataGridServer.jsx @@ -289,7 +289,9 @@ const BCDataGridServer = ({ // Memorized default column definition parameters const defaultColDefParams = useMemo(() => ({ - // headerComponent: AccessibleHeader, + headerComponentParams: { + innerHeaderComponent: AccessibleHeader + }, suppressHeaderFilterButton: true, resizable: true, sortable: true, diff --git a/frontend/src/components/BCDataGrid/BCGridViewer.jsx b/frontend/src/components/BCDataGrid/BCGridViewer.jsx index 994e1660f..54614873c 100644 --- a/frontend/src/components/BCDataGrid/BCGridViewer.jsx +++ b/frontend/src/components/BCDataGrid/BCGridViewer.jsx @@ -1,7 +1,10 @@ import BCAlert, { FloatingAlert } from '@/components/BCAlert' import BCBox from '@/components/BCBox' import { BCGridBase } from '@/components/BCDataGrid/BCGridBase' -import { AccessibleHeader, BCPagination } from '@/components/BCDataGrid/components' +import { + AccessibleHeader, + BCPagination +} from '@/components/BCDataGrid/components' import '@ag-grid-community/styles/ag-grid.css' import '@ag-grid-community/styles/ag-theme-material.css' import { useCallback, useMemo, useRef, useState } from 'react' @@ -161,7 +164,9 @@ export const BCGridViewer = ({ const defaultColDefParams = useMemo( () => ({ - // headerComponent: AccessibleHeader, + headerComponentParams: { + innerHeaderComponent: AccessibleHeader + }, suppressHeaderFilterButton: true, resizable: true, sortable: true,