// Copyright 2021 99cloud // // Licensed 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 from 'react'; import { observer, inject } from 'mobx-react'; import { toJS } from 'mobx'; import globalServerStore from 'stores/nova/instance'; import { Button, Table, Collapse, Divider, Col, Row, Radio, Spin, Tabs, } from 'antd'; import PrimaryActionButtons from 'components/Tables/Base/PrimaryActionButtons'; import classnames from 'classnames'; import interfaceImg from 'asset/image/interface.png'; import { CaretRightOutlined } from '@ant-design/icons'; import ItemActionButtons from 'components/Tables/Base/ItemActionButtons'; import { getSelfColumns } from 'resources/security-group-rule'; import { isAdminPage } from 'utils/index'; import { getPath } from 'utils/route-map'; import styles from './index.less'; import Detach from './action/Detach'; import ManageSecurityGroup from './action/ManageSecurityGroup'; const { Panel } = Collapse; const { TabPane } = Tabs; export class SecurityGroup extends React.Component { constructor(props) { super(props); this.state = { activeInterfaceId: null, activeInterface: null, filterData: [], }; this.store = globalServerStore; this.tableColumns = getSelfColumns(this).filter( (it) => it.dataIndex !== 'direction' ); } componentDidMount = async () => { this.actionCallback(true); }; get isAdminPage() { const { pathname } = this.props.location; return isAdminPage(pathname); } get showActions() { return !this.isAdminPage; } getDetailUrl(id) { const key = this.isAdminPage ? 'securityGroupDetailAdmin' : 'securityGroupDetail'; return getPath({ key, params: { id } }); } actionCallback = async (first) => { const { match: { params: { id }, }, } = this.props; await this.store.fetchSecurityGroup({ id }); const { activeInterface } = this.state; const params = first ? this.store.securityGroups.interfaces[0] : activeInterface; this.filterSecurityGroup(params); }; filterSecurityGroup = (item) => { const { data } = this.store.securityGroups; const filterData = toJS(data).filter( (it) => item.security_groups.indexOf(it.id) !== -1 ); this.setState({ activeInterfaceId: item && item.id, activeInterface: item, filterData, }); }; renderPanelTitle(item) { const { activeInterfaceId, filterData } = this.state; const newItem = { ...item, activeInterfaceId, filterData, }; return (