From 58026cf9bda1046e58fe7bea39e184191a5e846a Mon Sep 17 00:00:00 2001 From: "Jingwei.Zhang" Date: Wed, 13 Jul 2022 14:08:40 +0800 Subject: [PATCH] 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 --- src/components/Popover/Popover.jsx | 43 +++++++++++++++++------ src/components/Popover/PopoverSubnets.jsx | 4 +-- src/resources/neutron/network.jsx | 13 +++---- 3 files changed, 40 insertions(+), 20 deletions(-) diff --git a/src/components/Popover/Popover.jsx b/src/components/Popover/Popover.jsx index d236e4af..5cb12480 100644 --- a/src/components/Popover/Popover.jsx +++ b/src/components/Popover/Popover.jsx @@ -27,15 +27,21 @@ const getColumn = (column) => { }; }; -function PopupResources({ getRequests, columns }) { +function PopupResources({ getRequests, getData, columns, pagination }) { const [data, setData] = useState([]); const [isLoading, setLoading] = useState(true); useEffect(() => { const fetchData = async () => { - const requests = getRequests(); - const ret = await Promise.all(requests); - setData(ret); - setLoading(false); + if (getData) { + const ret = await getData(); + setData(ret); + setLoading(false); + } else if (getRequests) { + const requests = getRequests(); + const ret = await Promise.all(requests); + setData(ret); + setLoading(false); + } }; fetchData(); }, []); @@ -44,20 +50,37 @@ function PopupResources({ getRequests, columns }) { } const currentColumns = columns.map((c) => getColumn(c)); return ( - +
); } const IPopoverProps = { columns: PropTypes.array.isRequired, - getRequests: PropTypes.func.isRequired, + getRequests: PropTypes.func, + getData: PropTypes.func, + title: PropTypes.any, placement: PropTypes.string, + pagination: PropTypes.any, + icon: PropTypes.any, }; export default function IPopover(props) { - const { columns = [], getRequests, ...rest } = props; + const { + columns = [], + getRequests, + getData, + title, + pagination = false, + icon = , + ...rest + } = props; const content = ( - + ); return ( <> @@ -67,7 +90,7 @@ export default function IPopover(props) { mouseEnterDelay={0.5} {...rest} > - + {title} {icon} ); diff --git a/src/components/Popover/PopoverSubnets.jsx b/src/components/Popover/PopoverSubnets.jsx index b11ebb88..702cf59e 100644 --- a/src/components/Popover/PopoverSubnets.jsx +++ b/src/components/Popover/PopoverSubnets.jsx @@ -17,7 +17,7 @@ import { SubnetStore } from 'stores/neutron/subnet'; import IPopover from './Popover'; export default function PopoverSubnets(props) { - const { subnetIds = [] } = props; + const { subnetIds = [], title = '' } = props; if (!subnetIds.length) { return null; } @@ -34,5 +34,5 @@ export default function PopoverSubnets(props) { title: t('CIDR'), }, ]; - return ; + return ; } diff --git a/src/resources/neutron/network.jsx b/src/resources/neutron/network.jsx index 40c2aa32..21ff1756 100644 --- a/src/resources/neutron/network.jsx +++ b/src/resources/neutron/network.jsx @@ -61,14 +61,11 @@ export const networkColumns = (self) => [ title: t('Subnet Count'), dataIndex: 'subnets', render: (value, record) => { - return ( - <> - {(value && value.length) || 0}{' '} - {value && value.length !== 0 && ( - - )} - - ); + const count = (value || []).length; + if (count === 0) { + return count; + } + return ; }, stringify: (subnets) => `${subnets.length}(${subnets.join(',')})`, sorter: false,