liuxiran commented on a change in pull request #1813: URL: https://github.com/apache/apisix-dashboard/pull/1813#discussion_r619931026
########## 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 = () => { Review comment: It would be better to add code comments for each height and width. BTW I found when default leftsidebar open, collapsed it and reopened it again, the nodes container will get smaller  and actually every container has its own scroll bar, how about don't use page scrollbar on the right side?  ########## 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') Review comment: ```suggestion const siderbarCollapsedButton = document.querySelector('.ant-pro-sider-collapsed-button') ``` ########## File path: web/src/locales/en-US/component.ts ########## @@ -81,4 +81,6 @@ export default { 'component.global.copy': 'Copy', 'component.global.copySuccess': 'Copy Successfully ', 'component.global.copyFail': 'Copy Failed', + 'component.global.modal.confirm': 'OK', + 'component.global.modal.cancel': 'Cancel', Review comment: we already have `component.global.cancel` and `component.global.confirm`, better to reuse them -- 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]
