Skip to content

Commit

Permalink
feat: 默认值系统
Browse files Browse the repository at this point in the history
  • Loading branch information
bigfengyu committed Nov 15, 2019
1 parent f962e58 commit e569328
Show file tree
Hide file tree
Showing 13 changed files with 303 additions and 99 deletions.
5 changes: 3 additions & 2 deletions dispatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ cluster.setupMaster({
})

if (cluster.isMaster) {
require('os').cpus().forEach((cpu, index) => {
const maxSize = +process.env.SIGMA_MAX_PROCESSORS_LIMIT || +process.env.AJDK_MAX_PROCESSORS_LIMIT || require('os').cpus().length
for (let i = 0; i < maxSize; i++) {
cluster.fork()
})
}
cluster.on('listening', (worker, address) => {
console.error(`[${now()}] master#${process.pid} worker#${worker.process.pid} is now connected to ${address.address}:${address.port}.`)
})
Expand Down
96 changes: 48 additions & 48 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -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"
Expand Down
1 change: 0 additions & 1 deletion scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ app.use(async (ctx, next) => {
const ms = new Date() - start
console.log(`${ctx.method} ${ctx.url} - ${ms}ms`)
})

app.use(async (ctx, next) => {
await next()
if (ctx.response.body && ctx.response.body.url) {
Expand Down
16 changes: 15 additions & 1 deletion src/actions/repository.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { IDefaultVal } from 'components/editor/DefaultValueModal'

export const addRepository = (repository: any, onResolved: any) => ({ type: 'REPOSITORY_ADD', repository, onResolved })
export const addRepositorySucceeded = (repository: any) => ({ type: 'REPOSITORY_ADD_SUCCEEDED', repository })
export const addRepositoryFailed = (message: any) => ({ type: 'REPOSITORY_ADD_FAILED', message })
Expand Down Expand Up @@ -26,7 +28,7 @@ export const fetchRepositoryCount = () => ({ type: 'REPOSITORY_COUNT_FETCH' })
export const fetchRepositoryCountSucceeded = (count: any) => ({ type: 'REPOSITORY_COUNT_FETCH_SUCCEEDED', count })
export const fetchRepositoryCountFailed = (message: any) => ({ type: 'REPOSITORY_COUNT_FETCH_FAILED', message })

export const fetchRepositoryList = ({ user, organization, name, cursor, limit } = {user: '', organization: '', name: '', cursor: '', limit: ''}) => ({ type: 'REPOSITORY_LIST_FETCH', user, organization, name, cursor, limit })
export const fetchRepositoryList = ({ user, organization, name, cursor, limit } = { user: '', organization: '', name: '', cursor: '', limit: '' }) => ({ type: 'REPOSITORY_LIST_FETCH', user, organization, name, cursor, limit })
export const fetchRepositoryListSucceeded = (repositories: any) => ({ type: 'REPOSITORY_LIST_FETCH_SUCCEEDED', repositories })
export const fetchRepositoryListFailed = (message: any) => ({ type: 'REPOSITORY_LIST_FETCH_FAILED', message })
export const fetchOwnedRepositoryList = (
Expand All @@ -40,3 +42,15 @@ export const fetchJoinedRepositoryList = (
) => ({ type: 'JOINED_REPOSITORY_LIST_FETCH', user, name })
export const fetchJoinedRepositoryListSucceeded = (repositories: any) => ({ type: 'JOINED_REPOSITORY_LIST_FETCH_SUCCEEDED', repositories })
export const fetchJoinedRepositoryListFailed = (message: any) => ({ type: 'JOINED_REPOSITORY_LIST_FETCH_FAILED', message })

export const fetchDefaultVals = (id: number) => ({ type: 'DEFAULT_VALS_FETCH', payload: { id } })
export const fetchDefaultValsSucceeded = (data: IDefaultVal[]) => ({ type: 'DEFAULT_VALS_SUCCEEDED', payload: { data } })
export const fetchDefaultValsFailed = (payload: { message: string }) => ({ type: 'DEFAULT_VALS_FAILED', payload })

export type IFetchDefaultValsAction = ReturnType<typeof fetchDefaultVals>

export const updateDefaultVals = (id: number, data: IDefaultVal[]) => ({ type: 'UPDATE_DEFAULT_VALS_FETCH', payload: { id, data } })
export const updateDefaultValsSucceeded = () => ({ type: 'UPDATE_DEFAULT_VALS_SUCCEEDED' })
export const updateDefaultValsFailed = (payload: { message: string }) => ({ type: 'UPDATE_DEFAULT_VALS_FAILED', payload })

export type IUpdateDefaultValsAction = ReturnType<typeof updateDefaultVals>
164 changes: 164 additions & 0 deletions src/components/editor/DefaultValueModal.tsx
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)
1 change: 0 additions & 1 deletion src/components/editor/InterfaceForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ function InterfaceForm(props: Props) {
label="简介"
component={TextField}
multiline={true}
rows={4}
fullWidth={true}
/>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/editor/InterfaceSummary.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e569328

Please sign in to comment.