mirror of
https://github.com/portainer/portainer.git
synced 2025-07-19 05:19:39 +02:00
fix: kubeconfig download button inconsistency between http and https (#829)
This commit is contained in:
parent
7d7ae24351
commit
8d29b5ae71
1 changed files with 32 additions and 17 deletions
|
@ -7,6 +7,7 @@ import { trackEvent } from '@/angulartics.matomo/analytics-services';
|
||||||
import { Query } from '@/react/portainer/environments/queries/useEnvironmentList';
|
import { Query } from '@/react/portainer/environments/queries/useEnvironmentList';
|
||||||
|
|
||||||
import { Button } from '@@/buttons';
|
import { Button } from '@@/buttons';
|
||||||
|
import { TooltipWithChildren } from '@@/Tip/TooltipWithChildren';
|
||||||
|
|
||||||
import { KubeconfigPrompt } from './KubeconfigPrompt';
|
import { KubeconfigPrompt } from './KubeconfigPrompt';
|
||||||
|
|
||||||
|
@ -23,23 +24,41 @@ export function KubeconfigButton({ environments, envQueryParams }: Props) {
|
||||||
isKubernetesEnvironment(env.Type)
|
isKubernetesEnvironment(env.Type)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!isKubeconfigButtonVisible()) {
|
const isHttp = window.location.protocol === 'http:';
|
||||||
return null;
|
const noKubeEnvs = kubeEnvs.length === 0;
|
||||||
|
const isDisabled = noKubeEnvs || isHttp;
|
||||||
|
|
||||||
|
let tooltipMessage = '';
|
||||||
|
if (isHttp) {
|
||||||
|
tooltipMessage =
|
||||||
|
'Kubeconfig download is not available when Portainer is accessed via HTTP. Please use HTTPS';
|
||||||
|
} else if (noKubeEnvs) {
|
||||||
|
tooltipMessage = 'No Kubernetes environments detected';
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
const button = (
|
||||||
<>
|
|
||||||
<Button
|
<Button
|
||||||
onClick={handleClick}
|
onClick={handleClick}
|
||||||
data-cy="download-kubeconfig-button"
|
data-cy="download-kubeconfig-button"
|
||||||
size="medium"
|
size="medium"
|
||||||
className="!m-0"
|
className="!m-0"
|
||||||
icon={Download}
|
icon={Download}
|
||||||
disabled={kubeEnvs.length === 0}
|
disabled={isDisabled}
|
||||||
color="light"
|
color="light"
|
||||||
>
|
>
|
||||||
Kubeconfig
|
Kubeconfig
|
||||||
</Button>
|
</Button>
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{isDisabled ? (
|
||||||
|
<TooltipWithChildren message={tooltipMessage}>
|
||||||
|
<span className="!m-0">{button}</span>
|
||||||
|
</TooltipWithChildren>
|
||||||
|
) : (
|
||||||
|
button
|
||||||
|
)}
|
||||||
{prompt()}
|
{prompt()}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
@ -60,10 +79,6 @@ export function KubeconfigButton({ environments, envQueryParams }: Props) {
|
||||||
setIsOpen(false);
|
setIsOpen(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
function isKubeconfigButtonVisible() {
|
|
||||||
return window.location.protocol === 'https:';
|
|
||||||
}
|
|
||||||
|
|
||||||
function prompt() {
|
function prompt() {
|
||||||
return (
|
return (
|
||||||
isOpen && (
|
isOpen && (
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue