mirror of
https://github.com/portainer/portainer.git
synced 2025-07-24 07:49: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,41 @@
|
|||
import { saveAs } from 'file-saver';
|
||||
import { useMutation } from 'react-query';
|
||||
|
||||
import { EnvironmentId } from '@/react/portainer/environments/types';
|
||||
import axios, { parseAxiosError } from '@/portainer/services/axios';
|
||||
import { mutationOptions, withError } from '@/react-tools/react-query';
|
||||
|
||||
import { EdgeStack } from '../../types';
|
||||
|
||||
export function useDownloadLogsMutation() {
|
||||
return useMutation(
|
||||
downloadLogs,
|
||||
mutationOptions(withError('Unable to download logs'))
|
||||
);
|
||||
}
|
||||
|
||||
interface DownloadLogs {
|
||||
edgeStackId: EdgeStack['Id'];
|
||||
environmentId: EnvironmentId;
|
||||
}
|
||||
|
||||
async function downloadLogs({ edgeStackId, environmentId }: DownloadLogs) {
|
||||
try {
|
||||
const { headers, data } = await axios.get<Blob>(
|
||||
`/edge_stacks/${edgeStackId}/logs/${environmentId}/file`,
|
||||
{
|
||||
responseType: 'blob',
|
||||
headers: {
|
||||
Accept: 'text/yaml',
|
||||
},
|
||||
}
|
||||
);
|
||||
const contentDispositionHeader = headers['content-disposition'];
|
||||
const filename = contentDispositionHeader
|
||||
.replace('attachment; filename=', '')
|
||||
.trim();
|
||||
saveAs(data, filename);
|
||||
} catch (e) {
|
||||
throw parseAxiosError(e as Error, '');
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue