2022-05-09 21:01:15 +00:00
|
|
|
import { Fragment } from 'react';
|
2022-11-28 02:00:28 +00:00
|
|
|
import { Share2, Trash2 } from 'lucide-react';
|
2022-05-09 21:01:15 +00:00
|
|
|
|
2022-09-21 06:14:29 +00:00
|
|
|
import DockerNetworkHelper from '@/docker/helpers/networkHelper';
|
2022-11-13 08:10:18 +00:00
|
|
|
import { Authorized } from '@/react/hooks/useUser';
|
2022-05-09 21:01:15 +00:00
|
|
|
|
2023-05-02 06:42:16 +00:00
|
|
|
import { TableContainer, TableTitle } from '@@/datatables';
|
2022-06-17 16:18:42 +00:00
|
|
|
import { DetailsTable } from '@@/DetailsTable';
|
|
|
|
import { Button } from '@@/buttons';
|
2022-07-24 23:57:18 +00:00
|
|
|
import { Icon } from '@@/Icon';
|
2022-06-17 16:18:42 +00:00
|
|
|
|
2022-05-09 21:01:15 +00:00
|
|
|
import { isSystemNetwork } from '../network.helper';
|
|
|
|
import { DockerNetwork, IPConfig } from '../types';
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
network: DockerNetwork;
|
|
|
|
onRemoveNetworkClicked: () => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function NetworkDetailsTable({
|
|
|
|
network,
|
|
|
|
onRemoveNetworkClicked,
|
|
|
|
}: Props) {
|
|
|
|
const allowRemoveNetwork = !isSystemNetwork(network.Name);
|
|
|
|
const ipv4Configs: IPConfig[] = DockerNetworkHelper.getIPV4Configs(
|
|
|
|
network.IPAM?.Config
|
|
|
|
);
|
|
|
|
const ipv6Configs: IPConfig[] = DockerNetworkHelper.getIPV6Configs(
|
|
|
|
network.IPAM?.Config
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
2022-11-22 12:16:34 +00:00
|
|
|
<TableContainer>
|
2022-11-28 02:00:28 +00:00
|
|
|
<TableTitle label="Network details" icon={Share2} />
|
2023-05-02 06:42:16 +00:00
|
|
|
<DetailsTable dataCy="networkDetails-detailsTable">
|
|
|
|
{/* networkRowContent */}
|
|
|
|
<DetailsTable.Row label="Name">{network.Name}</DetailsTable.Row>
|
|
|
|
<DetailsTable.Row label="Id">
|
|
|
|
{network.Id}
|
|
|
|
{allowRemoveNetwork && (
|
|
|
|
<Authorized authorizations="DockerNetworkDelete">
|
|
|
|
<Button
|
|
|
|
data-cy="networkDetails-deleteNetwork"
|
|
|
|
size="xsmall"
|
|
|
|
color="danger"
|
|
|
|
onClick={() => onRemoveNetworkClicked()}
|
2022-11-22 12:16:34 +00:00
|
|
|
>
|
2023-05-02 06:42:16 +00:00
|
|
|
<Icon
|
|
|
|
icon={Trash2}
|
|
|
|
className="space-right"
|
|
|
|
aria-hidden="true"
|
|
|
|
/>
|
|
|
|
Delete this network
|
|
|
|
</Button>
|
|
|
|
</Authorized>
|
|
|
|
)}
|
|
|
|
</DetailsTable.Row>
|
|
|
|
<DetailsTable.Row label="Driver">{network.Driver}</DetailsTable.Row>
|
|
|
|
<DetailsTable.Row label="Scope">{network.Scope}</DetailsTable.Row>
|
|
|
|
<DetailsTable.Row label="Attachable">
|
|
|
|
{String(network.Attachable)}
|
|
|
|
</DetailsTable.Row>
|
|
|
|
<DetailsTable.Row label="Internal">
|
|
|
|
{String(network.Internal)}
|
|
|
|
</DetailsTable.Row>
|
2022-11-22 12:16:34 +00:00
|
|
|
|
2023-05-02 06:42:16 +00:00
|
|
|
{/* IPV4 ConfigRowContent */}
|
|
|
|
{ipv4Configs.map((config) => (
|
|
|
|
<Fragment key={config.Subnet}>
|
|
|
|
<DetailsTable.Row
|
|
|
|
label={`IPV4 Subnet${getConfigDetails(config.Subnet)}`}
|
|
|
|
>
|
|
|
|
{`IPV4 Gateway${getConfigDetails(config.Gateway)}`}
|
|
|
|
</DetailsTable.Row>
|
|
|
|
<DetailsTable.Row
|
|
|
|
label={`IPV4 IP Range${getConfigDetails(config.IPRange)}`}
|
|
|
|
>
|
|
|
|
{`IPV4 Excluded IPs${getAuxiliaryAddresses(
|
|
|
|
config.AuxiliaryAddresses
|
|
|
|
)}`}
|
|
|
|
</DetailsTable.Row>
|
|
|
|
</Fragment>
|
|
|
|
))}
|
|
|
|
|
|
|
|
{/* IPV6 ConfigRowContent */}
|
|
|
|
{ipv6Configs.map((config) => (
|
|
|
|
<Fragment key={config.Subnet}>
|
|
|
|
<DetailsTable.Row
|
|
|
|
label={`IPV6 Subnet${getConfigDetails(config.Subnet)}`}
|
|
|
|
>
|
|
|
|
{`IPV6 Gateway${getConfigDetails(config.Gateway)}`}
|
|
|
|
</DetailsTable.Row>
|
|
|
|
<DetailsTable.Row
|
|
|
|
label={`IPV6 IP Range${getConfigDetails(config.IPRange)}`}
|
|
|
|
>
|
|
|
|
{`IPV6 Excluded IPs${getAuxiliaryAddresses(
|
|
|
|
config.AuxiliaryAddresses
|
|
|
|
)}`}
|
|
|
|
</DetailsTable.Row>
|
|
|
|
</Fragment>
|
|
|
|
))}
|
|
|
|
</DetailsTable>
|
2022-11-22 12:16:34 +00:00
|
|
|
</TableContainer>
|
2022-05-09 21:01:15 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
function getConfigDetails(configValue?: string) {
|
|
|
|
return configValue ? ` - ${configValue}` : '';
|
|
|
|
}
|
|
|
|
|
|
|
|
function getAuxiliaryAddresses(auxiliaryAddresses?: object) {
|
|
|
|
return auxiliaryAddresses
|
|
|
|
? ` - ${Object.values(auxiliaryAddresses).join(' - ')}`
|
|
|
|
: '';
|
|
|
|
}
|
|
|
|
}
|