mirror of
https://github.com/portainer/portainer.git
synced 2025-07-24 07:49:41 +02:00
fix(published-ports): fix published port link and into a new component [EE-6592] (#11656)
Some checks are pending
ci / build_images (map[arch:amd64 platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
ci / build_images (map[arch:arm platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:arm64 platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:ppc64le platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:s390x platform:linux version:]) (push) Waiting to run
ci / build_manifests (push) Blocked by required conditions
/ triage (push) Waiting to run
Lint / Run linters (push) Waiting to run
Test / test-server (map[arch:amd64 platform:linux]) (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
Test / test-server (map[arch:arm64 platform:linux]) (push) Waiting to run
Test / test-client (push) Waiting to run
Some checks are pending
ci / build_images (map[arch:amd64 platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
ci / build_images (map[arch:arm platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:arm64 platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:ppc64le platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:s390x platform:linux version:]) (push) Waiting to run
ci / build_manifests (push) Blocked by required conditions
/ triage (push) Waiting to run
Lint / Run linters (push) Waiting to run
Test / test-server (map[arch:amd64 platform:linux]) (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
Test / test-server (map[arch:arm64 platform:linux]) (push) Waiting to run
Test / test-client (push) Waiting to run
This commit is contained in:
parent
4f4c685085
commit
39fce3e29b
3 changed files with 65 additions and 68 deletions
|
@ -1,11 +1,8 @@
|
|||
import _ from 'lodash';
|
||||
import { ExternalLink } from 'lucide-react';
|
||||
import { CellContext } from '@tanstack/react-table';
|
||||
|
||||
import type { DockerContainer } from '@/react/docker/containers/types';
|
||||
import { getSchemeFromPort } from '@/react/common/network-utils';
|
||||
|
||||
import { Icon } from '@@/Icon';
|
||||
import { PublishedPortLink } from '@/react/docker/components/ImageStatus/PublishedPortLink';
|
||||
|
||||
import { useRowContext } from '../RowContext';
|
||||
|
||||
|
@ -32,46 +29,12 @@ function Cell({ row }: CellContext<DockerContainer, string>) {
|
|||
return '-';
|
||||
}
|
||||
|
||||
const publicURL = getPublicUrl(environment.PublicURL);
|
||||
|
||||
return _.uniqBy(ports, 'public').map((port) => {
|
||||
let url = publicURL || port.host || '';
|
||||
if (!url.startsWith('http')) {
|
||||
const scheme = getSchemeFromPort(port.private);
|
||||
url = `${scheme}://${url}`;
|
||||
}
|
||||
url = `${url}:${port.public}`;
|
||||
|
||||
return (
|
||||
<a
|
||||
key={`${port.host}:${port.public}`}
|
||||
className="image-tag"
|
||||
href={url}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
>
|
||||
<Icon icon={ExternalLink} />
|
||||
{port.public}:{port.private}
|
||||
</a>
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
function getPublicUrl(url?: string): string {
|
||||
if (!url) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// Add protocol if missing
|
||||
const u =
|
||||
url.startsWith('http://') || url.startsWith('https://')
|
||||
? url
|
||||
: `http://${url}`;
|
||||
|
||||
try {
|
||||
const parsedUrl = new URL(u);
|
||||
return `${parsedUrl.protocol}://${parsedUrl.hostname}`;
|
||||
} catch (error) {
|
||||
return '';
|
||||
}
|
||||
return _.uniqBy(ports, 'public').map((port) => (
|
||||
<PublishedPortLink
|
||||
key={`${port.host}:${port.public}`}
|
||||
hostPort={port.public}
|
||||
containerPort={port.private}
|
||||
hostURL={environment.PublicURL || port.host}
|
||||
/>
|
||||
));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue