cl
22 小时以前 c4bba32b20f0869b45ed14be04543869dd91ee6c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import React from "react";
import {
    CreateBase,
    TextInput,
    NumberInput,
    SaveButton,
    SelectInput,
    Toolbar,
    Form,
    required,
    useNotify,
    useTranslate,
} from 'react-admin';
import { Dialog, DialogContent, DialogTitle, Grid, Box } from '@mui/material';
import DialogCloseButton from "@/page/components/DialogCloseButton";
 
const HttpAuditRuleCreate = (props) => {
    const { open, setOpen } = props;
    const notify = useNotify();
    const translate = useTranslate();
 
    const ruleTypeChoices = [
        { id: 'URI', name: translate('table.field.httpAuditRule.ruleType.URI') },
        { id: 'IP', name: translate('table.field.httpAuditRule.ruleType.IP') },
        { id: 'REQUEST_BODY', name: translate('table.field.httpAuditRule.ruleType.REQUEST_BODY') },
    ];
    const matchModeChoices = [
        { id: 'EQUAL', name: translate('table.field.httpAuditRule.matchMode.EQUAL') },
        { id: 'PREFIX', name: translate('table.field.httpAuditRule.matchMode.PREFIX') },
        { id: 'CONTAINS', name: translate('table.field.httpAuditRule.matchMode.CONTAINS') },
        { id: 'REGEX', name: translate('table.field.httpAuditRule.matchMode.REGEX') },
    ];
    const directionChoices = [
        { id: 'IN', name: translate('table.field.httpAuditRule.direction.IN') },
        { id: 'OUT', name: translate('table.field.httpAuditRule.direction.OUT') },
        { id: 'BOTH', name: translate('table.field.httpAuditRule.direction.BOTH') },
    ];
 
    const handleClose = (event, reason) => {
        if (reason !== "backdropClick") setOpen(false);
    };
 
    const handleSuccess = () => {
        setOpen(false);
        notify('新增成功');
    };
 
    const handleError = (error) => {
        notify(error?.message || '新增失败', { type: 'error' });
    };
 
    return (
        <CreateBase
            resource="httpAuditRule"
            record={{ direction: 'IN', recordAll: 0 }}
            mutationOptions={{ onSuccess: handleSuccess, onError: handleError }}
        >
            <Dialog
                open={open}
                onClose={handleClose}
                fullWidth
                disableRestoreFocus
                maxWidth="md"
            >
                <Form>
                    <DialogTitle sx={{ position: 'sticky', top: 0, backgroundColor: 'background.paper', zIndex: 1000 }}>
                        {translate('resources.httpAuditRule.createTitle')}
                        <Box sx={{ position: 'absolute', top: 8, right: 8, zIndex: 1001 }}>
                            <DialogCloseButton onClose={handleClose} />
                        </Box>
                    </DialogTitle>
                    <DialogContent sx={{ mt: 2 }}>
                        <Grid container rowSpacing={2} columnSpacing={2}>
                            <Grid item xs={12} sm={6}>
                                <SelectInput
                                    source="ruleType"
                                    label="table.field.httpAuditRule.ruleTypeLabel"
                                    choices={ruleTypeChoices}
                                    validate={required()}
                                    fullWidth
                                />
                            </Grid>
                            <Grid item xs={12} sm={6}>
                                <SelectInput
                                    source="matchMode"
                                    label="table.field.httpAuditRule.matchModeLabel"
                                    choices={matchModeChoices}
                                    validate={required()}
                                    fullWidth
                                />
                            </Grid>
                            <Grid item xs={12}>
                                <TextInput
                                    source="pattern"
                                    label="table.field.httpAuditRule.pattern"
                                    validate={required()}
                                    fullWidth
                                    multiline
                                    minRows={2}
                                />
                            </Grid>
                            <Grid item xs={12} sm={6}>
                                <SelectInput
                                    source="direction"
                                    label="table.field.httpAuditRule.directionLabel"
                                    choices={directionChoices}
                                    fullWidth
                                />
                            </Grid>
                            <Grid item xs={12} sm={6}>
                                <SelectInput
                                    source="recordAll"
                                    label="table.field.httpAuditRule.recordAll"
                                    choices={[
                                        { id: 1, name: translate('table.field.httpAuditRule.recordAllOn') },
                                        { id: 0, name: translate('table.field.httpAuditRule.recordAllOff') },
                                    ]}
                                    fullWidth
                                />
                            </Grid>
                            <Grid item xs={12} sm={6}>
                                <NumberInput source="requestMaxChars" label="table.field.httpAuditRule.requestMaxChars" fullWidth />
                            </Grid>
                            <Grid item xs={12} sm={6}>
                                <NumberInput source="responseMaxChars" label="table.field.httpAuditRule.responseMaxChars" fullWidth />
                            </Grid>
                            <Grid item xs={12} sm={6}>
                                <SelectInput
                                    source="enabled"
                                    label="table.field.httpAuditRule.enabled"
                                    choices={[
                                        { id: 1, name: translate('table.field.httpAuditRule.enabledOn') },
                                        { id: 0, name: translate('table.field.httpAuditRule.enabledOff') },
                                    ]}
                                    defaultValue={1}
                                    fullWidth
                                />
                            </Grid>
                            <Grid item xs={12} sm={6}>
                                <NumberInput source="sortOrder" label="table.field.httpAuditRule.sortOrder" defaultValue={0} fullWidth />
                            </Grid>
                            <Grid item xs={12}>
                                <TextInput source="remark" label="table.field.httpAuditRule.remark" fullWidth multiline minRows={2} />
                            </Grid>
                        </Grid>
                    </DialogContent>
                    <Box sx={{ position: 'sticky', bottom: 0, backgroundColor: 'background.paper', zIndex: 1000, p: 2, display: 'flex', justifyContent: 'flex-end' }}>
                        <Toolbar><SaveButton /></Toolbar>
                    </Box>
                </Form>
            </Dialog>
        </CreateBase>
    );
};
 
export default HttpAuditRuleCreate;