Skip to content

Commit 30b6c9c

Browse files
authored
Kirillarkhypovwork/mon 1939 alert rule screen redesign (#34)
1 parent 9449117 commit 30b6c9c

24 files changed

+598
-496
lines changed

cypress/e2e/alert_rules_screen.cy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ describe("Alert Rules Screen", () => {
230230

231231
if (alertRuleLogic.value !== undefined)
232232
cy.wrap(form)
233-
.contains("label", "Value")
233+
.contains("label", "Threshold")
234234
.next()
235235
.find("input")
236236
.should("exist")
@@ -360,7 +360,7 @@ describe("Alert Rules Screen", () => {
360360
it("Test closure of rule creation form", () => {
361361
cy.visit("/configuration/alert-rules");
362362
cy.contains("button", "New Alert Rule").should("exist").click();
363-
cy.contains("h1", "Create New Alert").should("exist").next().click();
363+
cy.contains("h2", "Create New Alert Rule").should("exist").next().click();
364364
cy.get("div[role=presentation] > div[role=dialog]").should("not.exist");
365365
});
366366

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { styled, Stack, Dialog, Box, Step } from '@mui/material';
2+
import { MUIBaseButton } from 'components/base/Button/MUIBaseButton';
3+
4+
const StyledDialog = styled(Dialog)({
5+
'& .MuiDialog-paper': { width: '603px', padding: '40px 32px', borderRadius: '20px' }
6+
});
7+
8+
const StyledContentContainer = styled(Stack)({
9+
justifyContent: 'center',
10+
flexDirection: 'column',
11+
alignItems: 'center'
12+
});
13+
14+
const StyledButton = styled(MUIBaseButton)({
15+
width: '99px',
16+
height: '42px'
17+
});
18+
19+
const StyledStepContainer = styled(Box)({
20+
marginTop: '38px',
21+
justifyContent: 'start',
22+
display: 'flex',
23+
flexDirection: 'column',
24+
alignItems: 'center'
25+
});
26+
27+
const StyledStep = styled(Step)(({ theme }) => ({
28+
'& .MuiStepIcon-root': {
29+
color: theme.palette.grey.light
30+
},
31+
32+
'& .MuiStepLabel-root': {
33+
color: theme.palette.primary.main,
34+
35+
'& .Mui-active': {
36+
color: theme.palette.primary.main,
37+
38+
'& .MuiStepIcon-text': {
39+
fill: theme.palette.common.white
40+
}
41+
},
42+
43+
'& .Mui-completed': {
44+
color: theme.palette.grey.light
45+
},
46+
47+
'& .MuiStepIcon-text': {
48+
fill: theme.palette.text.disabled,
49+
fontSize: '14px',
50+
fontWeight: 600
51+
}
52+
},
53+
54+
'& .MuiStepLabel-label': {
55+
color: theme.palette.text.disabled,
56+
fontWeight: 600
57+
}
58+
}));
59+
60+
export { StyledContentContainer, StyledButton, StyledDialog, StyledStepContainer, StyledStep };
Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { Dialog, DialogProps } from '@mui/material';
1+
import React, { useContext, useEffect } from 'react';
2+
23
import {
34
AlertRuleConfigSchema,
45
useCreateAlertRuleApiV1MonitorsMonitorIdAlertRulesPost,
@@ -8,11 +9,17 @@ import {
89
useUpdateAlertApiV1AlertRulesAlertRuleIdPut,
910
useUpdateMonitorApiV1MonitorsMonitorIdPut
1011
} from 'api/generated';
11-
import { Loader } from 'components/Loader';
12-
import React, { useContext, useEffect } from 'react';
13-
import { AlertRuleDialogContent } from './AlertRuleDialogContent';
12+
13+
import { AlertRuleDialogContent } from './components/AlertRuleDialogContent';
1414
import { AlertRuleDialogContext } from './AlertRuleDialogContext';
15-
import { DialogTopBar } from './DialogTopBar';
15+
16+
import { DialogProps } from '@mui/material';
17+
18+
import { ActionDialogHeader } from 'components/base/Dialog/ActionDialog/ActionDialogHeader';
19+
import { Loader } from 'components/Loader';
20+
21+
import { StyledDialog } from './AlertRuleDialog.styles';
22+
import { constants } from './alertRuleDialog.constants';
1623

1724
interface AlertRuleDialogProps extends Omit<DialogProps, 'onClose'> {
1825
alertRuleId?: AlertRuleConfigSchema['id'];
@@ -21,11 +28,14 @@ interface AlertRuleDialogProps extends Omit<DialogProps, 'onClose'> {
2128
}
2229

2330
export const AlertRuleDialog = ({ alertRuleId = 0, onClose, startingStep, ...props }: AlertRuleDialogProps) => {
31+
const { setAlertRule, setMonitor, resetState, monitor, alertRule } = useContext(AlertRuleDialogContext);
32+
2433
const { data: fetchedAlertRule, isLoading: isAlertRuleLoading } =
2534
useGetAlertRuleApiV1AlertRulesAlertRuleIdGet(alertRuleId);
2635
const { data: fetchedMonitor, isLoading: isMonitorLoading } = useGetMonitorApiV1MonitorsMonitorIdGet(
2736
fetchedAlertRule?.monitor_id || 0
2837
);
38+
2939
const { mutateAsync: createMonitor, isLoading: isCreateMonitorLoading } =
3040
useCreateMonitorApiV1ChecksCheckIdMonitorsPost();
3141
const { mutateAsync: createAlertRule, isLoading: isCreateAlertRuleLoading } =
@@ -34,40 +44,33 @@ export const AlertRuleDialog = ({ alertRuleId = 0, onClose, startingStep, ...pro
3444
const { mutateAsync: updateMonitor, isLoading: isUpdateMonitorLoading } = useUpdateMonitorApiV1MonitorsMonitorIdPut();
3545
const { mutateAsync: updateAlertRule, isLoading: isUpdateAlertRuleLoading } =
3646
useUpdateAlertApiV1AlertRulesAlertRuleIdPut();
37-
const { setAlertRule, setMonitor, resetState, monitor, alertRule } = useContext(AlertRuleDialogContext);
3847

3948
useEffect(() => {
40-
if (fetchedAlertRule) {
41-
setAlertRule(fetchedAlertRule);
42-
}
43-
if (fetchedMonitor) {
44-
setMonitor(fetchedMonitor);
45-
}
46-
}, [fetchedAlertRule, fetchedMonitor, setAlertRule, setMonitor]);
49+
if (fetchedAlertRule) setAlertRule(fetchedAlertRule);
50+
}, [fetchedAlertRule, setAlertRule]);
51+
52+
useEffect(() => {
53+
if (fetchedMonitor) setMonitor(fetchedMonitor);
54+
}, [fetchedMonitor, setMonitor]);
4755

4856
const handleClose = () => {
4957
onClose(false);
5058
resetState();
5159
};
5260

5361
const handleComplete = async () => {
54-
// Edit mode
5562
if (alertRuleId !== 0) {
5663
const { id: monitorId, ...editedMonitor } = monitor;
5764

5865
await Promise.all([
5966
updateMonitor({ monitorId, data: editedMonitor }),
6067
updateAlertRule({ alertRuleId, data: alertRule })
6168
]);
62-
63-
// trackAddEditRuleSavedSuccessfully(monitor);
6469
} else {
6570
const { check, ...addedMonitor } = monitor;
6671
const { id: monitorId } = await createMonitor({ checkId: check.id, data: addedMonitor });
6772

6873
await createAlertRule({ monitorId, data: alertRule });
69-
70-
// trackAddEditRuleSavedSuccessfully(monitor);
7174
}
7275

7376
onClose(true);
@@ -80,23 +83,17 @@ export const AlertRuleDialog = ({ alertRuleId = 0, onClose, startingStep, ...pro
8083
isCreateAlertRuleLoading ||
8184
isUpdateMonitorLoading ||
8285
isUpdateAlertRuleLoading;
86+
8387
return (
84-
<Dialog
85-
fullWidth={true}
86-
maxWidth={false}
87-
// TransitionComponent={Transition}
88-
onClose={() => handleClose()}
89-
{...props}
90-
sx={{ '& .MuiDialog-paper': { p: '0 40px' } }}
91-
>
88+
<StyledDialog onClose={handleClose} {...props}>
9289
{isLoading ? (
9390
<Loader />
9491
) : (
9592
<>
96-
<DialogTopBar handleClose={handleClose} />
93+
<ActionDialogHeader title={constants.dialogHeader(monitor?.name)} onClose={handleClose} />
9794
<AlertRuleDialogContent startingStep={startingStep} handleComplete={handleComplete} />
9895
</>
9996
)}
100-
</Dialog>
97+
</StyledDialog>
10198
);
10299
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export interface AlertRuleStepBaseProps {
2+
activeStep: number;
3+
handleNext: () => void;
4+
handleBack?: () => void;
5+
}

frontend/src/components/AlertRuleDialog/AlertRuleDialogContent.tsx

Lines changed: 0 additions & 86 deletions
This file was deleted.

frontend/src/components/AlertRuleDialog/DialogTopBar.tsx

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)