This is an automated email from the ASF dual-hosted git repository. juzhiyuan pushed a commit to branch feat-setting in repository https://gitbox.apache.org/repos/asf/incubator-apisix-dashboard.git
commit e030adc90615f12c5541247a95e1a6143220234f Author: juzhiyuan <[email protected]> AuthorDate: Mon May 25 06:14:10 2020 +0800 feat: refactor setting --- config/config.ts | 12 +----------- src/app.tsx | 2 +- src/pages/{ => Settings}/Settings.tsx | 3 ++- src/pages/Settings/constant.ts | 7 +++++++ src/pages/Settings/index.ts | 2 ++ src/{utils/setting.ts => pages/Settings/service.ts} | 21 ++++++++++++++++++--- src/pages/Settings/typing.d.ts | 9 +++++++++ src/pages/ssl/List.tsx | 2 +- src/pages/ssl/typing.d.ts | 2 +- src/typings.d.ts | 14 -------------- 10 files changed, 42 insertions(+), 32 deletions(-) diff --git a/config/config.ts b/config/config.ts index ab1862e..b332ab4 100644 --- a/config/config.ts +++ b/config/config.ts @@ -4,12 +4,7 @@ import defaultSettings from './defaultSettings'; import proxy from './proxy'; import routes from './routes'; -const { REACT_APP_ENV, NODE_ENV } = process.env; - -const getRequestPrefix = () => { - if (NODE_ENV === 'development') return '/api'; - return ''; -}; +const { REACT_APP_ENV } = process.env; export default defineConfig({ hash: true, @@ -38,11 +33,6 @@ export default defineConfig({ publicPath: '/', define: { REACT_APP_ENV: REACT_APP_ENV || false, - ADMIN_API_SCHEMA: 'http', - ADMIN_API_HOST: '127.0.0.1:9080', - ADMIN_API_PATH: '/apisix/admin', - API_KEY: '', - API_REQUEST_PREFIX: getRequestPrefix(), }, // Theme for antd: https://ant.design/docs/react/customize-theme-cn theme: { diff --git a/src/app.tsx b/src/app.tsx index 9e5d5fd..70ce2e1 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -3,7 +3,7 @@ import { notification } from 'antd'; import { RequestConfig, history } from 'umi'; import { BasicLayoutProps, Settings as LayoutSettings } from '@ant-design/pro-layout'; -import { getAdminAPIConfig } from '@/utils/setting'; +import { getAdminAPIConfig } from '@/pages/Settings'; import RightContent from '@/components/RightContent'; import Footer from '@/components/Footer'; import { queryCurrent } from '@/services/user'; diff --git a/src/pages/Settings.tsx b/src/pages/Settings/Settings.tsx similarity index 98% rename from src/pages/Settings.tsx rename to src/pages/Settings/Settings.tsx index 193d88c..4589c79 100644 --- a/src/pages/Settings.tsx +++ b/src/pages/Settings/Settings.tsx @@ -3,7 +3,8 @@ import { useForm } from 'antd/es/form/util'; import { Button, Card, Form, Input, notification, Select } from 'antd'; import { useIntl, FormattedMessage, history } from 'umi'; import { PageHeaderWrapper } from '@ant-design/pro-layout'; -import { getAdminAPIConfig } from '@/utils/setting'; + +import { getAdminAPIConfig } from './service'; const { Option } = Select; diff --git a/src/pages/Settings/constant.ts b/src/pages/Settings/constant.ts new file mode 100644 index 0000000..5bbaa1a --- /dev/null +++ b/src/pages/Settings/constant.ts @@ -0,0 +1,7 @@ +import { getRequestPrefix } from './service'; + +export const ADMIN_API_SCHEMA = 'http'; +export const ADMIN_API_HOST = '127.0.0.1:9080'; +export const ADMIN_API_PATH = '/apisix/admin'; +export const API_KEY = ''; +export const API_REQUEST_PREFIX = getRequestPrefix(); diff --git a/src/pages/Settings/index.ts b/src/pages/Settings/index.ts new file mode 100644 index 0000000..d990ce6 --- /dev/null +++ b/src/pages/Settings/index.ts @@ -0,0 +1,2 @@ +export { default } from './Settings'; +export * from './service'; diff --git a/src/utils/setting.ts b/src/pages/Settings/service.ts similarity index 51% rename from src/utils/setting.ts rename to src/pages/Settings/service.ts index 9b5898c..18cd2c6 100644 --- a/src/utils/setting.ts +++ b/src/pages/Settings/service.ts @@ -1,9 +1,24 @@ -export const getAdminAPIConfig = (): AdminAPIConfig => { +import { + ADMIN_API_HOST, + ADMIN_API_SCHEMA, + ADMIN_API_PATH, + API_KEY, + API_REQUEST_PREFIX, +} from './constant'; + +export const getAdminAPIConfig = (): SettingModule.AdminAPIConfig => { return { schema: localStorage.getItem('GLOBAL_ADMIN_API_SCHEMA') || ADMIN_API_SCHEMA, host: localStorage.getItem('GLOBAL_ADMIN_API_HOST') || ADMIN_API_HOST, path: localStorage.getItem('GLOBAL_ADMIN_API_PATH') || ADMIN_API_PATH, prefix: API_REQUEST_PREFIX, - key: localStorage.getItem('GLOBAL_ADMIN_API_KEY') || API_KEY + key: localStorage.getItem('GLOBAL_ADMIN_API_KEY') || API_KEY, }; -} +}; + +export const getRequestPrefix = () => { + if (process.env.NODE_ENV === 'development') { + return '/api'; + } + return ''; +}; diff --git a/src/pages/Settings/typing.d.ts b/src/pages/Settings/typing.d.ts new file mode 100644 index 0000000..e846281 --- /dev/null +++ b/src/pages/Settings/typing.d.ts @@ -0,0 +1,9 @@ +declare namespace SettingModule { + interface AdminAPIConfig { + schema: string; + host: string; + path: string; + prefix: string; + key: string; + } +} diff --git a/src/pages/ssl/List.tsx b/src/pages/ssl/List.tsx index 5a21d64..16949eb 100644 --- a/src/pages/ssl/List.tsx +++ b/src/pages/ssl/List.tsx @@ -5,8 +5,8 @@ import { Button, Modal, notification, Switch } from 'antd'; import { history, useIntl } from 'umi'; import { PlusOutlined } from '@ant-design/icons'; -import { fetchList as fetchSSLList, remove as removeSSL } from './service'; import { ListItem } from '@/transforms/global'; +import { fetchList as fetchSSLList, remove as removeSSL } from './service'; interface SearchParamsProps { current: number; diff --git a/src/pages/ssl/typing.d.ts b/src/pages/ssl/typing.d.ts index 4799329..337adb6 100644 --- a/src/pages/ssl/typing.d.ts +++ b/src/pages/ssl/typing.d.ts @@ -1,5 +1,5 @@ declare namespace SSLModule { - export type SSL = { + type SSL = { sni: string[]; cert: string; key: string; diff --git a/src/typings.d.ts b/src/typings.d.ts index 6eb33dc..b52e470 100644 --- a/src/typings.d.ts +++ b/src/typings.d.ts @@ -37,20 +37,6 @@ declare let ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION: 'site' | undefine declare const REACT_APP_ENV: 'test' | 'dev' | 'pre' | false; -declare let ADMIN_API_SCHEMA; -declare let ADMIN_API_HOST; -declare let ADMIN_API_PATH; -declare let API_KEY: ''; -declare let API_REQUEST_PREFIX: ''; - -declare interface AdminAPIConfig { - schema: string; - host: string; - path: string; - prefix: string; - key: string; -} - type PageMode = 'CREATE' | 'EDIT' | 'VIEW'; interface PluginProperty {
