This is an automated email from the ASF dual-hosted git repository. hanahmily pushed a commit to branch update-antdpro in repository https://gitbox.apache.org/repos/asf/incubator-skywalking-ui.git
commit f7d231148c3e3fcb0ccec4016dc7d3f97a8c9a3f Author: hanahmily <[email protected]> AuthorDate: Mon Feb 26 10:45:13 2018 +0800 Update utils --- appveyor.yml | 22 ------- src/router.js | 4 +- src/services/graphql.js | 8 +++ src/utils/models.js | 155 ++++++++++++++++++++++++++++++++++++++++++++++++ src/utils/request.js | 25 +------- 5 files changed, 168 insertions(+), 46 deletions(-) diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index ee06d65..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,22 +0,0 @@ -# Test against the latest version of this Node.js version -environment: - nodejs_version: "8" - -# Install scripts. (runs after repo cloning) -install: - # Get the latest stable version of Node.js or io.js - - ps: Install-Product node $env:nodejs_version - # install modules - - npm install - # Output useful info for debugging. - - node --version - - npm --version - -# Post-install test scripts. -test_script: - - npm run lint - - npm run test:all - - npm run build - -# Don't actually build. -build: off diff --git a/src/router.js b/src/router.js index 54eefd1..0f189f7 100644 --- a/src/router.js +++ b/src/router.js @@ -1,7 +1,7 @@ import React from 'react'; import { routerRedux, Switch } from 'dva/router'; import { LocaleProvider, Spin } from 'antd'; -import zhCN from 'antd/lib/locale-provider/zh_CN'; +import enUS from 'antd/lib/locale-provider/en_US'; import dynamic from 'dva/dynamic'; import { getRouterData } from './common/router'; import Authorized from './utils/Authorized'; @@ -18,7 +18,7 @@ function RouterConfig({ history, app }) { const UserLayout = routerData['/user'].component; const BasicLayout = routerData['/'].component; return ( - <LocaleProvider locale={zhCN}> + <LocaleProvider locale={enUS}> <ConnectedRouter history={history}> <Switch> <AuthorizedRoute diff --git a/src/services/graphql.js b/src/services/graphql.js new file mode 100644 index 0000000..1201019 --- /dev/null +++ b/src/services/graphql.js @@ -0,0 +1,8 @@ +import request from '../utils/request'; + +export async function query(namespace, playload) { + return request(`/api/${namespace}`, { + method: 'POST', + body: playload, + }); +} diff --git a/src/utils/models.js b/src/utils/models.js new file mode 100644 index 0000000..f69cb6a --- /dev/null +++ b/src/utils/models.js @@ -0,0 +1,155 @@ +import { query as queryService } from '../services/graphql'; + +export function generateModal({ namespace, dataQuery, optionsQuery, state = {}, + effects = {}, reducers = {}, subscriptions = {} }) { + return { + namespace, + state: { + variables: { + values: {}, + labels: {}, + options: {}, + }, + data: state, + }, + effects: { + *initOptions({ payload }, { call, put }) { + const { variables, reducer = undefined } = payload; + const response = yield call(queryService, `${namespace}/options`, { variables, query: optionsQuery }); + if (reducer) { + yield put({ + type: reducer, + payload: response.data, + }); + } else { + yield put({ + type: 'saveOptions', + payload: response.data, + }); + } + }, + *fetchData({ payload }, { call, put }) { + const { variables, reducer = undefined } = payload; + const response = yield call(queryService, namespace, { variables, query: dataQuery }); + if (reducer) { + yield put({ + type: reducer, + payload: response.data, + }); + } else { + yield put({ + type: 'saveData', + payload: response.data, + }); + } + }, + ...effects, + }, + reducers: { + saveOptions(preState, { payload: allOptions }) { + if (!allOptions) { + return preState; + } + const { variables } = preState; + const { values, labels, options } = variables; + const amendOptions = {}; + const defaultValues = {}; + const defaultLabels = {}; + Object.keys(allOptions).forEach((_) => { + const thisOptions = allOptions[_]; + if (!values[_]) { + if (thisOptions.length > 0) { + defaultValues[_] = thisOptions[0].key; + defaultLabels[_] = thisOptions[0].label; + } + return; + } + const key = values[_]; + if (!thisOptions.find(o => o.key === key)) { + amendOptions[_] = [...thisOptions, { key, label: labels[_] }]; + } + }); + variables.options = { + ...options, + ...allOptions, + ...amendOptions, + }; + let newVariables = variables; + if (Object.keys(defaultValues).length > 0) { + newVariables = { + ...variables, + values: { + ...values, + ...defaultValues, + }, + labels: { + ...labels, + ...defaultLabels, + }, + }; + } + return { + ...preState, + variables: newVariables, + }; + }, + save(preState, { payload: { variables: { values = {}, options = {}, labels = {} }, + data = {} } }) { + const { variables: { values: preValues, options: preOptions, labels: preLabels }, + data: preData } = preState; + return { + variables: { + values: { + ...preValues, + ...values, + }, + options: { + ...preOptions, + ...options, + }, + labels: { + ...preLabels, + ...labels, + }, + }, + data: { + ...preData, + ...data, + }, + }; + }, + saveData(preState, { payload }) { + const { data } = preState; + return { + ...preState, + data: { + ...data, + ...payload, + }, + }; + }, + saveVariables(preState, { payload: { values: variableValues, labels = {} } }) { + const { variables: preVariables } = preState; + const { values: preValues, lables: preLabels } = preVariables; + return { + ...preState, + variables: { + ...preVariables, + values: { + ...preValues, + ...variableValues, + }, + labels: { + ...preLabels, + ...labels, + }, + }, + }; + }, + ...reducers, + }, + subscriptions: { + ...subscriptions, + }, + }; +} diff --git a/src/utils/request.js b/src/utils/request.js index ccabf19..fa8af59 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -4,21 +4,8 @@ import { routerRedux } from 'dva/router'; import store from '../index'; const codeMessage = { - 200: '服务器成功返回请求的数据', - 201: '新建或修改数据成功。', - 202: '一个请求已经进入后台排队(异步任务)', - 204: '删除数据成功。', - 400: '发出的请求有错误,服务器没有进行新建或修改数据,的操作。', - 401: '用户没有权限(令牌、用户名、密码错误)。', - 403: '用户得到授权,但是访问是被禁止的。', - 404: '发出的请求针对的是不存在的记录,服务器没有进行操作', - 406: '请求的格式不可得。', - 410: '请求的资源被永久删除,且不会再得到的。', - 422: '当创建一个对象时,发生一个验证错误。', - 500: '服务器发生错误,请检查服务器', - 502: '网关错误', - 503: '服务不可用,服务器暂时过载或维护', - 504: '网关超时', + 404: 'No resource', + 500: 'Server error', }; function checkStatus(response) { if (response.status >= 200 && response.status < 300) { @@ -26,7 +13,7 @@ function checkStatus(response) { } const errortext = codeMessage[response.status] || response.statusText; notification.error({ - message: `请求错误 ${response.status}: ${response.url}`, + message: `Request Error ${response.status}: ${response.url}`, description: errortext, }); const error = new Error(errortext); @@ -67,12 +54,6 @@ export default function request(url, options) { .catch((e) => { const { dispatch } = store; const status = e.name; - if (status === 401) { - dispatch({ - type: 'login/logout', - }); - return; - } if (status === 403) { dispatch(routerRedux.push('/exception/403')); return; -- To stop receiving notification emails like this one, please contact [email protected].
