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,51 @@
|
|||
import { useQuery } from 'react-query';
|
||||
|
||||
import { EnvironmentId } from '@/react/portainer/environments/types';
|
||||
import axios, { parseAxiosError } from '@/portainer/services/axios';
|
||||
import { EdgeStack } from '@/react/edge/edge-stacks/types';
|
||||
|
||||
import { queryKeys } from '../../queries/query-keys';
|
||||
|
||||
export function logsStatusQueryKey(
|
||||
edgeStackId: EdgeStack['Id'],
|
||||
environmentId: EnvironmentId
|
||||
) {
|
||||
return [...queryKeys.item(edgeStackId), 'logs', environmentId] as const;
|
||||
}
|
||||
|
||||
export function useLogsStatus(
|
||||
edgeStackId: EdgeStack['Id'],
|
||||
environmentId: EnvironmentId
|
||||
) {
|
||||
return useQuery(
|
||||
logsStatusQueryKey(edgeStackId, environmentId),
|
||||
() => getLogsStatus(edgeStackId, environmentId),
|
||||
{
|
||||
refetchInterval(status) {
|
||||
if (status === 'pending') {
|
||||
return 30 * 1000;
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
interface LogsStatusResponse {
|
||||
status: 'collected' | 'idle' | 'pending';
|
||||
}
|
||||
|
||||
async function getLogsStatus(
|
||||
edgeStackId: EdgeStack['Id'],
|
||||
environmentId: EnvironmentId
|
||||
) {
|
||||
try {
|
||||
const { data } = await axios.get<LogsStatusResponse>(
|
||||
`/edge_stacks/${edgeStackId}/logs/${environmentId}`
|
||||
);
|
||||
return data.status;
|
||||
} catch (error) {
|
||||
throw parseAxiosError(error as Error, 'Unable to retrieve logs status');
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue