Merge "feat: Add cidr in subnet-select-options & subnet details in column"

This commit is contained in:
Zuul 2021-08-27 11:28:24 +00:00 committed by Gerrit Code Review
commit 094b50f135
3 changed files with 63 additions and 18 deletions

View File

@ -232,7 +232,12 @@ export default class NetworkSelect extends React.Component {
return subnets return subnets
.filter((it) => it.network_id === network) .filter((it) => it.network_id === network)
.map((it) => ({ .map((it) => ({
label: it.name, label: (
<div>
<span>{it.name}</span>
<span className={styles.subnet_options_cidr}>{it.cidr}</span>
</div>
),
value: it.id, value: it.id,
})); }));
}; };
@ -252,22 +257,10 @@ export default class NetworkSelect extends React.Component {
} }
renderSubnet() { renderSubnet() {
const { network, subnets, subnet, ipType } = this.state; const { network, subnet, ipType } = this.state;
if (!network || !ipType) { if (!network || !ipType) {
return null; return null;
} }
let tips = '';
if (subnet) {
const item = subnets.find((it) => it.id === subnet);
if (item) {
tips = (
<span>
<span className={styles.label}>{t('Cidr')}: </span>
<span className={styles.content}>{item.cidr}</span>
</span>
);
}
}
return ( return (
<Col span={6}> <Col span={6}>
<Select <Select
@ -276,7 +269,6 @@ export default class NetworkSelect extends React.Component {
placeholder={t('please select subnet')} placeholder={t('please select subnet')}
onChange={this.onSubnetChange} onChange={this.onSubnetChange}
/> />
<div className={styles.tips}>{tips}</div>
</Col> </Col>
); );
} }

View File

@ -1,4 +1,4 @@
@import "~styles/variables"; @import '~styles/variables';
.network-select { .network-select {
display: block; display: block;
height: 61.6px; height: 61.6px;
@ -33,4 +33,11 @@
} }
.content { .content {
color: @color-text-body; color: @color-text-body;
} }
.subnet_options_cidr {
padding-left: 5px;
margin-left: 5px;
opacity: 0.6;
border-left: 1px solid;
}

View File

@ -12,6 +12,11 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
import React, { useEffect, useState } from 'react';
import { Col, Empty, Popover, Row, Spin } from 'antd';
import { FileTextOutlined } from '@ant-design/icons';
import { SubnetStore } from 'stores/neutron/subnet';
export const networkStatus = { export const networkStatus = {
ACTIVE: t('Active'), ACTIVE: t('Active'),
BUILD: t('Build'), BUILD: t('Build'),
@ -57,7 +62,19 @@ export const networkColumns = (self) => [
{ {
title: t('Subnet Count'), title: t('Subnet Count'),
dataIndex: 'subnets', dataIndex: 'subnets',
render: (value) => (value && value.length) || 0, render: (value, record) => {
const content = <PopUpSubnet subnetIds={record.subnets} />;
return (
<>
{(value && value.length) || 0}{' '}
{value && value.length !== 0 && (
<Popover content={content} destroyTooltipOnHide>
<FileTextOutlined />
</Popover>
)}
</>
);
},
sorter: false, sorter: false,
}, },
{ {
@ -97,3 +114,32 @@ export const getAnchorData = (num, y) => {
}; };
export const isExternalNetwork = (network) => !!network['router:external']; export const isExternalNetwork = (network) => !!network['router:external'];
function PopUpSubnet({ subnetIds }) {
const [subnets, setSubnets] = useState(subnetIds);
const [isLoading, setLoaidng] = useState(false);
useEffect(() => {
setLoaidng(true);
(async function () {
const promises = subnets.map((i) =>
new SubnetStore().fetchDetail({ id: i })
);
const ret = await Promise.all(promises);
setSubnets(ret);
setLoaidng(false);
})();
}, []);
if (isLoading) {
return <Spin />;
}
return subnets.length === 0 ? (
<Empty />
) : (
subnets.map((item, index) => (
<Row gutter={[24]} key={`${item}_${index}`} style={{ minWidth: 300 }}>
<Col span={12}>{item.name}</Col>
<Col span={12}>{item.cidr}</Col>
</Row>
))
);
}