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;
|