guoqqqi commented on code in PR #2480: URL: https://github.com/apache/apisix-dashboard/pull/2480#discussion_r905643042
########## web/src/pages/Route/components/DataLoader/Import.tsx: ########## @@ -0,0 +1,262 @@ +/* + * 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, { useState } from 'react'; +import { + Button, + Col, + Collapse, + Divider, + Drawer, + Form, + Input, + notification, + Result, + Row, + Select, + Space, + Upload, +} from 'antd'; +import { UploadOutlined } from '@ant-design/icons'; +import { useIntl } from '@@/plugin-locale/localeExports'; +import OpenAPI3 from './loader/OpenAPI3'; +import type { RcFile } from 'antd/lib/upload'; +import { importRoutes } from '@/pages/Route/service'; + +type Props = { + onClose?: () => void; + onFinish?: () => void; +}; + +type ImportType = 'openapi3' | 'openapi_legacy'; +type ImportState = 'import' | 'result'; +type ImportResult = { + success: boolean; + data: Record< + string, + { + total: number; + failed: number; + errors: string[]; + } + >; +}; + +const entityNames = [ + 'route', + 'upstream', + 'service', + 'consumer', + 'ssl', + 'stream_route', + 'global_rule', + 'plugin_config', + 'proto', +]; + +const Option: React.FC<{ + type: ImportType; +}> = ({ type }) => { + switch (type) { + case 'openapi_legacy': + return <></>; + case 'openapi3': + default: + return <OpenAPI3 />; + } +}; + +const DataLoaderImport: React.FC<Props> = (props) => { + const [form] = Form.useForm(); + const { formatMessage } = useIntl(); + const { onClose } = props; + const [importType, setImportType] = useState<ImportType>('openapi3'); + const [uploadFileList, setUploadFileList] = useState<RcFile[]>([]); + const [state, setState] = useState<ImportState>('import'); + const [importResult, setImportResult] = useState<ImportResult>({ + success: true, + data: {}, + }); + + const onFinish = (values: Record<string, string>) => { + const formData = new FormData(); + if (!uploadFileList[0]) { + notification.warn({ + message: formatMessage({ id: 'page.route.button.selectFile' }), + }); + return; + } + Object.keys(values).forEach((key) => { + formData.append(key, values[key]); + }); + formData.append('file', uploadFileList[0]); + + importRoutes(formData).then((r) => { + let errorNumber = 0; + entityNames.forEach((v) => { + errorNumber += r.data[v].failed; + }); + + setImportResult({ + success: errorNumber <= 0, + data: r.data, + }); + setState('result'); + }); + }; + + return ( + <> + <Drawer + title={formatMessage({ id: 'page.route.data_loader.import_panel' })} + width={480} + visible={true} + onClose={onClose} + footer={ + <div + style={{ + display: state === 'result' ? 'none' : 'flex', + justifyContent: 'space-between', + }} + > + <Button onClick={onClose}>{formatMessage({ id: 'component.global.cancel' })}</Button> + <Space> + <Button + type="primary" + onClick={() => { + form.submit(); + }} + > + {formatMessage({ id: 'component.global.submit' })} + </Button> + </Space> + </div> + } + > + {state === 'import' && ( + <Form layout="vertical" form={form} onFinish={onFinish} hideRequiredMark> + <Row gutter={16}> + <Col span={12}> + <Form.Item + name="type" + label={formatMessage({ id: 'page.route.data_loader.labels.loader_type' })} + rules={[ + { + required: true, + message: formatMessage({ id: 'page.route.data_loader.tips.select_type' }), + }, + ]} + initialValue={importType} + > + <Select onChange={(value: ImportType) => setImportType(value)}> + <Select.Option value="openapi3"> + {formatMessage({ id: 'page.route.data_loader.types.openapi3' })} + </Select.Option> + <Select.Option value="openapi_legacy" disabled> Review Comment: I see that the old import method is disabled now, will the old code be removed uniformly, or will it be compatible with the new openAPI import? ########## web/cypress/integration/route/data-loader-import.spec.js: ########## @@ -0,0 +1,198 @@ +/* + * 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. + */ + +context('Data Loader import', () => { + const selector = { + drawer: '.ant-drawer-content', + selectDropdown: '.ant-select-dropdown', + listTbody: '.ant-table-tbody', + listRow: 'tr.ant-table-row-level-0', + refresh: '.anticon-reload', + notification: '.ant-notification-notice-message', + notificationCloseIcon: '.ant-notification-notice-close', + fileSelector: '[type=file]', + notificationDesc: '.ant-notification-notice-description', + task_name: '#task_name', + merge_method: '#merge_method', + }; + const data = { + route_name_0: 'route_name_0', + route_name_1: 'route_name_1', + upstream_node0_host_0: '1.1.1.1', + upstream_node0_host_1: '2.2.2.2', + importErrorMsg: 'required file type is .yaml, .yml or .json but got: .txt', + uploadRouteFiles: [ + '../../../api/test/testdata/import/default.json', + '../../../api/test/testdata/import/default.yaml', + 'import-error.txt', + ], + // Note: export file's name will be end of a timestamp + jsonMask: 'cypress/downloads/*.json', + yamlMask: 'cypress/downloads/*.yaml', + port: '80', + weight: 1, + importRouteSuccess: 'Import Successfully', + deleteRouteSuccess: 'Delete Route Successfully', + deleteUpstreamSuccess: 'Delete Upstream Successfully', + }; + const cases = { + API101: '../../../api/test/testdata/import/Postman-API101.yaml', + }; + + beforeEach(() => { + cy.login(); + + cy.fixture('selector.json').as('domSelector'); + cy.fixture('data.json').as('data'); + cy.fixture('export-route-dataset.json').as('exportFile'); + }); + + it('should import API101 with merge mode', () => { + cy.visit('/'); + cy.contains('Route').click(); + + cy.get(selector.refresh).click(); + cy.contains('Advanced').click(); + cy.contains('Import').should('be.visible').click(); + + // select Data Loader type + cy.contains('OpenAPI 3').should('be.visible').click(); + cy.get(selector.selectDropdown).contains('OpenAPI 3').should('be.visible').click(); + cy.get(selector.drawer).get(selector.task_name).type('api101_mm'); + cy.get(selector.fileSelector).attachFile(cases.API101); + cy.get(selector.drawer).contains('Submit').click(); + cy.get(selector.drawer).contains('Import Successfully').should('be.visible'); + cy.get(selector.drawer).contains('Total 3 route imported, 0 failed').click(); + cy.get(selector.drawer).contains('Close').click(); + + // check result + cy.get(selector.listTbody).get(selector.listRow).should('have.length', 3); + cy.contains('api101_mm_customer').should('be.visible'); + cy.contains('api101_mm_customer/{customer_id}').should('be.visible'); + cy.contains('api101_mm_customers').should('be.visible'); + + // remove route + for (let i = 0; i < 3; i += 1) { + cy.get(selector.listTbody).get(selector.listRow).contains('More').click(); + cy.contains('Delete').should('be.visible').click(); + cy.contains('OK').should('be.visible').click(); + cy.get(selector.notification).should('contain', data.deleteRouteSuccess); + cy.get(selector.notificationCloseIcon).click(); + } + }); + + it('should import API101 with duplicate upstream', () => { + cy.visit('/'); + cy.contains('Route').click(); + + cy.get(selector.refresh).click(); + cy.contains('Advanced').click(); + cy.contains('Import').should('be.visible').click(); + + // select Data Loader type + cy.contains('OpenAPI 3').should('be.visible').click(); + cy.get(selector.selectDropdown).contains('OpenAPI 3').should('be.visible').click(); + cy.get(selector.drawer).get(selector.task_name).type('api101_mm'); + cy.get(selector.fileSelector).attachFile(cases.API101); + cy.get(selector.drawer).contains('Submit').click(); + cy.get(selector.drawer).contains('Import Failed').should('be.visible'); + cy.get(selector.drawer).contains('Total 1 upstream imported, 1 failed').click(); + cy.get(selector.drawer).contains('key: api101_mm is conflicted').should('be.visible'); + cy.get(selector.drawer).contains('Close').click(); + + // remove route + for (let i = 0; i < 3; i += 1) { + cy.get(selector.listTbody).get(selector.listRow).contains('More').click(); + cy.contains('Delete').should('be.visible').click(); + cy.contains('OK').should('be.visible').click(); + cy.get(selector.notification).should('contain', data.deleteRouteSuccess); + cy.get(selector.notificationCloseIcon).click(); + } + }); + + it('should import API101 with non-merge mode', () => { + cy.visit('/'); + cy.contains('Route').click(); + + cy.get(selector.refresh).click(); + cy.contains('Advanced').click(); + cy.contains('Import').should('be.visible').click(); + + // select Data Loader type + cy.contains('OpenAPI 3').should('be.visible').click(); + cy.get(selector.selectDropdown).contains('OpenAPI 3').should('be.visible').click(); + cy.get(selector.drawer).get(selector.task_name).type('api101_nmm'); + cy.get(selector.drawer).get(selector.merge_method).click(); + cy.get(selector.fileSelector).attachFile(cases.API101); + cy.get(selector.drawer).contains('Submit').click(); + cy.get(selector.drawer).contains('Import Successfully').should('be.visible'); + cy.get(selector.drawer).contains('Total 5 route imported, 0 failed').click(); + cy.get(selector.drawer).contains('Close').click(); + + // check result + cy.get(selector.listTbody).get(selector.listRow).should('have.length', 5); + + // remove route + /**/ Review Comment: This section seems to be able to be deleted ########## web/src/pages/Route/components/DataLoader/Import.tsx: ########## @@ -0,0 +1,262 @@ +/* + * 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, { useState } from 'react'; +import { + Button, + Col, + Collapse, + Divider, + Drawer, + Form, + Input, + notification, + Result, + Row, + Select, + Space, + Upload, +} from 'antd'; +import { UploadOutlined } from '@ant-design/icons'; +import { useIntl } from '@@/plugin-locale/localeExports'; +import OpenAPI3 from './loader/OpenAPI3'; +import type { RcFile } from 'antd/lib/upload'; +import { importRoutes } from '@/pages/Route/service'; + +type Props = { + onClose?: () => void; + onFinish?: () => void; +}; + +type ImportType = 'openapi3' | 'openapi_legacy'; +type ImportState = 'import' | 'result'; +type ImportResult = { + success: boolean; + data: Record< + string, + { + total: number; + failed: number; + errors: string[]; + } + >; +}; + +const entityNames = [ + 'route', + 'upstream', + 'service', + 'consumer', + 'ssl', + 'stream_route', + 'global_rule', + 'plugin_config', + 'proto', +]; + +const Option: React.FC<{ + type: ImportType; +}> = ({ type }) => { + switch (type) { + case 'openapi_legacy': + return <></>; + case 'openapi3': + default: + return <OpenAPI3 />; + } +}; + +const DataLoaderImport: React.FC<Props> = (props) => { + const [form] = Form.useForm(); + const { formatMessage } = useIntl(); + const { onClose } = props; + const [importType, setImportType] = useState<ImportType>('openapi3'); + const [uploadFileList, setUploadFileList] = useState<RcFile[]>([]); + const [state, setState] = useState<ImportState>('import'); + const [importResult, setImportResult] = useState<ImportResult>({ + success: true, + data: {}, + }); + + const onFinish = (values: Record<string, string>) => { + const formData = new FormData(); + if (!uploadFileList[0]) { + notification.warn({ + message: formatMessage({ id: 'page.route.button.selectFile' }), + }); + return; + } + Object.keys(values).forEach((key) => { + formData.append(key, values[key]); + }); + formData.append('file', uploadFileList[0]); + + importRoutes(formData).then((r) => { + let errorNumber = 0; + entityNames.forEach((v) => { + errorNumber += r.data[v].failed; + }); + + setImportResult({ + success: errorNumber <= 0, + data: r.data, + }); + setState('result'); + }); + }; + + return ( + <> + <Drawer + title={formatMessage({ id: 'page.route.data_loader.import_panel' })} + width={480} + visible={true} + onClose={onClose} + footer={ + <div + style={{ + display: state === 'result' ? 'none' : 'flex', + justifyContent: 'space-between', + }} + > + <Button onClick={onClose}>{formatMessage({ id: 'component.global.cancel' })}</Button> + <Space> + <Button + type="primary" + onClick={() => { + form.submit(); + }} + > + {formatMessage({ id: 'component.global.submit' })} + </Button> + </Space> + </div> + } + > + {state === 'import' && ( + <Form layout="vertical" form={form} onFinish={onFinish} hideRequiredMark> Review Comment: ```suggestion <Form layout="vertical" form={form} onFinish={onFinish} hideRequiredMark> ``` `hideRequiredMark` Why do we need to hide the required attributes? ########## web/cypress/integration/route/data-loader-import.spec.js: ########## @@ -0,0 +1,198 @@ +/* + * 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. + */ + +context('Data Loader import', () => { + const selector = { + drawer: '.ant-drawer-content', + selectDropdown: '.ant-select-dropdown', + listTbody: '.ant-table-tbody', + listRow: 'tr.ant-table-row-level-0', + refresh: '.anticon-reload', + notification: '.ant-notification-notice-message', + notificationCloseIcon: '.ant-notification-notice-close', + fileSelector: '[type=file]', + notificationDesc: '.ant-notification-notice-description', + task_name: '#task_name', + merge_method: '#merge_method', + }; + const data = { + route_name_0: 'route_name_0', + route_name_1: 'route_name_1', + upstream_node0_host_0: '1.1.1.1', + upstream_node0_host_1: '2.2.2.2', + importErrorMsg: 'required file type is .yaml, .yml or .json but got: .txt', + uploadRouteFiles: [ + '../../../api/test/testdata/import/default.json', + '../../../api/test/testdata/import/default.yaml', + 'import-error.txt', + ], + // Note: export file's name will be end of a timestamp + jsonMask: 'cypress/downloads/*.json', + yamlMask: 'cypress/downloads/*.yaml', + port: '80', + weight: 1, + importRouteSuccess: 'Import Successfully', + deleteRouteSuccess: 'Delete Route Successfully', + deleteUpstreamSuccess: 'Delete Upstream Successfully', + }; + const cases = { + API101: '../../../api/test/testdata/import/Postman-API101.yaml', + }; + + beforeEach(() => { + cy.login(); + + cy.fixture('selector.json').as('domSelector'); + cy.fixture('data.json').as('data'); + cy.fixture('export-route-dataset.json').as('exportFile'); + }); + + it('should import API101 with merge mode', () => { + cy.visit('/'); + cy.contains('Route').click(); + + cy.get(selector.refresh).click(); + cy.contains('Advanced').click(); + cy.contains('Import').should('be.visible').click(); + + // select Data Loader type + cy.contains('OpenAPI 3').should('be.visible').click(); + cy.get(selector.selectDropdown).contains('OpenAPI 3').should('be.visible').click(); + cy.get(selector.drawer).get(selector.task_name).type('api101_mm'); + cy.get(selector.fileSelector).attachFile(cases.API101); + cy.get(selector.drawer).contains('Submit').click(); + cy.get(selector.drawer).contains('Import Successfully').should('be.visible'); + cy.get(selector.drawer).contains('Total 3 route imported, 0 failed').click(); + cy.get(selector.drawer).contains('Close').click(); + + // check result + cy.get(selector.listTbody).get(selector.listRow).should('have.length', 3); + cy.contains('api101_mm_customer').should('be.visible'); + cy.contains('api101_mm_customer/{customer_id}').should('be.visible'); + cy.contains('api101_mm_customers').should('be.visible'); + + // remove route + for (let i = 0; i < 3; i += 1) { + cy.get(selector.listTbody).get(selector.listRow).contains('More').click(); + cy.contains('Delete').should('be.visible').click(); + cy.contains('OK').should('be.visible').click(); + cy.get(selector.notification).should('contain', data.deleteRouteSuccess); + cy.get(selector.notificationCloseIcon).click(); + } + }); + + it('should import API101 with duplicate upstream', () => { + cy.visit('/'); + cy.contains('Route').click(); + + cy.get(selector.refresh).click(); + cy.contains('Advanced').click(); + cy.contains('Import').should('be.visible').click(); + + // select Data Loader type + cy.contains('OpenAPI 3').should('be.visible').click(); + cy.get(selector.selectDropdown).contains('OpenAPI 3').should('be.visible').click(); + cy.get(selector.drawer).get(selector.task_name).type('api101_mm'); + cy.get(selector.fileSelector).attachFile(cases.API101); + cy.get(selector.drawer).contains('Submit').click(); + cy.get(selector.drawer).contains('Import Failed').should('be.visible'); + cy.get(selector.drawer).contains('Total 1 upstream imported, 1 failed').click(); + cy.get(selector.drawer).contains('key: api101_mm is conflicted').should('be.visible'); + cy.get(selector.drawer).contains('Close').click(); + + // remove route + for (let i = 0; i < 3; i += 1) { + cy.get(selector.listTbody).get(selector.listRow).contains('More').click(); + cy.contains('Delete').should('be.visible').click(); + cy.contains('OK').should('be.visible').click(); + cy.get(selector.notification).should('contain', data.deleteRouteSuccess); + cy.get(selector.notificationCloseIcon).click(); + } + }); + + it('should import API101 with non-merge mode', () => { + cy.visit('/'); + cy.contains('Route').click(); + + cy.get(selector.refresh).click(); + cy.contains('Advanced').click(); + cy.contains('Import').should('be.visible').click(); + + // select Data Loader type + cy.contains('OpenAPI 3').should('be.visible').click(); + cy.get(selector.selectDropdown).contains('OpenAPI 3').should('be.visible').click(); + cy.get(selector.drawer).get(selector.task_name).type('api101_nmm'); + cy.get(selector.drawer).get(selector.merge_method).click(); + cy.get(selector.fileSelector).attachFile(cases.API101); + cy.get(selector.drawer).contains('Submit').click(); + cy.get(selector.drawer).contains('Import Successfully').should('be.visible'); + cy.get(selector.drawer).contains('Total 5 route imported, 0 failed').click(); + cy.get(selector.drawer).contains('Close').click(); + + // check result + cy.get(selector.listTbody).get(selector.listRow).should('have.length', 5); + + // remove route + /**/ + }); + + it('should import API101 with duplicate route', () => { + cy.visit('/'); + cy.contains('Route').click(); + + cy.get(selector.refresh).click(); + cy.contains('Advanced').click(); + cy.contains('Import').should('be.visible').click(); + + // select Data Loader type + cy.contains('OpenAPI 3').should('be.visible').click(); + cy.get(selector.selectDropdown).contains('OpenAPI 3').should('be.visible').click(); + cy.get(selector.drawer).get(selector.task_name).type('api101_nmm'); + cy.get(selector.drawer).get(selector.merge_method).click(); + cy.get(selector.fileSelector).attachFile(cases.API101); + cy.get(selector.drawer).contains('Submit').click(); + cy.get(selector.drawer).contains('Import Failed').should('be.visible'); + cy.get(selector.drawer).contains('Total 5 route imported, 1 failed').click(); + cy.get(selector.drawer).contains('is duplicated with route api101_nmm_').should('be.visible'); + cy.get(selector.drawer).contains('Close').click(); Review Comment: It is best to add assertions to confirm that the drawer has disappeared ########## web/src/pages/Route/components/DataLoader/Import.tsx: ########## @@ -0,0 +1,262 @@ +/* + * 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, { useState } from 'react'; +import { + Button, + Col, + Collapse, + Divider, + Drawer, + Form, + Input, + notification, + Result, + Row, + Select, + Space, + Upload, +} from 'antd'; +import { UploadOutlined } from '@ant-design/icons'; +import { useIntl } from '@@/plugin-locale/localeExports'; +import OpenAPI3 from './loader/OpenAPI3'; +import type { RcFile } from 'antd/lib/upload'; +import { importRoutes } from '@/pages/Route/service'; + +type Props = { + onClose?: () => void; + onFinish?: () => void; +}; + +type ImportType = 'openapi3' | 'openapi_legacy'; +type ImportState = 'import' | 'result'; +type ImportResult = { + success: boolean; + data: Record< + string, + { + total: number; + failed: number; + errors: string[]; + } + >; +}; + +const entityNames = [ + 'route', + 'upstream', + 'service', + 'consumer', + 'ssl', + 'stream_route', + 'global_rule', + 'plugin_config', + 'proto', +]; + +const Option: React.FC<{ + type: ImportType; +}> = ({ type }) => { + switch (type) { + case 'openapi_legacy': + return <></>; + case 'openapi3': + default: + return <OpenAPI3 />; + } +}; + +const DataLoaderImport: React.FC<Props> = (props) => { + const [form] = Form.useForm(); + const { formatMessage } = useIntl(); + const { onClose } = props; + const [importType, setImportType] = useState<ImportType>('openapi3'); + const [uploadFileList, setUploadFileList] = useState<RcFile[]>([]); + const [state, setState] = useState<ImportState>('import'); + const [importResult, setImportResult] = useState<ImportResult>({ + success: true, + data: {}, + }); + + const onFinish = (values: Record<string, string>) => { + const formData = new FormData(); + if (!uploadFileList[0]) { + notification.warn({ + message: formatMessage({ id: 'page.route.button.selectFile' }), + }); + return; + } + Object.keys(values).forEach((key) => { + formData.append(key, values[key]); + }); + formData.append('file', uploadFileList[0]); + + importRoutes(formData).then((r) => { + let errorNumber = 0; + entityNames.forEach((v) => { + errorNumber += r.data[v].failed; + }); + + setImportResult({ + success: errorNumber <= 0, + data: r.data, + }); + setState('result'); + }); + }; + + return ( + <> + <Drawer + title={formatMessage({ id: 'page.route.data_loader.import_panel' })} + width={480} + visible={true} + onClose={onClose} + footer={ + <div + style={{ + display: state === 'result' ? 'none' : 'flex', + justifyContent: 'space-between', + }} + > + <Button onClick={onClose}>{formatMessage({ id: 'component.global.cancel' })}</Button> + <Space> + <Button + type="primary" + onClick={() => { + form.submit(); + }} + > + {formatMessage({ id: 'component.global.submit' })} + </Button> + </Space> + </div> + } + > + {state === 'import' && ( + <Form layout="vertical" form={form} onFinish={onFinish} hideRequiredMark> + <Row gutter={16}> + <Col span={12}> + <Form.Item + name="type" + label={formatMessage({ id: 'page.route.data_loader.labels.loader_type' })} + rules={[ + { + required: true, + message: formatMessage({ id: 'page.route.data_loader.tips.select_type' }), + }, + ]} + initialValue={importType} + > + <Select onChange={(value: ImportType) => setImportType(value)}> + <Select.Option value="openapi3"> + {formatMessage({ id: 'page.route.data_loader.types.openapi3' })} + </Select.Option> + <Select.Option value="openapi_legacy" disabled> + {formatMessage({ id: 'page.route.data_loader.types.openapi_legacy' })} + </Select.Option> + </Select> + </Form.Item> + </Col> + <Col span={12}> + <Form.Item + name="task_name" + label={formatMessage({ id: 'page.route.data_loader.labels.task_name' })} + rules={[ + { + required: true, + message: formatMessage({ id: 'page.route.data_loader.tips.input_task_name' }), + }, + ]} + > + <Input + placeholder={formatMessage({ + id: 'page.route.data_loader.tips.input_task_name', + })} + /> + </Form.Item> + </Col> + </Row> + <Option type={importType}></Option> + <Divider /> + <Row gutter={16}> + <Col span={24}> + <Form.Item label={formatMessage({ id: 'page.route.data_loader.labels.upload' })}> + <Upload + fileList={uploadFileList as any} + beforeUpload={(file) => { + setUploadFileList([file]); + return false; + }} + onRemove={() => { + setUploadFileList([]); + }} + > + <Button icon={<UploadOutlined />}> + {formatMessage({ id: 'page.route.data_loader.tips.click_upload' })} + </Button> + </Upload> + </Form.Item> + </Col> + </Row> + </Form> + )} + {state === 'result' && ( + <Result + status={importResult.success ? 'success' : 'error'} + title={`${formatMessage({ id: 'page.route.data_loader.import' })} ${ + importResult.success + ? formatMessage({ id: 'component.status.success' }) + : formatMessage({ id: 'component.status.fail' }) + }`} + extra={[ + <Button + type="primary" + onClick={() => { + setState('import'); + onClose?.(); Review Comment: Would it be better to change the onClose method to a mandatory parameter? -- 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. To unsubscribe, e-mail: notifications-unsubscr...@apisix.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org