diff --git a/.npmrc b/.npmrc deleted file mode 100644 index f3b1a9f..0000000 --- a/.npmrc +++ /dev/null @@ -1 +0,0 @@ -//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN} diff --git a/packages/plugin/package.json b/packages/plugin/package.json index 7a3c503..9518aaa 100644 --- a/packages/plugin/package.json +++ b/packages/plugin/package.json @@ -1,6 +1,6 @@ { "name": "@api7-dashboard/plugin", - "version": "1.0.3", + "version": "1.0.4", "description": "@api7-dashboard/plugin", "repository": { "type": "git", @@ -25,6 +25,7 @@ "dependencies": { "@rjsf/antd": "^2.3.0", "@rjsf/core": "^2.3.0", + "@uiw/react-codemirror": "^3.0.1", "json-schema": "^0.2.5", "set-value": "^3.0.2" }, diff --git a/packages/plugin/src/CodeMirrorDrawer.tsx b/packages/plugin/src/CodeMirrorDrawer.tsx new file mode 100644 index 0000000..a8d27e6 --- /dev/null +++ b/packages/plugin/src/CodeMirrorDrawer.tsx @@ -0,0 +1,25 @@ +import React from 'react'; +import { Drawer } from 'antd'; +import CodeMirror from '@uiw/react-codemirror'; + +type Props = { + visiable: boolean; + data: object; + onClose(): void +}; + +const CodeMirrorDrawer: React.FC = ({ visiable, data = {}, onClose }) => { + return ( + + + + ); +}; + +export default CodeMirrorDrawer; diff --git a/packages/plugin/src/PluginCard.tsx b/packages/plugin/src/PluginCard.tsx deleted file mode 100644 index 1c6b3de..0000000 --- a/packages/plugin/src/PluginCard.tsx +++ /dev/null @@ -1,17 +0,0 @@ -import React from 'react'; -import { Card } from 'antd'; -import { CardProps } from 'antd/lib/card'; - -interface Props extends CardProps { - name: string; -} - -const PluginCard: React.FC = ({ name, actions }) => { - return ( - - - - ); -}; - -export default PluginCard; diff --git a/packages/plugin/src/PluginDrawer.tsx b/packages/plugin/src/PluginDrawer.tsx index c1910b0..31143ca 100644 --- a/packages/plugin/src/PluginDrawer.tsx +++ b/packages/plugin/src/PluginDrawer.tsx @@ -1,78 +1,54 @@ -import React, { Fragment } from 'react'; +import React, { Fragment, useRef } from 'react'; import { Drawer, Button } from 'antd'; import { withTheme, FormProps } from '@rjsf/core'; import { JSONSchema7 } from 'json-schema'; // @ts-ignore import { Theme as AntDTheme } from '@rjsf/antd'; -interface Props { +type Props = { name?: string; initialData: any; - active?: boolean; - disabled?: boolean; schema: JSONSchema7; - onActive(name: string): void; - onInactive(name: string): void; + readonly?: boolean; onClose(): void; onFinish(values: any): void; -} +}; + +const PluginForm = withTheme(AntDTheme); const PluginDrawer: React.FC = ({ name, - active, - disabled, schema, initialData, - onActive, - onInactive, + readonly, onClose, onFinish, }) => { - const PluginForm = withTheme(AntDTheme); - if (!name) { return null; } - // NOTE: 用于作为 PluginForm 的引用 - let form: any; - + const form = useRef(null); return ( -
- {Boolean(active) && ( - - )} - {Boolean(!active) && ( - - )} -
- {Boolean(active) && ( -
- - -
- )} + + ) } @@ -80,12 +56,12 @@ const PluginDrawer: React.FC = ({ ) => { - form = _form; + form.current = _form; }} onSubmit={({ formData }) => { onFinish(formData); diff --git a/packages/plugin/src/PluginPage.tsx b/packages/plugin/src/PluginPage.tsx index a88828a..8ea1e4f 100644 --- a/packages/plugin/src/PluginPage.tsx +++ b/packages/plugin/src/PluginPage.tsx @@ -1,128 +1,167 @@ import React, { useState, useEffect } from 'react'; -import { LinkOutlined, SettingOutlined } from '@ant-design/icons'; -import { omit } from 'lodash'; +import { SettingOutlined, InfoOutlined } from '@ant-design/icons'; import { JSONSchema7 } from 'json-schema'; +import { Anchor, Layout, Switch, Card, Tooltip, Button, notification } from 'antd'; +import { omit } from 'lodash'; + // @ts-ignore import { PanelSection } from '@api7-dashboard/ui'; -import PluginCard from './PluginCard'; import PluginDrawer from './PluginDrawer'; import { getList, fetchPluginSchema } from './service'; -import { PLUGIN_MAPPER_SOURCE } from './data'; import { transformPlugin } from './transformer'; import { PluginPage } from './typing.d'; +import { PLUGIN_MAPPER_SOURCE } from './data'; +import CodeMirrorDrawer from './CodeMirrorDrawer'; type Props = { - disabled?: boolean; - data?: PluginPage.PluginData; - onChange?(data: PluginPage.PluginData): void; + readonly?: boolean; + initialData?: PluginPage.FinalData; + onChange?(data: PluginPage.FinalData): void; }; -const PluginPageApp: React.FC = ({ data = {}, disabled, onChange }) => { +const PanelSectionStyle = { + display: 'grid', + gridTemplateColumns: 'repeat(4, 25%)', + gridRowGap: 15, + gridColumnGap: 10, + width: 'calc(100% - 40px)', +}; + +const { Sider, Content } = Layout; + +const PluginPageApp: React.FC = ({ initialData = {}, readonly, onChange = () => {} }) => { const [pluginName, setPluginName] = useState(); - const [activeList, setActiveList] = useState([]); - const [inactiveList, setInactiveList] = useState([]); const [schema, setSchema] = useState(); - - const pluginList = [ - { - title: '已启用', - list: activeList, - }, - { - title: '未启用', - list: inactiveList, - }, - ]; + const [allPlugins, setAllPlugins] = useState>({}); + const [codeMirrorCodes, setCodeMirrorCodes] = useState(); useEffect(() => { - getList(data).then(props => { - setActiveList(props.activeList); - setInactiveList(props.inactiveList); - }); + getList(initialData).then(setAllPlugins); }, []); return ( <> - {pluginList.map(({ list, title }) => { - if (disabled && title === '未启用') { - return null; - } - return ( - - {list.map(({ name }) => ( - { - fetchPluginSchema(name).then(schemaData => { - setSchema(schemaData); - setTimeout(() => { - setPluginName(name); - }, 300); - }); - }} - />, - - window.open( - `https://github.com/apache/incubator-apisix/blob/master/doc/plugins/${name}.md`, - ) + + + + {Object.entries(allPlugins).map(([category]) => { + return ( + + ); + })} + + + + {Object.entries(allPlugins).map(([category, plugins]) => { + return ( + + {plugins.map(({ name, enabled }) => ( + + {name} + } - />, - ]} - key={name} - /> - ))} - - ); - })} - + extra={[ + +