Skip to content

Commit c42476c

Browse files
authored
PR Incident Filters UI Component (#658)
* Added Incident PRs Setting * Exclude Revert PR from Incident types based on IncidentPRsSetting and added tests * Core logic for Incident PR filtering * Updated Incident types setting tests * modify core logic for efficiency and add tests for incident prs * Added Incident PR settings slices, types and api * filters component for team incident PRs * Set Include revert PRs default to True * Improved type safety and better variable naming * Improved UI and User experience * Better variable naming and code readability
1 parent 65b1873 commit c42476c

File tree

6 files changed

+541
-7
lines changed

6 files changed

+541
-7
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import * as yup from 'yup';
2+
3+
import { handleRequest } from '@/api-helpers/axios';
4+
import { Endpoint, nullSchema } from '@/api-helpers/global';
5+
import {
6+
TeamIncidentPRsSettingApiResponse,
7+
TeamIncidentPRsSettingsResponse
8+
} from '@/types/resources';
9+
10+
const pathSchema = yup.object().shape({
11+
team_id: yup.string().uuid().required()
12+
});
13+
14+
const putSchema = yup.object().shape({
15+
setting: yup.object().shape({
16+
include_revert_prs: yup.boolean(),
17+
filters: yup.array(
18+
yup.object({
19+
field: yup.string().required(),
20+
value: yup.string().required()
21+
})
22+
)
23+
})
24+
});
25+
26+
const endpoint = new Endpoint(pathSchema);
27+
28+
endpoint.handle.GET(nullSchema, async (req, res) => {
29+
const { team_id } = req.payload;
30+
const { setting } = await handleRequest<TeamIncidentPRsSettingApiResponse>(
31+
`/teams/${team_id}/settings`,
32+
{
33+
method: 'GET',
34+
params: {
35+
setting_type: 'INCIDENT_PRS_SETTING'
36+
}
37+
}
38+
);
39+
return res.send({ setting } as TeamIncidentPRsSettingsResponse);
40+
});
41+
42+
endpoint.handle.PUT(putSchema, async (req, res) => {
43+
const { team_id, setting } = req.payload;
44+
const response = await handleRequest<TeamIncidentPRsSettingApiResponse>(
45+
`/teams/${team_id}/settings`,
46+
{
47+
method: 'PUT',
48+
data: {
49+
setting_type: 'INCIDENT_PRS_SETTING',
50+
setting_data: setting
51+
}
52+
}
53+
);
54+
return res.send({
55+
setting: response.setting
56+
} as TeamIncidentPRsSettingsResponse);
57+
});
58+
59+
export default endpoint.serve();

web-server/src/components/DoraMetricsConfigurationSettings.tsx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@ import { Button, Menu, MenuItem } from '@mui/material';
33
import { useCallback, useRef, useEffect } from 'react';
44

55
import { FlexBox } from '@/components/FlexBox';
6+
import { TeamIncidentPRsFilter } from '@/components/TeamIncidentPRsFilter';
67
import { TeamProductionBranchSelector } from '@/components/TeamProductionBranchSelector';
78
import { isRoleLessThanEM } from '@/constants/useRoute';
89
import { useModal } from '@/contexts/ModalContext';
910
import { useAuth } from '@/hooks/useAuth';
1011
import { useBoolState } from '@/hooks/useEasyState';
1112
import { useSingleTeamConfig } from '@/hooks/useStateTeamConfig';
12-
import { fetchTeamReposProductionBranches } from '@/slices/team';
13+
import {
14+
fetchTeamIncidentPRsFilter,
15+
fetchTeamReposProductionBranches
16+
} from '@/slices/team';
1317
import { useDispatch } from '@/store';
1418

1519
export const DoraMetricsConfigurationSettings = () => {
@@ -20,6 +24,7 @@ export const DoraMetricsConfigurationSettings = () => {
2024
const isEng = isRoleLessThanEM(role);
2125
useEffect(() => {
2226
dispatch(fetchTeamReposProductionBranches({ team_id: singleTeamId }));
27+
dispatch(fetchTeamIncidentPRsFilter({ team_id: singleTeamId }));
2328
}, [dispatch, singleTeamId]);
2429

2530
const openProductionBranchSelectorModal = useCallback(async () => {
@@ -32,6 +37,14 @@ export const DoraMetricsConfigurationSettings = () => {
3237
});
3338
}, [addModal, closeModal]);
3439

40+
const openIncidentPRFilterModal = useCallback(async () => {
41+
const modal = addModal({
42+
title: `Configure Filters for Incident PRs`,
43+
body: <TeamIncidentPRsFilter onClose={() => closeModal(modal.key)} />,
44+
showCloseIcon: true
45+
});
46+
}, [addModal, closeModal]);
47+
3548
const anchorEl = useRef(null);
3649
const open = useBoolState(false);
3750

@@ -74,6 +87,14 @@ export const DoraMetricsConfigurationSettings = () => {
7487
>
7588
Configure Production Branches
7689
</MenuItem>
90+
<MenuItem
91+
onClick={() => {
92+
open.false();
93+
openIncidentPRFilterModal();
94+
}}
95+
>
96+
Configure Filters for Incident PRs
97+
</MenuItem>
7798
</Menu>
7899
</>
79100
);

0 commit comments

Comments
 (0)