LiteSun commented on a change in pull request #1813:
URL: https://github.com/apache/apisix-dashboard/pull/1813#discussion_r619811540
##########
File path:
web/src/components/PluginFlow/components/ConfigPanel/ConfigNode/index.tsx
##########
@@ -0,0 +1,180 @@
+/*
+* MIT License
+
+* Copyright (c) 2019 Alipay.inc
+
+* Permission is hereby granted, free of charge, to any person obtaining a copy
+* of this software and associated documentation files (the "Software"), to deal
+* in the Software without restriction, including without limitation the rights
+* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+* copies of the Software, and to permit persons to whom the Software is
+* furnished to do so, subject to the following conditions:
+
+* The above copyright notice and this permission notice shall be included in
all
+* copies or substantial portions of the Software.
+
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+* SOFTWARE.
+*/
+import React, { useEffect, useState, useRef } from 'react'
+import { Tabs, Row, Col, Input, Slider } from 'antd'
+import { Cell } from '@antv/x6'
+import { useIntl } from 'umi'
+
+import FlowGraph from '../../FlowGraph'
+
+const { TabPane } = Tabs
+
+interface IProps {
+ id: string
+}
+interface NodeAttrs {
+ stroke: string
+ strokeWidth: number
+ fill: string
+ fontSize: number
+ color: string
+}
+
+export default function (props: IProps) {
+ const { formatMessage } = useIntl()
+ const { id } = props
+ const [attrs, setAttrs] = useState<NodeAttrs>({
+ stroke: '#5F95FF',
+ strokeWidth: 1,
+ fill: 'rgba(95,149,255,0.05)',
+ fontSize: 12,
+ color: 'rgba(0,0,0,0.85)',
+ })
+ const cellRef = useRef<Cell>()
+
+ useEffect(() => {
+ if (id) {
+ const { graph } = FlowGraph
+ const cell = graph.getCellById(id)
+ if (!cell || !cell.isNode()) {
+ return
+ }
+ cellRef.current = cell
+ setAttrs({
+ stroke: cell.attr('body/stroke'),
+ strokeWidth: cell.attr('body/strokeWidth'),
+ fill: cell.attr('body/fill'),
+ fontSize: cell.attr('text/fontSize'),
+ color: cell.attr('text/fill'),
+ })
+ }
+ }, [id])
+
+ const setAttr = (key: string, val: any) => {
+ setAttrs((prev) => ({
+ ...prev,
+ [key]: val,
+ }))
+ }
+
+ const onStrokeChange = (e: React.FocusEvent<HTMLInputElement>) => {
+ const val = e.target.value
+ setAttr('stroke', val)
+ cellRef.current!.attr('body/stroke', val)
+ }
+
+ const onStrokeWidthChange = (val: number) => {
+ setAttr('strokeWidth', val)
+ cellRef.current!.attr('body/strokeWidth', val)
+ }
+
+ const onFillChange = (e: React.FocusEvent<HTMLInputElement>) => {
+ const val = e.target.value
+ setAttr('fill', val)
+ cellRef.current!.attr('body/fill', val)
+ }
+
+ const onFontSizeChange = (val: number) => {
+ setAttr('fontSize', val)
+ cellRef.current!.attr('text/fontSize', val)
+ }
+
+ const onColorChange = (e: React.FocusEvent<HTMLInputElement>) => {
+ const val = e.target.value
+ setAttr('color', val)
+ cellRef.current!.attr('text/fill', val)
+ }
+
+ return (
+ <Tabs defaultActiveKey="1">
+ <TabPane tab={formatMessage({ id: 'component.plugin-flow.text.node' })}
key="1">
+ <Row align="middle">
+ <Col span={8}>Border Color</Col>
+ <Col span={14}>
+ <Input
+ type="color"
+ value={attrs.stroke}
+ style={{ width: '100%' }}
+ onChange={onStrokeChange}
+ />
+ </Col>
+ </Row>
+ <Row align="middle">
+ <Col span={8}>Border Width</Col>
Review comment:
i18n
##########
File path: web/src/components/PluginFlow/PluginFlow.tsx
##########
@@ -0,0 +1,203 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+import React, { useEffect, useState } from 'react'
+import { Modal, Form, Input, Alert } from 'antd'
+import { Cell } from '@antv/x6'
+import { useIntl } from 'umi'
+
+import FlowGraph from './components/FlowGraph'
+import Toolbar from './components/Toolbar'
+import { DEFAULT_CONDITION_PROPS, DEFAULT_PLUGIN_PROPS, DEFAULT_STENCIL_WIDTH,
DEFAULT_TOOLBAR_HEIGHT, FlowGraphEvent } from './constants'
+import styles from './style.less'
+import ConfigPanel from './components/ConfigPanel'
+import PluginDetail from '../Plugin/PluginDetail'
+import { fetchList } from '../Plugin/service'
+
+type Props = {
+ chart: {
+ cells: Cell.Properties[];
+ };
+ readonly?: boolean;
+}
+
+type PluginProps = {
+ id: string;
+ name: string;
+ visible: boolean;
+ data: any;
+}
+
+type ConditionProps = {
+ id: string;
+ visible: boolean;
+ data: string;
+}
+
+const PluginFlow: React.FC<Props> = ({ chart, readonly = false }) => {
+ const { formatMessage } = useIntl()
+
+ // NOTE: To prevent from graph is not initialized
+ const [isReady, setIsReady] = useState(false)
+ const [plugins, setPlugins] = useState<PluginComponent.Meta[]>([])
+
+ const [pluginProps, setPluginProps] =
useState<PluginProps>(DEFAULT_PLUGIN_PROPS)
+ const [conditionProps, setConditionProps] =
useState<ConditionProps>(DEFAULT_CONDITION_PROPS)
+
+ const getContainerSize = () => {
+ const leftSidebar = document.querySelector('aside.ant-layout-sider')
+ const blankSpaceWidth = 24 * 4
+
+ const globalHeaderHeight = 48
+ const pageHeaderHeight = 72
+ const otherHeight = 191
+
+ const width = document.body.offsetWidth - (leftSidebar?.clientWidth || 0)
- blankSpaceWidth - DEFAULT_STENCIL_WIDTH
+ const height = document.body.offsetHeight - globalHeaderHeight -
pageHeaderHeight - otherHeight
+
+ return {
+ width,
+ height: height < 800 ? 800 : height
+ }
+ }
+
+ useEffect(() => {
+ if (!plugins.length) {
+ return
+ }
+
+ const container = document.getElementById("container")
+ if (!container) {
+ return
+ }
+
+ const sidebar = document.querySelector('.ant-pro-sider-collapsed-button')
+
+ const graph = FlowGraph.init(container, plugins, chart);
+ (window as any).graph = graph
+ setIsReady(true)
+
+ const stencilContainer = document.querySelector('#stencil') as HTMLElement
+
+ const handleResize = () => {
+ const { width, height } = getContainerSize()
+ graph.resize(width, height)
+
+ stencilContainer.style.height = `${height + DEFAULT_TOOLBAR_HEIGHT}px`
+ stencilContainer.style.width = `${DEFAULT_STENCIL_WIDTH}px`
+ }
+
+ const handleLeftSidebarResize = () => {
+ setTimeout(() => {
+ handleResize()
+ }, 200)
+ }
+
+ handleResize()
+
+ graph.on(FlowGraphEvent.PLUGIN_CHANGE, setPluginProps)
+ graph.on(FlowGraphEvent.CONDITION_CHANGE, (props: ConditionProps) => {
+ setConditionProps(props)
+ })
+
+ if (readonly) {
+ graph.disableKeyboard()
+ }
+
+ window.addEventListener("resize", handleResize)
+ sidebar?.addEventListener('click', handleLeftSidebarResize)
+ return () => {
+ window.removeEventListener("resize", handleResize)
+ sidebar?.removeEventListener('click', handleLeftSidebarResize)
+ }
+ }, [plugins])
+
+ useEffect(() => {
+ fetchList().then(data => setPlugins(data))
Review comment:
```suggestion
fetchList().then(setPlugins)
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]