mirror of
https://github.com/portainer/portainer.git
synced 2025-08-02 20:35:25 +02:00
feat(home): move edge device to view [EE-4559] (#8189)
Co-authored-by: matias.spinarolli <matias.spinarolli@portainer.io>
This commit is contained in:
parent
b4a6f6911c
commit
7fe0712b61
72 changed files with 988 additions and 1593 deletions
|
@ -0,0 +1,40 @@
|
|||
import { useMutation, useQueryClient } from 'react-query';
|
||||
|
||||
import axios, { parseAxiosError } from '@/portainer/services/axios';
|
||||
import { withError } from '@/react-tools/react-query';
|
||||
import { EnvironmentId } from '@/react/portainer/environments/types';
|
||||
|
||||
export enum DeviceAction {
|
||||
PowerOn = 'power on',
|
||||
PowerOff = 'power off',
|
||||
Restart = 'restart',
|
||||
}
|
||||
|
||||
export function useExecuteAMTDeviceActionMutation() {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation(executeDeviceAction, {
|
||||
onSuccess(_data, { environmentId }) {
|
||||
queryClient.invalidateQueries([['amt_devices', environmentId]]);
|
||||
},
|
||||
...withError('Unable to execute device action'),
|
||||
});
|
||||
}
|
||||
|
||||
async function executeDeviceAction({
|
||||
action,
|
||||
deviceGUID,
|
||||
environmentId,
|
||||
}: {
|
||||
environmentId: EnvironmentId;
|
||||
deviceGUID: string;
|
||||
action: DeviceAction;
|
||||
}) {
|
||||
try {
|
||||
await axios.post(
|
||||
`/open_amt/${environmentId}/devices/${deviceGUID}/action`,
|
||||
{ action }
|
||||
);
|
||||
} catch (e) {
|
||||
throw parseAxiosError(e as Error, 'Unable to execute device action');
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue