Skip to content

Commit

Permalink
Merge branch 'release-0.2.0' into LCFS-1581-EditIconIDIRUsers
Browse files Browse the repository at this point in the history
  • Loading branch information
prv-proton authored Jan 10, 2025
2 parents bddd434 + fd27caf commit 18592c3
Show file tree
Hide file tree
Showing 8 changed files with 685 additions and 3 deletions.
177 changes: 177 additions & 0 deletions backend/lcfs/db/migrations/versions/2025-01-06-22-09_fa98709e7952.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
"""Add legacy fuel types
Revision ID: fa98709e7952
Revises: 94306eca5261
Create Date: 2025-01-06 22:09:52.936619
"""

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "fa98709e7952"
down_revision = "94306eca5261"
branch_labels = None
depends_on = None


def upgrade():
op.execute(
"""
INSERT INTO fuel_type (
fuel_type,
fossil_derived,
other_uses_fossil_derived,
default_carbon_intensity,
units,
unrecognized,
create_user,
update_user,
is_legacy
)
VALUES
-- 1) Natural gas-based gasoline
(
'Natural gas-based gasoline',
FALSE,
TRUE,
90.07,
'Litres',
FALSE,
'no_user',
'no_user',
TRUE
),
-- 2) Petroleum-based diesel
(
'Petroleum-based diesel',
FALSE,
TRUE,
94.76,
'Litres',
FALSE,
'no_user',
'no_user',
TRUE
),
-- 3) Petroleum-based gasoline
(
'Petroleum-based gasoline',
FALSE,
TRUE,
88.14,
'Litres',
FALSE,
'no_user',
'no_user',
TRUE
);
"""
)

op.execute(
"""
INSERT INTO energy_density (
fuel_type_id,
density,
uom_id,
create_user,
update_user
)
SELECT
ft.fuel_type_id,
CASE
WHEN ft.fuel_type = 'Natural gas-based gasoline' THEN 34.69
WHEN ft.fuel_type = 'Petroleum-based diesel' THEN 38.65
WHEN ft.fuel_type = 'Petroleum-based gasoline' THEN 34.69
END AS density,
1 AS uom_id,
'no_user' AS create_user,
'no_user' AS update_user
FROM fuel_type ft
WHERE ft.fuel_type IN (
'Natural gas-based gasoline',
'Petroleum-based diesel',
'Petroleum-based gasoline'
);
"""
)

op.execute(
"""
INSERT INTO energy_effectiveness_ratio (
fuel_category_id,
fuel_type_id,
end_use_type_id,
ratio,
create_user,
update_user,
effective_date,
effective_status,
expiration_date
)
SELECT
CASE
WHEN ft.fuel_type = 'Petroleum-based diesel' THEN 2
ELSE 1
END AS fuel_category_id,
ft.fuel_type_id,
NULL AS end_use_type_id,
1.0 AS ratio,
'no_user' AS create_user,
'no_user' AS update_user,
CURRENT_DATE AS effective_date,
TRUE AS effective_status,
NULL AS expiration_date
FROM fuel_type ft
WHERE ft.fuel_type IN (
'Natural gas-based gasoline',
'Petroleum-based diesel',
'Petroleum-based gasoline'
);
"""
)


def downgrade():
op.execute(
"""
DELETE FROM energy_effectiveness_ratio
WHERE fuel_type_id IN (
SELECT fuel_type_id
FROM fuel_type
WHERE fuel_type IN (
'Natural gas-based gasoline',
'Petroleum-based diesel',
'Petroleum-based gasoline'
)
);
"""
)

op.execute(
"""
DELETE FROM energy_density
WHERE fuel_type_id IN (
SELECT fuel_type_id
FROM fuel_type
WHERE fuel_type IN (
'Natural gas-based gasoline',
'Petroleum-based diesel',
'Petroleum-based gasoline'
)
);
"""
)

