mirror of
https://github.com/portainer/portainer.git
synced 2025-07-24 15:59:41 +02:00
refactor(edge/stacks): migrate envs table to react [EE-5613] (#9093)
This commit is contained in:
parent
dfc1a7b1d7
commit
11571fd6ea
24 changed files with 652 additions and 281 deletions
|
@ -0,0 +1,112 @@
|
|||
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 (
|
||||
<>
|
||||
<Button color="none" title="Retrieve logs" onClick={handleCollectLogs}>
|
||||
<Icon
|
||||
icon={clsx({
|
||||
'file-text': !collecting,
|
||||
loader: collecting,
|
||||
})}
|
||||
/>
|
||||
</Button>
|
||||
<Button
|
||||
color="none"
|
||||
title="Download logs"
|
||||
disabled={status !== 'collected'}
|
||||
onClick={handleDownloadLogs}
|
||||
>
|
||||
<Icon
|
||||
icon={clsx({
|
||||
'download-cloud': !downloadLogsMutation.isLoading,
|
||||
loader: downloadLogsMutation.isLoading,
|
||||
})}
|
||||
/>
|
||||
</Button>
|
||||
<Button
|
||||
color="none"
|
||||
title="Delete logs"
|
||||
disabled={status !== 'collected'}
|
||||
onClick={handleDeleteLogs}
|
||||
>
|
||||
<Icon
|
||||
icon={clsx({
|
||||
delete: !deleteLogsMutation.isLoading,
|
||||
loader: deleteLogsMutation.isLoading,
|
||||
})}
|
||||
/>
|
||||
</Button>
|
||||
</>
|
||||
);
|
||||
|
||||
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');
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue