feat: update Popover component

1. Update Popover component: support custom icon, title; support another data fetch func for only one request; suport pagination setting in table
2. Update PopoverSubnets components to support title
3. Update network-select-table component subnet display: update subnet's
count to title, when hover it, the popover will show

Change-Id: I5ca81146a7392b797f9f27d95c5d9cbf715d5e3d
This commit is contained in:
Jingwei.Zhang 2022-07-13 14:08:40 +08:00
parent 15d5998e11
commit 58026cf9bd
3 changed files with 40 additions and 20 deletions

View File

@ -27,15 +27,21 @@ const getColumn = (column) => {
}; };
}; };
function PopupResources({ getRequests, columns }) { function PopupResources({ getRequests, getData, columns, pagination }) {
const [data, setData] = useState([]); const [data, setData] = useState([]);
const [isLoading, setLoading] = useState(true); const [isLoading, setLoading] = useState(true);
useEffect(() => { useEffect(() => {
const fetchData = async () => { const fetchData = async () => {
const requests = getRequests(); if (getData) {
const ret = await Promise.all(requests); const ret = await getData();
setData(ret); setData(ret);
setLoading(false); setLoading(false);
} else if (getRequests) {
const requests = getRequests();
const ret = await Promise.all(requests);
setData(ret);
setLoading(false);
}
}; };
fetchData(); fetchData();
}, []); }, []);
@ -44,20 +50,37 @@ function PopupResources({ getRequests, columns }) {
} }
const currentColumns = columns.map((c) => getColumn(c)); const currentColumns = columns.map((c) => getColumn(c));
return ( return (
<Table columns={currentColumns} dataSource={data} pagination={false} /> <Table columns={currentColumns} dataSource={data} pagination={pagination} />
); );
} }
const IPopoverProps = { const IPopoverProps = {
columns: PropTypes.array.isRequired, columns: PropTypes.array.isRequired,
getRequests: PropTypes.func.isRequired, getRequests: PropTypes.func,
getData: PropTypes.func,
title: PropTypes.any,
placement: PropTypes.string, placement: PropTypes.string,
pagination: PropTypes.any,
icon: PropTypes.any,
}; };
export default function IPopover(props) { export default function IPopover(props) {
const { columns = [], getRequests, ...rest } = props; const {
columns = [],
getRequests,
getData,
title,
pagination = false,
icon = <FileTextOutlined style={{ cursor: 'pointer' }} />,
...rest
} = props;
const content = ( const content = (
<PopupResources columns={columns} getRequests={getRequests} /> <PopupResources
columns={columns}
getRequests={getRequests}
getData={getData}
pagination={pagination}
/>
); );
return ( return (
<> <>
@ -67,7 +90,7 @@ export default function IPopover(props) {
mouseEnterDelay={0.5} mouseEnterDelay={0.5}
{...rest} {...rest}
> >
<FileTextOutlined style={{ cursor: 'pointer' }} /> {title}&nbsp;{icon}
</Popover> </Popover>
</> </>
); );

View File

@ -17,7 +17,7 @@ import { SubnetStore } from 'stores/neutron/subnet';
import IPopover from './Popover'; import IPopover from './Popover';
export default function PopoverSubnets(props) { export default function PopoverSubnets(props) {
const { subnetIds = [] } = props; const { subnetIds = [], title = '' } = props;
if (!subnetIds.length) { if (!subnetIds.length) {
return null; return null;
} }
@ -34,5 +34,5 @@ export default function PopoverSubnets(props) {
title: t('CIDR'), title: t('CIDR'),
}, },
]; ];
return <IPopover columns={columns} getRequests={getRequests} />; return <IPopover columns={columns} getRequests={getRequests} title={title} />;
} }

View File

@ -61,14 +61,11 @@ export const networkColumns = (self) => [
title: t('Subnet Count'), title: t('Subnet Count'),
dataIndex: 'subnets', dataIndex: 'subnets',
render: (value, record) => { render: (value, record) => {
return ( const count = (value || []).length;
<> if (count === 0) {
{(value && value.length) || 0}{' '} return count;
{value && value.length !== 0 && ( }
<PopoverSubnets subnetIds={record.subnets} /> return <PopoverSubnets subnetIds={record.subnets} title={count} />;
)}
</>
);
}, },
stringify: (subnets) => `${subnets.length}(${subnets.join(',')})`, stringify: (subnets) => `${subnets.length}(${subnets.join(',')})`,
sorter: false, sorter: false,