Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MPDX-8478 - Add MPD-HI Card to Dashboard #1221

Closed
wants to merge 35 commits into from

Conversation

dr-bizz
Copy link
Contributor

@dr-bizz dr-bizz commented Dec 11, 2024

Description

In this PR, I have created the Health Indicator widget and add it to the dashboard. The data I use is the last item in the healthIndicatorDataarray, which I fetch using the HealthIndicatorWidget GQL query. (I'm unsure if that is correct, but I'm going with it for now.)

I've added tests for the HI widget and Monthly Goal Components.

Mentionable changes

Process Bar Component: Switched makeStyles() to styled() components to allow me to make the HI process bar thinner.
Monthly Goal Component: If HI data is present, make it responsive with the HI widget.

Jira Task - MPDX-8478

Checklist:

  • I have given my PR a title with the format "MPDX-(JIRA#) (summary sentence max 80 chars)"
  • I have applied the appropriate labels. (Add the label "On Staging" to get the branch automatically merged into staging.)
  • I have requested a review from another person on the project

@dr-bizz dr-bizz requested a review from canac December 11, 2024 15:47
@dr-bizz dr-bizz changed the title Add hi graph to dashboard MPDX-8478 - Add MPD-HI Card to Dashboard Dec 11, 2024
@dr-bizz dr-bizz added the Preview Environment Add this label to create an Amplify Preview label Dec 11, 2024
Copy link
Contributor

Preview branch generated at https://add-hi-graph-to-dashboard.d3dytjb8adxkk5.amplifyapp.com

Copy link
Contributor

@canac canac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks really good! Great work so far.

…e when we pass the data to the API since we get the data in lowercase.
@dr-bizz dr-bizz requested a review from canac December 12, 2024 14:27
Copy link
Contributor

@canac canac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be a future PR, but do you see how at 100% the progress bar slightly spills overflows? Screenshot 2024-12-12 at 11 38 42 AM

There are 2px of margin on each side, so instead of width: 100% on the yellow bar, I think it needs width: calc(100% - 4px). I assume this bug is present on all of our progress bars.

@canac canac force-pushed the 8481-hi-report-graph branch from e3940ad to 31a2a39 Compare December 12, 2024 17:40
@@ -85,15 +85,21 @@ const StyledProgress = ({
<>
<ProgressBar
style={{
width: percentageFormat(secondary, locale).replace('\xa0', ''),
width: `calc(${percentageFormat(secondary, locale).replace(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't notice this before, but I don't think we should be using a localized percentage format for the CSS width. Different locales use different separators or even put the percent sign first, which will result in invalid CSS syntax. I think we should just do (secondary / 100).toFixed() + '%' since we want the percentage in a specific format. Thanks for the - 4px fix though!

Copy link
Contributor Author

@dr-bizz dr-bizz Dec 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried many different languages and locales, and all those I tried worked. I'm using the same method to calculate the percentage as we have been doing. I haven't hear of the progress bars not working for users.

Screenshot 2024-12-13 at 10 40 00 AM

Screenshot 2024-12-13 at 10 44 22 AM

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you changing the language or the locale? On my account, I'm seeing a difference when switching between en-US and ar.

Here it is with American locale:

Screenshot 2024-12-13 at 11 26 33 AM

Here it is with Arabic locale:

Screenshot 2024-12-13 at 11 26 15 AM

But maybe I'm missing something.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird, maybe I needed to do a hard refresh to flush the cache

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch

canac and others added 5 commits December 13, 2024 07:42
* Sort tag list after they are joined

* Make button content left aligned for short tag names
…ountList Id if they have an underscore as their accountList ID
MPDX-8492 - Enhance loadSession to Redirect Placeholder _ to Default Account List
@dr-bizz dr-bizz changed the base branch from 8481-hi-report-graph to health-indicator December 16, 2024 17:26
@dr-bizz dr-bizz force-pushed the add-hi-graph-to-dashboard branch from a18307b to 0d3cbc6 Compare December 16, 2024 17:31
Copy link

@codescene-delta-analysis codescene-delta-analysis bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Health Quality Gates: FAILED

Change in average Code Health of affected files: +0.09 (8.64 -> 8.73)

  • Declining Code Health: 5 findings(s) 🚩
  • Improving Code Health: 1 findings(s) ✅
  • Affected Hotspots: 1 files(s) 🔥

View detailed results in CodeScene

@@ -69,6 +69,7 @@ export const FourteenMonthReport: React.FC<Props> = ({
useEffect(() => {
(async () => {
try {
setFourteenMonthReportError('');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ Getting worse: Complex Method
FourteenMonthReport:React.FC<Props> already has high cyclomatic complexity, and now it increases in Lines of Code from 131 to 132

Suppress

Comment on lines -531 to -540
expect(mutationSpy.mock.lastCall).toMatchObject([
{
operation: {
operationName: 'UpdateContactPartnership',
variables: {
attributes: {
likelyToGive: 'MOST_LIKELY',
},
},
},

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ Getting worse: Code Duplication
introduced similar code in: 'should allow for user to remove the start date','should allow user to remove next ask date'

@@ -5,6 +5,7 @@ import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
import { render, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { SnackbarProvider } from 'notistack';
import TestRouter from '__tests__/util/TestRouter';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Getting better: Code Duplication
reduced similar code in: 'should handle closing modal | Cancel Button','should handle closing modal | Close Button','should render edit partnership info modal','should save when only status is inputted'

}

export const DeleteContactModal: React.FC<DeleteContactModalProps> = ({
open,
setOpen,
deleting,
deleteContact,
contactId,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ New issue: Complex Method
DeleteContactModal:React.FC<DeleteContactModalProps> has a cyclomatic complexity of 18, threshold = 10

Suppress

@@ -993,10 +993,22 @@ class MpdxRestApi extends RESTDataSource {
googleIntegrationId,
googleIntegration,
) {
const attributes = {};
interface GoogleIntegrationAttributes {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ Getting worse: Lines of Code in a Single File
The lines of code increases from 1014 to 1024, improve code health by reducing it to 1000

@@ -63,15 +65,40 @@ const MonthlyGoal = ({
pledged = 0,
totalGiftsNotStarted,
currencyCode = 'USD',
}: Props): ReactElement => {
const { classes } = useStyles();
}: MonthlyGoalProps): ReactElement => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ Getting worse: Complex Method
MonthlyGoal increases in cyclomatic complexity from 14 to 19, threshold = 10

Suppress

Comment on lines +103 to +113
it('should set to TRUE as machine goal is defined and the same as the monthly goal', async () => {
const { findByText } = render(
<Components
healthIndicatorData={[healthIndicatorScore]}
goal={healthIndicatorScore.machineCalculatedGoal}
/>,
);

expect(await findByText('Ownership')).toBeInTheDocument();
expect(setUsingMachineCalculatedGoal).toHaveBeenCalledWith(true);
});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ New issue: Code Duplication
The module contains 3 functions with similar structure: 'should set to FALSE as machine goal is different than the monthly goal','should set to FALSE as machine goal is not defined','should set to TRUE as machine goal is defined and the same as the monthly goal'

Suppress

Copy link

@codescene-delta-analysis codescene-delta-analysis bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Health Quality Gates: FAILED

Change in average Code Health of affected files: +0.09 (8.64 -> 8.73)

  • Declining Code Health: 5 findings(s) 🚩
  • Improving Code Health: 1 findings(s) ✅
  • Affected Hotspots: 1 files(s) 🔥

View detailed results in CodeScene

Comment on lines +42 to +150
const { data, loading } = useHealthIndicatorWidgetQuery({
variables: {
accountListId,
month: DateTime.now().startOf('month').toISODate(),
},
});

useEffect(() => {
setShowHealthIndicator(!!data?.healthIndicatorData.length);
const machineCalculatedGoal =
data?.healthIndicatorData[0]?.machineCalculatedGoal;
setUsingMachineCalculatedGoal(
!!machineCalculatedGoal && goal === machineCalculatedGoal,
);
}, [data, goal]);

if (!showHealthIndicator) {
return null;
}

const currentStats = data?.healthIndicatorData[0];

return (
<AnimatedCard sx={{ height: '100%' }}>
<CardHeader
title={t('MPD Health Indicator')}
titleTypographyProps={{
style: { fontSize: '1rem' },
}}
/>
<StyledCardContent>
<Tooltip
title={`${t('MPD Health')} = [(${t('Ownership')} * 3) + (${t(
'Success',
)} * 2) + (${t('Consistency')} * 1) + (${t('Depth')} * 1)] / 7`}
arrow
>
<StyledBox>
<Typography variant="h4" color="primary" width={'55px'}>
{currentStats?.overallHi}
</Typography>
<Box width={'calc(100% - 55px)'}>
<Typography
component="div"
color="primary"
sx={{ marginBottom: 1 }}
>
{t('Overall Health Indicator')}
</Typography>
<StyledProgress
loading={loading}
primary={
currentStats?.overallHi ? currentStats.overallHi / 100 : 0
}
barHeight={20}
/>
</Box>
</StyledBox>
</Tooltip>

<Grid container>
<WidgetStat
loading={loading}
stat={currentStats?.ownershipHi}
statName={t('Ownership')}
toolTip={t('% of Self-raised Funds over Total Funds')}
/>
<WidgetStat
loading={loading}
stat={currentStats?.consistencyHi}
statName={t('Consistency')}
toolTip={t('% of months with positive account balance')}
/>
<WidgetStat
loading={loading}
stat={currentStats?.successHi}
statName={t('Success')}
toolTip={t('% of Self-raised Funds over Support Goal')}
/>
<WidgetStat
loading={loading}
stat={currentStats?.depthHi}
statName={t('Depth')}
toolTip={t('Trend of local partners')}
/>
</Grid>
</StyledCardContent>
<CardActions>
<Button
LinkComponent={NextLink}
href={`/accountLists/${accountListId}/reports/healthIndicator`}
size="small"
color="primary"
>
{t('View Details')}
</Button>
</CardActions>
</AnimatedCard>
);
};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ New issue: Complex Method
HealthIndicatorWidget:React.FC<HealthIndicatorWidgetProps> has a cyclomatic complexity of 14, threshold = 10

Suppress

@dr-bizz
Copy link
Contributor Author

dr-bizz commented Dec 16, 2024

Due to the state of the commit history, I closed this PR and cherry-picked it to this PR - #1221

@dr-bizz dr-bizz closed this Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Preview Environment Add this label to create an Amplify Preview
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants