Skip to content

Commit 1f84876

Browse files
committed
Fixed CI failing test
1 parent 208faed commit 1f84876

File tree

2 files changed

+73
-47
lines changed

2 files changed

+73
-47
lines changed

web-server/src/content/DoraMetrics/DoraMetricsDuration.tsx

Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
import { Card, Chip, Tooltip, useTheme } from '@mui/material';
1+
import {
2+
CheckCircleRounded,
3+
AccessTimeRounded,
4+
OpenInNew,
5+
Code,
6+
ArrowForwardIosRounded
7+
} from '@mui/icons-material';
8+
import { Card, Tooltip, useTheme } from '@mui/material';
29
import { FC, useMemo } from 'react';
3-
import { CheckCircleRounded, AccessTimeRounded, OpenInNew, Code, ArrowForwardIosRounded } from '@mui/icons-material';
410

511
import { FlexBox } from '@/components/FlexBox';
612
import { Line } from '@/components/Text';
@@ -9,7 +15,6 @@ import { getDurationString, isoDateString } from '@/utils/date';
915

1016
type DeploymentCardType = 'Longest' | 'Shortest';
1117

12-
1318
interface DeploymentCardProps {
1419
deployment: Deployment;
1520
type: DeploymentCardType;
@@ -19,7 +24,6 @@ interface DoraMetricsDurationProps {
1924
deployments: Deployment[];
2025
}
2126

22-
2327
const formatDeploymentDate = (dateString: string): string => {
2428
if (!dateString) return 'Unknown Date';
2529

@@ -62,14 +66,16 @@ const DeploymentCard: FC<DeploymentCardProps> = ({ deployment }) => {
6266
width: '20vw',
6367
maxWidth: '30vw',
6468
border: `1px solid ${theme.palette.primary.light}`,
65-
borderRadius: 2,
69+
borderRadius: 2
6670
}}
6771
>
6872
<FlexBox col gap={1.2} sx={{ position: 'relative' }}>
69-
<FlexBox gap={0.8} alignItems="center" >
73+
<FlexBox gap={0.8} alignItems="center">
7074
<FlexBox alignItems="center" gap={1}>
7175
<CheckCircleRounded color="success" fontSize="inherit" />
72-
<Line white semibold>Run On {formatDeploymentDate(deployment.conducted_at)}</Line>
76+
<Line white semibold>
77+
Run On {formatDeploymentDate(deployment.conducted_at)}
78+
</Line>
7379
</FlexBox>
7480
<Tooltip title="Open in new tab" arrow>
7581
<FlexBox
@@ -105,7 +111,7 @@ const DeploymentCard: FC<DeploymentCardProps> = ({ deployment }) => {
105111
position: 'absolute',
106112
right: 0,
107113
top: '35%',
108-
bottom: '35%',
114+
bottom: '35%'
109115
}}
110116
fontSize="medium"
111117
/>
@@ -115,28 +121,41 @@ const DeploymentCard: FC<DeploymentCardProps> = ({ deployment }) => {
115121
);
116122
};
117123

