Skip to content

Commit

Permalink
feat: fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Bosn committed Aug 3, 2020
1 parent 022ad46 commit 8ebcb42
Show file tree
Hide file tree
Showing 16 changed files with 116 additions and 91 deletions.
32 changes: 14 additions & 18 deletions src/actions/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { RouterState } from 'connected-react-router'
import { THEME_TEMPLATE_KEY } from 'components/account/ThemeChangeOverlay'
import { POS_TYPE } from 'components/editor/InterfaceSummary'

export interface RootState {
auth: {
Expand Down Expand Up @@ -115,8 +116,6 @@ export interface RepositoryFormData {

collaboratorIdstring?: string

canUserEdit?: boolean

token?: string

modules?: Module[]
Expand Down Expand Up @@ -207,23 +206,20 @@ export interface Interface {
status?: number
}

export type Property = {
name: string;
type: any;
rule: string;
value: any;
descripton: string;
creator: any;
repositoryId: number;
moduleId: number;
interfaceId: number;
scope: string;
parentId: number;
memory: boolean;
id: number;
}

export type Async<T> = {
data: T
fetching: boolean
}
export interface Property {
id: number | string
name: string
description: string
parentId: number | string
interfaceId: number
moduleId: number
repositoryId: number
scope: 'request' | 'response'
value: string
memory: boolean
pos: POS_TYPE
}
2 changes: 1 addition & 1 deletion src/assets/index.css.map

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

24 changes: 6 additions & 18 deletions src/components/editor/Importer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import React, { Component } from 'react'
import { connect, Link, Mock, _, PropTypes } from '../../family'
import { RCodeMirror } from '../utils/'
import { addProperty } from '../../actions/property'
import { RootState } from 'actions/types'
import { RootState, User, Property } from 'actions/types'
import JSON5 from 'json5'
import { Button } from '@material-ui/core'
import { POS_TYPE } from './InterfaceSummary'
const mockResult =
process.env.NODE_ENV === 'development'
? () => ({
Expand Down Expand Up @@ -78,6 +79,7 @@ type ImporterProps = {
handleAddMemoryProperties: (...args: any[]) => any,
interfaceId: number
[k: string]: any;
pos: POS_TYPE
}
type ImporterState = {
result: string
Expand Down Expand Up @@ -142,9 +144,9 @@ class Importer extends Component<ImporterProps, ImporterState> {
};
// TODO 2.1 待完整测试各种输入
// DONE 2.1 BUG 类型 Number,初始值 '',被解析为随机字符串
handleJSONSchema = (schema: any, parent = { id: -1 }, memoryProperties: any, siblings?: any) => {
handleJSONSchema = (schema: any, parent = { id: -1 } as { id: number | string }, memoryProperties: any, siblings?: any) => {
if (!schema) { return }
const { auth, repository, mod, interfaceId, scope } = this.props
const { auth, repository, mod, interfaceId, scope, pos } = this.props
const hasSiblings = siblings instanceof Array && siblings.length > 0
// DONE 2.1 需要与 Mock 的 rule.type 规则统一,首字符小写,好烦!应该忽略大小写!
if (schema.name === lengthAlias) {
Expand Down Expand Up @@ -181,28 +183,14 @@ class Importer extends Component<ImporterProps, ImporterState> {
}
}

type Property = {
name: any;
type: any;
rule: string;
value: any;
description: string;
creator: any;
repositoryId: any;
moduleId: any;
interfaceId: any;
scope: any;
parentId: number;
memory: boolean;
id: any;
}
const property: Property = Object.assign(
{
name: schema.name,
type,
rule,
value,
description: '',
pos,
},
{
creator: auth.id,
Expand Down
53 changes: 46 additions & 7 deletions src/components/editor/InterfaceEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import InterfaceSummary from './InterfaceSummary'
import PropertyList from './PropertyList'
import MoveInterfaceForm from './MoveInterfaceForm'
import { fetchRepository } from '../../actions/repository'
import { RootState } from 'actions/types'
import { RootState, Property } from 'actions/types'
import { lockInterface, unlockInterface, fetchInterface } from 'actions/interface'
import { updateProperties } from 'actions/property'
import { updateInterface } from 'actions/interface'
import Spin from '../../components/utils/Spin'
import { showMessage, MSG_TYPE } from 'actions/common'

export const RequestPropertyList = (props: any) => {
return <PropertyList scope="request" title="请求参数" label="请求" {...props} />
Expand All @@ -27,12 +28,13 @@ type InterfaceEditorProps = {
unlockInterface: typeof unlockInterface
updateInterface: typeof updateInterface
updateProperties: typeof updateProperties
showMessage: typeof showMessage
}

type InterfaceEditorState = {
summaryState: any
itf: any
properties: any
properties: Property[]
editable: boolean
moveInterfaceDialogOpen: boolean
}
Expand Down Expand Up @@ -97,7 +99,7 @@ class InterfaceEditor extends Component<InterfaceEditorProps, InterfaceEditorSta
fetchInterfaceProperties() {
// 发现接口信息没有 properties 就发起请求
if (this.state.properties === undefined) {
this.props.fetchInterface(this.state.itf.id, () => {})
this.props.fetchInterface(this.state.itf.id, () => { })
}
}

Expand Down Expand Up @@ -166,8 +168,8 @@ class InterfaceEditor extends Component<InterfaceEditorProps, InterfaceEditorSta
/>
</>
) : (
<Spin />
)}
<Spin />
)}

{this.state.moveInterfaceDialogOpen && (
<MoveInterfaceForm
Expand Down Expand Up @@ -243,11 +245,47 @@ class InterfaceEditor extends Component<InterfaceEditorProps, InterfaceEditorSta
e.preventDefault()
const { itf } = this.state
const { updateProperties, updateInterface } = this.props
if (!itf.name.trim()) {
this.props.showMessage('名称不能为空', MSG_TYPE.WARNING)
return
}

if (!itf.url.trim()) {
this.props.showMessage('URL地址不能为空', MSG_TYPE.WARNING)
return
}

if (itf.url.substring(0, 4) !== 'http' && itf.url[0] !== '/') {
this.props.showMessage('合法的URL地址,需以 http 或 / 开头,例如/a/b 或者 https://www.taobao.com', MSG_TYPE.WARNING)
return
}

// 判断参数命名冲突
const pMap: { [key: string]: number } = {}
const getPKey = (p: Property) => `${p.name}|${p.parentId}|${p.scope}`
for (const p of this.state.properties) {
if (!p.name.trim()) {
this.props.showMessage(`有参数未命名,请检查...${p.description ? '描述为:' + p.description : ''}`, MSG_TYPE.WARNING)
return
}
p.name = p.name.trim()
const key = getPKey(p)
if (pMap[key]) {
pMap[key]++
} else {
pMap[key] = 1
}
if (pMap[key] > 1) {
this.props.showMessage(`参数${p.name}命名冲突,同层级不能有相同的属性名`, MSG_TYPE.WARNING)
return
}
}

updateInterface(
{
id: itf.id,
name: itf.name,
url: itf.url,
name: itf.name.trim(),
url: itf.url.trim(),
method: itf.method,
status: itf.status,
description: itf.description,
Expand Down Expand Up @@ -293,5 +331,6 @@ const mapDispatchToProps = {
unlockInterface,
updateProperties,
updateInterface,
showMessage,
}
export default connect(mapStateToProps, mapDispatchToProps)(InterfaceEditor)
Loading

0 comments on commit 8ebcb42

Please sign in to comment.