Files
portainer/app/react/kubernetes/applications/DetailsView/ApplicationDetailsWidget/ButtonsLine.tsx
T

90 lines
2.3 KiB
TypeScript

import { Pod } from 'kubernetes-types/core/v1';
import { Stack } from '@/react/common/stacks/types';
import { EnvironmentId } from '@/react/portainer/environments/types';
import { isGitConfigDiverged } from '@/react/portainer/gitops/utils';
import { AddButton } from '@@/buttons';
import { useAppStackFile } from '../../queries/useAppStackFile';
import { Application } from '../../types';
import { applicationIsKind } from '../../utils';
import { EditButtons } from './EditButtons';
import { RedeployApplicationButton } from './RedeployApplicationButton';
import { RestartApplicationButton } from './RestartApplicationButton';
import { RollbackApplicationButton } from './RollbackApplicationButton';
export function ButtonsLine({
stack,
environmentId,
externalApp,
appStackKind,
app,
name,
namespace,
}: {
stack?: Stack;
externalApp: boolean;
environmentId: EnvironmentId;
appStackKind?: string;
namespace: string;
app?: Application;
name: string;
}) {
const appStackFileQuery = useAppStackFile(
{
id: stack?.Id,
kind: appStackKind,
},
{
enabled:
stack &&
(!stack.GitConfig ||
!isGitConfigDiverged(stack.GitConfig, stack.CurrentDeploymentInfo)),
}
);
const appStackFileContent = appStackFileQuery.data;
return (
<div className="flex flex-wrap gap-2">
<EditButtons
isEdge={appStackKind === 'edge'}
stackId={stack?.Id}
externalApp={externalApp}
stack={stack}
/>
{!applicationIsKind<Pod>('Pod', app) && (
<>
<RestartApplicationButton />
<RedeployApplicationButton
environmentId={environmentId}
namespace={namespace}
appName={name}
app={app}
/>
</>
)}
{!externalApp && (
<RollbackApplicationButton
environmentId={environmentId}
namespace={namespace}
appName={name}
app={app}
/>
)}
{appStackFileContent && (
<AddButton
to="kubernetes.templates.custom.new"
data-cy="k8sAppDetail-createCustomTemplateButton"
params={{
fileContent: appStackFileContent,
}}
>
Create template from application
</AddButton>
)}
</div>
);
}