118-
export const DoraMetricsDuration: FC<DoraMetricsDurationProps> = ({ deployments }) => {
124+
export const DoraMetricsDuration: FC<DoraMetricsDurationProps> = ({
125+
deployments
126+
}) => {
119127
const { longestDeployment, shortestDeployment } = useMemo(() => {
120128
if (!Array.isArray(deployments) || !deployments.length) {
121129
return { longestDeployment: null, shortestDeployment: null };
122130
}
123131

124132
const validDeployments = deployments
125-
.filter((d): d is Deployment => Boolean(d.conducted_at && typeof d.run_duration === 'number'))
133+
.filter((d): d is Deployment =>
134+
Boolean(d.conducted_at && typeof d.run_duration === 'number')
135+
)
126136
.filter((d) => d.run_duration >= 0);
127137

128138
if (!validDeployments.length) {
129139
return { longestDeployment: null, shortestDeployment: null };
130140
}
131141

132142
// Function to calculate Longest and shortest deployments
133-
const { longest, shortest } = validDeployments.reduce((acc, current) => ({
134-
longest: !acc.longest || current.run_duration > acc.longest.run_duration ? current : acc.longest,
135-
shortest: !acc.shortest || current.run_duration < acc.shortest.run_duration ? current : acc.shortest
136-
}), {
137-
longest: null as Deployment | null,
138-
shortest: null as Deployment | null
139-
});
143+
const { longest, shortest } = validDeployments.reduce(
144+
(acc, current) => ({
145+
longest:
146+
!acc.longest || current.run_duration > acc.longest.run_duration
147+
? current
148+
: acc.longest,
149+
shortest:
150+
!acc.shortest || current.run_duration < acc.shortest.run_duration
151+
? current
152+
: acc.shortest
153+
}),
154+
{
155+
longest: null as Deployment | null,
156+
shortest: null as Deployment | null
157+
}
158+
);
140159

141160
return { longestDeployment: longest, shortestDeployment: shortest };
142161
}, [deployments]);
@@ -145,19 +164,17 @@ export const DoraMetricsDuration: FC<DoraMetricsDurationProps> = ({ deployments
145164
<FlexBox col gap={1.5}>
146165
<FlexBox gap={3}>
147166
<FlexBox col gap={1}>
148-
<Line white sx={{ fontSize: '1.0rem' }} semibold>Longest Deployment</Line>
149-
<DeploymentCard
150-
deployment={longestDeployment}
151-
type="Longest"
152-
/>
167+
<Line white sx={{ fontSize: '1.0rem' }} semibold>
168+
Longest Deployment
169+
</Line>
170+
<DeploymentCard deployment={longestDeployment} type="Longest" />
153171
</FlexBox>
154172

155173
<FlexBox col gap={1}>
156-
<Line white sx={{ fontSize: '1.0rem' }} semibold>Shortest Deployment</Line>
157-
<DeploymentCard
158-
deployment={shortestDeployment}
159-
type="Shortest"
160-
/>
174+
<Line white sx={{ fontSize: '1.0rem' }} semibold>
175+
Shortest Deployment
176+
</Line>
177+
<DeploymentCard deployment={shortestDeployment} type="Shortest" />
161178
</FlexBox>
162179
</FlexBox>
163180
</FlexBox>

web-server/src/content/PullRequests/DeploymentInsightsOverlay.tsx

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { ArrowDownwardRounded } from '@mui/icons-material';
22
import { Card, Divider, useTheme, Collapse, Box } from '@mui/material';
3+
import Link from 'next/link';
34
import pluralize from 'pluralize';
45
import { ascend, descend, groupBy, path, prop, sort } from 'ramda';
56
import { FC, useCallback, useEffect, useMemo, useState } from 'react';
6-
import { DoraMetricsTrend } from '../DoraMetrics/DoraMetricsTrend';
7-
import { DoraMetricsDuration } from '../DoraMetrics/DoraMetricsDuration';
7+
88
import { FlexBox } from '@/components/FlexBox';
99
import { MiniButton } from '@/components/MiniButton';
1010
import { MiniCircularLoader } from '@/components/MiniLoader';
@@ -13,6 +13,7 @@ import { PullRequestsTableMini } from '@/components/PRTableMini/PullRequestsTabl
1313
import Scrollbar from '@/components/Scrollbar';
1414
import { Tabs, TabItem } from '@/components/Tabs';
1515
import { Line } from '@/components/Text';
16+
import { ROUTES } from '@/constants/routes';
1617
import { FetchState } from '@/constants/ui-states';
1718
import { useAuth } from '@/hooks/useAuth';
1819
import { useBoolState, useEasyState } from '@/hooks/useEasyState';
@@ -29,14 +30,15 @@ import {
2930
} from '@/slices/dora_metrics';
3031
import { useDispatch, useSelector } from '@/store';
3132
import { Deployment, PR, RepoWorkflowExtended } from '@/types/resources';
33+
import { DeploymentSources } from '@/types/resources';
3234
import { percent } from '@/utils/datatype';
3335
import { depFn } from '@/utils/fn';
34-
import Link from 'next/link';
35-
import { ROUTES } from '@/constants/routes';
36-
import { DeploymentSources } from '@/types/resources';
3736

3837
import { DeploymentItem } from './DeploymentItem';
3938

39+
import { DoraMetricsDuration } from '../DoraMetrics/DoraMetricsDuration';
40+
import { DoraMetricsTrend } from '../DoraMetrics/DoraMetricsTrend';
41+
4042
enum DepStatusFilter {
4143
All,
4244
Pass,
@@ -199,8 +201,11 @@ export const DeploymentInsightsOverlay = () => {
199201
const dateRangeLabel = useCurrentDateRangeReactNode();
200202

201203
// Determine if the selected repository uses PR_MERGE as its deployment source
202-
const currentBaseRepo = selectedRepo.value ? teamDeployments.repos_map[selectedRepo.value] : null;
203-
const isPRMergeSource = currentBaseRepo?.deployment_type === DeploymentSources.PR_MERGE;
204+
const currentBaseRepo = selectedRepo.value
205+
? teamDeployments.repos_map[selectedRepo.value]
206+
: null;
207+
const isPRMergeSource =
208+
currentBaseRepo?.deployment_type === DeploymentSources.PR_MERGE;
204209

205210
if (!team) return <Line>Please select a team first...</Line>;
206211

@@ -226,10 +231,11 @@ export const DeploymentInsightsOverlay = () => {
226231
px={1}
227232
py={1 / 2}
228233
corner={theme.spacing(1)}
229-
border={`1px solid ${repo.id === selectedRepo.value
234+
border={`1px solid ${
235+
repo.id === selectedRepo.value
230236
? theme.colors.info.main
231237
: theme.colors.secondary.light
232-
}`}
238+
}`}
233239
pointer
234240
bgcolor={
235241
repo.id === selectedRepo.value
@@ -241,9 +247,7 @@ export const DeploymentInsightsOverlay = () => {
241247
? theme.colors.info.main
242248
: undefined
243249
}
244-
fontWeight={
245-
repo.id === selectedRepo.value ? 'bold' : undefined
246-
}
250+
fontWeight={repo.id === selectedRepo.value ? 'bold' : undefined}
247251
onClick={() => {
248252
selectedRepo.set(repo.id as ID);
249253
}}
@@ -297,7 +301,7 @@ export const DeploymentInsightsOverlay = () => {
297301
{activeTab === TabKeys.ANALYTICS ? (
298302
<FlexBox col gap={1} p={1}>
299303
<Divider sx={{ mb: '10px' }} />
300-
<Box sx={{mb:'10px'}} key={selectedRepo.value}>
304+
<Box sx={{ mb: '10px' }} key={selectedRepo.value}>
301305
<FlexBox col gap={1 / 2}>
302306
<Line white medium>
303307
<Line bold white>
@@ -338,10 +342,7 @@ export const DeploymentInsightsOverlay = () => {
338342
</Line>
339343
<ProgressBar
340344
mt={1}
341-
perc={percent(
342-
successfulDeps.length,
343-
deployments.length
344-
)}
345+
perc={percent(successfulDeps.length, deployments.length)}
345346
height="12px"
346347
maxWidth="300px"
347348
progressTitle="Successful deployments"
@@ -366,9 +367,17 @@ export const DeploymentInsightsOverlay = () => {
366367
) : (
367368
<Box sx={{ mb: '10px' }}>
368369
<Line small white>
369-
Deployment trends are only available for repos with workflows as source.{' '}
370+
Deployment trends are only available for repos with
371+
workflows as source.{' '}
370372
<Link href={ROUTES.TEAMS.ROUTE.PATH} passHref>
371-
<Line component="a" small color="primary" bold underline pointer>
373+
<Line
374+
component="a"
375+
small
376+
color="primary"
377+
bold
378+
underline
379+
pointer
380+
>
372381
Go to settings →
373382
</Line>
374383
</Link>
@@ -379,7 +388,7 @@ export const DeploymentInsightsOverlay = () => {
379388
) : (
380389
<>
381390
<FlexBox col flex1>
382-
<Divider sx={{ mt: '10px' }} />
391+
<Divider sx={{ mt: '10px' }} />
383392
<FlexBox gap1 flex1 fullWidth>
384393
<FlexBox col>
385394
<FlexBox p={1} pb={0} gap={1 / 2}>

0 commit comments

Comments
 (0)