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

Adm 944 [frontend] change thumbup icon position #1474

Merged
merged 6 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import ChartAndTitleWrapper from '@src/containers/ReportStep/ChartAndTitleWrapper';
import { CHART_TYPE, TREND_ICON, TREND_TYPE } from '@src/constants/resources';
import { render, screen } from '@testing-library/react';
import { theme } from '@src/theme';

describe('ChartAndTitleWrapper', () => {
it('should render green up icon given icon is set to up and better', () => {
Expand All @@ -14,7 +15,7 @@ describe('ChartAndTitleWrapper', () => {
const icon = screen.getByTestId('TrendingUpSharpIcon');

expect(icon).toBeInTheDocument();
expect(icon.parentElement?.parentElement).toHaveStyle({ color: 'green' });
expect(icon.parentElement?.parentElement).toHaveStyle({ color: theme.main.chartTrend.betterColor });
});

it('should render down icon given icon is set to down and worse', () => {
Expand All @@ -28,7 +29,7 @@ describe('ChartAndTitleWrapper', () => {
const icon = screen.getByTestId('TrendingDownSharpIcon');

expect(screen.getByTestId('TrendingDownSharpIcon')).toBeInTheDocument();
expect(icon.parentElement?.parentElement).toHaveStyle({ color: 'red' });
expect(icon.parentElement?.parentElement).toHaveStyle({ color: theme.main.chartTrend.worseColor });
});

it('should show positive trend number even if the tend number is negative', () => {
Expand Down
10 changes: 9 additions & 1 deletion frontend/__tests__/containers/ReportStep/style.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,15 @@ describe('ChartAndTitleWrapper styled component', () => {
<ThumbUpIcon />
</TrendTypeIcon>,
);
console.log(screen.getByLabelText('test component 1'));
expect(screen.getByLabelText('test component 1').children[0]).toHaveStyle({ color: 'red' });
});

it('should render the TrendTypeIcon with the reverse style', () => {
render(
<TrendTypeIcon aria-label='test component 2' color='red' reverse>
<ThumbUpIcon />
</TrendTypeIcon>,
);
expect(screen.getByLabelText('test component 2').children[0]).toHaveStyle({ transform: 'scaleY(-1)' });
});
});
16 changes: 8 additions & 8 deletions frontend/e2e/fixtures/import-file/chart-result.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
export const BOARD_CHART_VALUE = {
Velocity: {
type: 'trend up',
color: 'green',
color: '#02C4A8',
value: '160.00%',
},
'Average Cycle Time': {
type: 'trend up',
color: 'red',
color: '#E82107',
value: '75.25%',
},
'Cycle Time Allocation': {
type: 'trend up',
color: 'green',
color: '#02C4A8',
value: '1.93%',
},
Rework: {
type: 'trend up',
color: 'red',
color: '#E82107',
value: '266.67%',
},
};

export const DORA_CHART_VALUE = {
'Lead Time For Changes': {
type: 'trend down',
color: 'green',
color: '#02C4A8',
value: '40.28%',
},
'Deployment Frequency': {
type: 'trend down',
color: 'red',
color: '#E82107',
value: '6.67%',
},
'Dev Change Failure Rate': {
type: 'trend down',
color: 'green',
color: '#02C4A8',
value: '59.99%',
},
'Dev Mean Time To Recovery': {
type: 'trend down',
color: 'green',
color: '#02C4A8',
value: '22.19%',
},
};
21 changes: 6 additions & 15 deletions frontend/src/containers/ReportStep/ChartAndTitleWrapper/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
ChartTitle,
StyledTooltipContent,
StyledTooltipWrapper,
TrendContainer,
TrendIcon,
TrendTypeIcon,
Expand All @@ -10,7 +9,6 @@ import { CHART_TREND_TIP, CHART_TYPE, TREND_ICON, TREND_TYPE, UP_TREND_IS_BETTER
import TrendingDownSharpIcon from '@mui/icons-material/TrendingDownSharp';
import TrendingUpSharpIcon from '@mui/icons-material/TrendingUpSharp';
import { ChartWrapper } from '@src/containers/MetricsStep/style';
import ThumbDownIcon from '@mui/icons-material/ThumbDown';
import { convertNumberToPercent } from '@src/utils/util';
import React, { ForwardedRef, forwardRef } from 'react';
import ThumbUpIcon from '@mui/icons-material/ThumbUp';
Expand All @@ -30,11 +28,6 @@ const TREND_ICON_MAPPING = {
[TREND_ICON.DOWN]: <TrendingDownSharpIcon aria-label={'trend down'} />,
};

const TREND_TYPE_ICON_MAPPING = {
[TREND_TYPE.BETTER]: <ThumbUpIcon />,
[TREND_TYPE.WORSE]: <ThumbDownIcon />,
};

const TREND_COLOR_MAP = {
[TREND_TYPE.BETTER]: theme.main.chartTrend.betterColor,
[TREND_TYPE.WORSE]: theme.main.chartTrend.worseColor,
Expand Down Expand Up @@ -65,15 +58,13 @@ const ChartAndTitleWrapper = forwardRef(
}
};
const tipContent = (
<StyledTooltipWrapper>
<TrendTypeIcon color={TREND_COLOR_MAP[trendInfo.trendType!]}>
{TREND_TYPE_ICON_MAPPING[trendInfo.trendType!]}
<StyledTooltipContent>
<p>{`The rate of ${trendDescribe()} for ${CHART_TREND_TIP[trendInfo.type]}: `}</p>
{trendInfo.dateRangeList?.map((dateRange) => <p key={dateRange}>{dateRange}</p>)}
<TrendTypeIcon color={TREND_COLOR_MAP[trendInfo.trendType!]} reverse={trendInfo.trendType === TREND_TYPE.WORSE}>
<ThumbUpIcon />
</TrendTypeIcon>
<StyledTooltipContent>
<p>{`The rate of ${trendDescribe()} for ${CHART_TREND_TIP[trendInfo.type]}: `}</p>
{trendInfo.dateRangeList?.map((dateRange) => <p key={dateRange}>{dateRange}</p>)}
</StyledTooltipContent>
</StyledTooltipWrapper>
</StyledTooltipContent>
);

return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { styled } from '@mui/material/styles';

export const ChartTitle = styled('div')({
display: 'flex',
alignItems: 'center',
Expand Down Expand Up @@ -31,20 +30,20 @@ export const TrendContainer = styled('div')(({ color }: { color: string }) => ({
}));

export const StyledTooltipContent = styled('div')({
position: 'relative',
fontSize: '0.85rem',
display: 'flex',
flexDirection: 'column',
gap: '0.5rem',
});

export const StyledTooltipWrapper = styled('div')({
display: 'flex',
});

export const TrendTypeIcon = styled('div')(({ color }: { color: string }) => ({
export const TrendTypeIcon = styled('div')(({ color, reverse }: { color: string; reverse?: boolean }) => ({
position: 'absolute',
right: '0',
bottom: '0',
'& svg': {
color: color,
fontSize: '1rem',
marginRight: '0.5rem',
fontSize: '1.125rem',
transform: reverse ? 'scaleY(-1)' : 'none',
},
}));
4 changes: 2 additions & 2 deletions frontend/src/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ export const theme = createTheme({
},
main: {
chartTrend: {
betterColor: 'green',
worseColor: 'red',
betterColor: '#02C4A8',
worseColor: '#E82107',
},
doraChart: {
barColorA: '#003D4F',
Expand Down
1 change: 1 addition & 0 deletions ops/check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ hex_check() {
result=$(grep -rinE \
--exclude-dir='node_modules' \
--exclude-dir='coverage' \
--exclude='chart-result.ts' \
--exclude='*.html' \
--exclude='*.svg' \
--exclude='*.xml' \
Expand Down
Loading