|
|
|
@ -9,6 +9,7 @@ import { EnvironmentId } from '@/react/portainer/environments/types';
|
|
|
|
|
import axios, { parseAxiosError } from '@/portainer/services/axios';
|
|
|
|
|
|
|
|
|
|
import { buildDockerProxyUrl } from '../../proxy/queries/buildDockerProxyUrl';
|
|
|
|
|
import { withAgentTargetHeader } from '../../proxy/queries/utils';
|
|
|
|
|
import { NetworkId } from '../types';
|
|
|
|
|
|
|
|
|
|
import { queryKeys } from './queryKeys';
|
|
|
|
@ -17,8 +18,8 @@ export function useDeleteNetwork(environmentId: EnvironmentId) {
|
|
|
|
|
const queryClient = useQueryClient();
|
|
|
|
|
|
|
|
|
|
return useMutation(
|
|
|
|
|
({ networkId }: { networkId: NetworkId }) =>
|
|
|
|
|
deleteNetwork(environmentId, networkId),
|
|
|
|
|
({ networkId, nodeName }: { networkId: NetworkId; nodeName?: string }) =>
|
|
|
|
|
deleteNetwork(environmentId, networkId, { nodeName }),
|
|
|
|
|
mutationOptions(
|
|
|
|
|
withInvalidate(queryClient, [queryKeys.base(environmentId)]),
|
|
|
|
|
withError('Unable to remove network')
|
|
|
|
@ -34,11 +35,15 @@ export function useDeleteNetwork(environmentId: EnvironmentId) {
|
|
|
|
|
*/
|
|
|
|
|
export async function deleteNetwork(
|
|
|
|
|
environmentId: EnvironmentId,
|
|
|
|
|
networkId: NetworkId
|
|
|
|
|
networkId: NetworkId,
|
|
|
|
|
{ nodeName }: { nodeName?: string } = {}
|
|
|
|
|
) {
|
|
|
|
|
try {
|
|
|
|
|
await axios.delete(
|
|
|
|
|
buildDockerProxyUrl(environmentId, 'networks', networkId)
|
|
|
|
|
buildDockerProxyUrl(environmentId, 'networks', networkId),
|
|
|
|
|
{
|
|
|
|
|
headers: { ...withAgentTargetHeader(nodeName) },
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
return networkId;
|
|
|
|
|
} catch (err) {
|
|
|
|
|