import clsx from 'clsx';
import { notifySuccess } from '@/portainer/services/notifications';
import { EnvironmentId } from '@/react/portainer/environments/types';
import { Button } from '@@/buttons';
import { Icon } from '@@/Icon';
import { EdgeStack } from '../../types';
import { useCollectLogsMutation } from './useCollectLogsMutation';
import { useDeleteLogsMutation } from './useDeleteLogsMutation';
import { useDownloadLogsMutation } from './useDownloadLogsMutation';
import { useLogsStatus } from './useLogsStatus';
interface Props {
environmentId: EnvironmentId;
edgeStackId: EdgeStack['Id'];
}
export function LogsActions({ environmentId, edgeStackId }: Props) {
const logsStatusQuery = useLogsStatus(edgeStackId, environmentId);
const collectLogsMutation = useCollectLogsMutation();
const downloadLogsMutation = useDownloadLogsMutation();
const deleteLogsMutation = useDeleteLogsMutation();
if (!logsStatusQuery.isSuccess) {
return null;
}
const status = logsStatusQuery.data;
const collecting = collectLogsMutation.isLoading || status === 'pending';
return (
<>
>
);
function handleCollectLogs() {
if (status === 'pending') {
return;
}
collectLogsMutation.mutate(
{
edgeStackId,
environmentId,
},
{
onSuccess() {
notifySuccess('Success', 'Logs Collection started');
},
}
);
}
function handleDownloadLogs() {
downloadLogsMutation.mutate({
edgeStackId,
environmentId,
});
}
function handleDeleteLogs() {
deleteLogsMutation.mutate(
{
edgeStackId,
environmentId,
},
{
onSuccess() {
notifySuccess('Success', 'Logs Deleted');
},
}
);
}
}