op.execute(
"""
DELETE FROM fuel_type
WHERE fuel_type IN (
'Natural gas-based gasoline',
'Petroleum-based diesel',
'Petroleum-based gasoline'
);
"""
)
12 changes: 12 additions & 0 deletions frontend/src/assets/locales/en/dashboard.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,17 @@
"inProgress": "Compliance report(s) in progress",
"awaitingGovReview": "Compliance report(s) awaiting government review",
"noActionRequired": "There are no reports that require any action."
},
"userSettings": {
"title": "User settings",
"notifications": "Notifications",
"configureNotifications": "Configure your notifications",
"help": "Help"
},
"orgUserSettings": {
"title": "User settings",
"notifications": "Notifications",
"configureNotifications": "Configure your notifications",
"help": "Help"
}
}
19 changes: 16 additions & 3 deletions frontend/src/views/Dashboard/Dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@ import { Grid, Box } from '@mui/material'
import { Role } from '@/components/Role'
import { roles, govRoles, nonGovRoles } from '@/constants/roles'
import {
// IDIR Cards
AdminLinksCard,
DirectorReviewCard,
TransactionsCard,
UserSettingsCard,

// BCeID Cards
OrgDetailsCard,
OrgBalanceCard,
FeedbackCard,
WebsiteCard,
DirectorReviewCard,
TransactionsCard,
OrgTransactionsCard,
OrgComplianceReportsCard
OrgComplianceReportsCard,
OrgUserSettingsCard
} from './components/cards'
import OrganizationsSummaryCard from './components/cards/idir/OrganizationsSummaryCard'

Expand Down Expand Up @@ -93,6 +98,14 @@ export const Dashboard = () => {
<Role roles={[govRoles, roles.administrator]}>
<AdminLinksCard />
</Role>

{/* User settings */}
<Role roles={nonGovRoles}>
<OrgUserSettingsCard />
</Role>
<Role roles={govRoles}>
<UserSettingsCard />
</Role>
</Box>
</Grid>
</Grid>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import React from 'react'
import { List, ListItemButton, Stack, Typography } from '@mui/material'
import { useNavigate } from 'react-router-dom'
import { useTranslation } from 'react-i18next'
import BCWidgetCard from '@/components/BCWidgetCard/BCWidgetCard'
import BCTypography from '@/components/BCTypography'
import withRole from '@/utils/withRole'
import { nonGovRoles } from '@/constants/roles'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { faArrowUpRightFromSquare } from '@fortawesome/free-solid-svg-icons'
import { useCurrentUser } from '@/hooks/useCurrentUser'
import { ROUTES } from '@/constants/routes'

const linkStyle = {
textDecoration: 'underline',
color: 'link.main',
'&:hover': { color: 'info.main' }
}

const UserSettingsLink = ({ onClick, children }) => (
<ListItemButton onClick={onClick}>
<Typography variant="subtitle2" sx={linkStyle}>
{children}
</Typography>
</ListItemButton>
)

const OrgUserSettingsCard = () => {
const { t } = useTranslation(['dashboard'])
const { data: currentUser } = useCurrentUser()
const navigate = useNavigate()

const { title, firstName, lastName } = currentUser || {}
const name = [firstName, lastName].filter(Boolean).join(' ')
const displayName = [name, title].filter(Boolean).join(', ')

return (
<BCWidgetCard
component="div"
disableHover={true}
color="nav"
icon="user"
title={t('dashboard:orgUserSettings.title')}
content={
<Stack spacing={1}>
<BCTypography
variant="body2"
sx={{ fontWeight: 'bold', color: '#003366' }}
>
{displayName}
</BCTypography>

<List component="nav" sx={{ maxWidth: '100%', mt: 1 }}>
<UserSettingsLink onClick={() => navigate(ROUTES.NOTIFICATIONS)}>
{t('dashboard:orgUserSettings.notifications')}
</UserSettingsLink>

<UserSettingsLink
onClick={() => navigate(ROUTES.NOTIFICATIONS_SETTINGS)}
>
{t('dashboard:orgUserSettings.configureNotifications')}
</UserSettingsLink>

{/* TODO: Update the link to the help page */}
<UserSettingsLink onClick={() => navigate()}>
{t('dashboard:orgUserSettings.help')}
<FontAwesomeIcon
icon={faArrowUpRightFromSquare}
style={{ color: '#578260', marginLeft: 6 }}
/>
</UserSettingsLink>
</List>
</Stack>
}
/>
)
}

export default withRole(OrgUserSettingsCard, nonGovRoles)
Loading

0 comments on commit 18592c3

Please sign in to comment.