mirror of
https://github.com/portainer/portainer.git
synced 2025-08-02 20:35:25 +02:00
refactor(nomad): sync frontend with EE [EE-3353] (#7758)
This commit is contained in:
parent
78dcba614d
commit
881e99df53
68 changed files with 1799 additions and 17 deletions
75
app/react/nomad/jobs/EventsView/useEvents.ts
Normal file
75
app/react/nomad/jobs/EventsView/useEvents.ts
Normal file
|
@ -0,0 +1,75 @@
|
|||
import { useQuery, useQueryClient } from 'react-query';
|
||||
import { useCurrentStateAndParams } from '@uirouter/react';
|
||||
|
||||
import * as notifications from '@/portainer/services/notifications';
|
||||
import { EnvironmentId } from '@/react/portainer/environments/types';
|
||||
import axios, { parseAxiosError } from '@/portainer/services/axios';
|
||||
|
||||
import { NomadEventsList } from '../../types';
|
||||
|
||||
export function useEvents() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
const {
|
||||
params: {
|
||||
endpointId: environmentID,
|
||||
allocationID,
|
||||
jobID,
|
||||
taskName,
|
||||
namespace,
|
||||
},
|
||||
} = useCurrentStateAndParams();
|
||||
|
||||
if (!environmentID) {
|
||||
throw new Error('endpointId url param is required');
|
||||
}
|
||||
|
||||
const key = [
|
||||
'environments',
|
||||
environmentID,
|
||||
'nomad',
|
||||
'events',
|
||||
allocationID,
|
||||
jobID,
|
||||
taskName,
|
||||
namespace,
|
||||
];
|
||||
|
||||
function invalidateQuery() {
|
||||
return queryClient.invalidateQueries(key);
|
||||
}
|
||||
|
||||
const query = useQuery(
|
||||
key,
|
||||
() =>
|
||||
getTaskEvents(environmentID, allocationID, jobID, taskName, namespace),
|
||||
{
|
||||
refetchOnWindowFocus: false,
|
||||
onError: (err) => {
|
||||
notifications.error('Failed loading events', err as Error, '');
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
return { query, invalidateQuery };
|
||||
}
|
||||
|
||||
export async function getTaskEvents(
|
||||
environmentId: EnvironmentId,
|
||||
allocationId: string,
|
||||
jobId: string,
|
||||
taskName: string,
|
||||
namespace: string
|
||||
) {
|
||||
try {
|
||||
const ret = await axios.get<NomadEventsList>(
|
||||
`/nomad/endpoints/${environmentId}/allocation/${allocationId}/events`,
|
||||
{
|
||||
params: { jobId, taskName, namespace },
|
||||
}
|
||||
);
|
||||
return ret.data;
|
||||
} catch (e) {
|
||||
throw parseAxiosError(e as Error);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue