-
Notifications
You must be signed in to change notification settings - Fork 254
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
bigfengyu
committed
Nov 15, 2019
1 parent
f962e58
commit e569328
Showing
13 changed files
with
303 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,54 +23,54 @@ | |
"author": "[email protected]", | ||
"license": "ISC", | ||
"dependencies": { | ||
"@material-ui/core": "^4.2.0", | ||
"@material-ui/icons": "^4.2.1", | ||
"@material-ui/pickers": "^3.1.2", | ||
"@material-ui/styles": "^4.2.0", | ||
"@material-ui/core": "^4.4.3", | ||
"@material-ui/icons": "^4.4.3", | ||
"@material-ui/pickers": "^3.2.6", | ||
"@material-ui/styles": "^4.4.3", | ||
"@types/json5": "^0.0.30", | ||
"animate.css": "3.7.2", | ||
"awesome-debounce-promise": "^2.1.0", | ||
"chart.js": "^2.8.0", | ||
"classnames": "^2.2.6", | ||
"clipboard-copy": "^3.1.0", | ||
"codemirror": "5.48.0", | ||
"connected-react-router": "^6.5.0", | ||
"codemirror": "5.49.0", | ||
"connected-react-router": "^6.5.2", | ||
"debounce-promise": "^3.1.2", | ||
"formik": "^1.5.7", | ||
"formik-material-ui": "^0.0.19", | ||
"formik": "^1.5.8", | ||
"formik-material-ui": "^0.0.22", | ||
"graceful": "1.0.2", | ||
"history": "^4.9.0", | ||
"history": "^4.10.1", | ||
"jquery": "^3.4.1", | ||
"json5": "^2.1.0", | ||
"koa": "2.7.0", | ||
"koa": "2.8.1", | ||
"koa-router": "7.4.0", | ||
"koa-session": "5.12.2", | ||
"koa-session": "5.12.3", | ||
"koa-static": "5.0.0", | ||
"lodash": "4.17.13", | ||
"mockjs": "1.0.1-beta3", | ||
"lodash": "4.17.15", | ||
"mockjs": "1.1.0", | ||
"moment": "2.24.0", | ||
"node-fetch": "2.6.0", | ||
"normalizr": "^3.4.0", | ||
"notistack": "^0.8.9", | ||
"normalizr": "^3.4.1", | ||
"notistack": "^0.9.2", | ||
"nprogress": "0.2.0", | ||
"parsleyjs": "^2.9.1", | ||
"popper.js": "^1.15.0", | ||
"prop-types": "15.7.2", | ||
"rc-tooltip": "^3.7.3", | ||
"react": "^16.8.6", | ||
"react-dom": "^16.8.6", | ||
"react": "^16.9.0", | ||
"react-dom": "^16.9.0", | ||
"react-hotkeys": "^2.0.0", | ||
"react-icons": "3.7.0", | ||
"react-modal": "3.8.2", | ||
"react-redux": "^7.1.0", | ||
"react-router": "5.0.1", | ||
"react-router-config": "5.0.1", | ||
"react-router-dom": "5.0.1", | ||
"react-select": "^3.0.4", | ||
"redux": "4.0.3", | ||
"redux-saga": "1.0.5", | ||
"react-modal": "3.10.1", | ||
"react-redux": "^7.1.1", | ||
"react-router": "5.1.0", | ||
"react-router-config": "5.1.0", | ||
"react-router-dom": "5.1.0", | ||
"react-select": "^3.0.5", | ||
"redux": "4.0.4", | ||
"redux-saga": "1.1.1", | ||
"reselect": "^4.0.0", | ||
"sortablejs": "1.9.0", | ||
"sortablejs": "1.10.0", | ||
"urijs": "1.19.1", | ||
"yup": "^0.27.0" | ||
}, | ||
|
@@ -84,36 +84,36 @@ | |
] | ||
}, | ||
"devDependencies": { | ||
"@types/chart.js": "^2.7.55", | ||
"@types/chart.js": "^2.8.5", | ||
"@types/classnames": "^2.2.9", | ||
"@types/codemirror": "^0.0.76", | ||
"@types/history": "^4.7.2", | ||
"@types/jest": "^24.0.15", | ||
"@types/jquery": "^3.3.30", | ||
"@types/lodash": "^4.14.136", | ||
"@types/codemirror": "^0.0.77", | ||
"@types/history": "^4.7.3", | ||
"@types/jest": "^24.0.18", | ||
"@types/jquery": "^3.3.31", | ||
"@types/lodash": "^4.14.140", | ||
"@types/mockjs": "^1.0.2", | ||
"@types/node": "^12.6.2", | ||
"@types/node": "^12.7.8", | ||
"@types/nprogress": "^0.2.0", | ||
"@types/rc-tooltip": "^3.7.1", | ||
"@types/react": "^16.8.23", | ||
"@types/react-dom": "^16.8.4", | ||
"@types/react-modal": "^3.8.2", | ||
"@types/react-redux": "^7.1.1", | ||
"@types/react-router-config": "^5.0.0", | ||
"@types/react-router-dom": "^4.3.4", | ||
"@types/react-select": "^3.0.0", | ||
"@types/react": "^16.9.3", | ||
"@types/react-dom": "^16.9.1", | ||
"@types/react-modal": "^3.8.3", | ||
"@types/react-redux": "^7.1.4", | ||
"@types/react-router-config": "^5.0.1", | ||
"@types/react-router-dom": "^5.1.0", | ||
"@types/react-select": "^3.0.4", | ||
"@types/sortablejs": "^1.7.2", | ||
"@types/urijs": "^1.19.3", | ||
"@types/yup": "^0.26.21", | ||
"@types/urijs": "^1.19.4", | ||
"@types/yup": "^0.26.24", | ||
"sass": "^1.23.2", | ||
"npm-run-all": "4.1.5", | ||
"pre-commit": "^1.2.2", | ||
"react-scripts": "^3.0.1", | ||
"standard": "12.0.1", | ||
"tslint": "^5.18.0", | ||
"tslint-react": "^4.0.0", | ||
"tslint-react-hooks": "^2.1.1", | ||
"typescript": "^3.5.3" | ||
"react-scripts": "^3.1.2", | ||
"standard": "14.3.1", | ||
"tslint": "^5.20.0", | ||
"tslint-react": "^4.1.0", | ||
"tslint-react-hooks": "^2.2.1", | ||
"typescript": "^3.6.3" | ||
}, | ||
"pre-commit": [ | ||
"lint" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
import React, { useState, useEffect } from 'react' | ||
import { createStyles, makeStyles, Theme } from '@material-ui/core/styles' | ||
import Button from '@material-ui/core/Button' | ||
import Dialog from '@material-ui/core/Dialog' | ||
import AppBar from '@material-ui/core/AppBar' | ||
import Toolbar from '@material-ui/core/Toolbar' | ||
import IconButton from '@material-ui/core/IconButton' | ||
import Typography from '@material-ui/core/Typography' | ||
import CloseIcon from '@material-ui/icons/Close' | ||
import Slide from '@material-ui/core/Slide' | ||
import TextField from '@material-ui/core/TextField' | ||
import { TransitionProps } from '@material-ui/core/transitions' | ||
import { Table, TableHead, TableRow, TableCell, TableBody, DialogContent } from '@material-ui/core' | ||
import Delete from '@material-ui/icons/Delete' | ||
import { useDispatch, useSelector } from 'react-redux' | ||
import { fetchDefaultVals, updateDefaultVals } from 'actions/repository' | ||
import { withSnackbar, WithSnackbarProps } from 'notistack' | ||
|
||
export interface IDefaultVal { | ||
name: string | ||
rule: string | ||
value: string | ||
} | ||
|
||
const useStyles = makeStyles(({ spacing }: Theme) => | ||
createStyles({ | ||
appBar: { | ||
position: 'relative', | ||
}, | ||
title: { | ||
marginLeft: spacing(2), | ||
flex: 1, | ||
}, | ||
btn: { | ||
marginBottom: spacing(2), | ||
marginTop: spacing(2), | ||
}, | ||
topHint: { | ||
marginBottom: spacing(2), | ||
marginTop: spacing(2), | ||
}, | ||
}) | ||
) | ||
|
||
const Transition = React.forwardRef<unknown, TransitionProps>((props, ref) => { | ||
return <Slide direction="up" ref={ref} {...props} /> | ||
}) | ||
|
||
function DefaultValueModal({ open, handleClose, repositoryId, enqueueSnackbar }: | ||
{ open: boolean, handleClose: () => void, repositoryId: number } & WithSnackbarProps) { | ||
const classes = useStyles() | ||
const [editingData, setEditingData] = useState<IDefaultVal[]>([]) | ||
const dispatch = useDispatch() | ||
|
||
useEffect(() => { | ||
dispatch(fetchDefaultVals(repositoryId)) | ||
}, [repositoryId]) | ||
const defaultVals: IDefaultVal[] = useSelector((state: any) => state.defaultVals) | ||
|
||
useEffect(() => { | ||
setEditingData(defaultVals) | ||
}, [defaultVals]) | ||
|
||
const addNewLine = () => { | ||
setEditingData([...editingData, { | ||
name: '', | ||
rule: '', | ||
value: '', | ||
}]) | ||
} | ||
|
||
const onChange = (key: keyof IDefaultVal, i: number, val: string) => { | ||
setEditingData(editingData.map((x, j) => { | ||
if (j === i) { | ||
return { | ||
...x, | ||
[key]: val, | ||
} | ||
} | ||
return x | ||
})) | ||
} | ||
|
||
const onDelete = (i: number) => { | ||
setEditingData(editingData.filter((_, j) => i !== j)) | ||
} | ||
|
||
const onSubmit = () => { | ||
dispatch(updateDefaultVals(repositoryId, editingData)) | ||
handleClose() | ||
enqueueSnackbar(`更新默认值成功`, { | ||
variant: 'success', | ||
autoHideDuration: 1000, | ||
}) | ||
} | ||
|
||
return ( | ||
<Dialog fullScreen={true} open={open} onClose={handleClose} TransitionComponent={Transition}> | ||
<AppBar className={classes.appBar}> | ||
<Toolbar> | ||
<IconButton edge="start" color="inherit" onClick={handleClose} aria-label="close"> | ||
<CloseIcon /> | ||
</IconButton> | ||
<Typography variant="h6" className={classes.title}>默认值配置</Typography> | ||
<Button color="inherit" onClick={onSubmit}> | ||
保存 | ||
</Button> | ||
</Toolbar> | ||
</AppBar> | ||
<DialogContent> | ||
<div className={classes.topHint}> | ||
<Typography variant="body1"> 系统将根据变量名进行搜索,如果生成规则和初始值均未填写,系统才会对同名参数的Mock规则进行覆盖。</Typography> | ||
</div> | ||
<div className={classes.btn}> | ||
<Button onClick={addNewLine} color="primary" variant="contained" size="small">添加一行</Button> | ||
</div> | ||
<Table> | ||
<TableHead> | ||
<TableRow> | ||
<TableCell>变量名</TableCell> | ||
<TableCell>生成规则</TableCell> | ||
<TableCell>初始值</TableCell> | ||
<TableCell /> | ||
</TableRow> | ||
</TableHead> | ||
<TableBody> | ||
{editingData.map((row, i) => ( | ||
<TableRow key={i}> | ||
<TableCell component="th" scope="row"> | ||
<TextField | ||
value={row.name} | ||
onChange={e => onChange('name', i, e.target.value)} | ||
placeholder="请输入变量名" | ||
/> | ||
</TableCell> | ||
<TableCell> | ||
<TextField | ||
value={row.rule} | ||
onChange={e => onChange('rule', i, e.target.value)} | ||
placeholder="请输入生成规则" | ||
/> | ||
</TableCell> | ||
<TableCell> | ||
<TextField | ||
value={row.value} | ||
onChange={e => onChange('value', i, e.target.value)} | ||
placeholder="请输入初始值" | ||
/> | ||
</TableCell> | ||
<TableCell> | ||
<Delete | ||
onClick={() => onDelete(i)} | ||
/> | ||
</TableCell> | ||
</TableRow> | ||
))} | ||
</TableBody> | ||
</Table> | ||
</DialogContent> | ||
</Dialog> | ||
) | ||
} | ||
|
||
export default withSnackbar(DefaultValueModal) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.