2022-09-21 16:49:42 +12:00
|
|
|
import { useQuery } from 'react-query';
|
|
|
|
|
2022-10-23 09:53:25 +03:00
|
|
|
import { EnvironmentId } from '@/react/portainer/environments/types';
|
2022-09-21 16:49:42 +12:00
|
|
|
import { error as notifyError } from '@/portainer/services/notifications';
|
|
|
|
|
|
|
|
import { getNamespaces, getNamespace } from './service';
|
|
|
|
|
|
|
|
export function useNamespaces(environmentId: EnvironmentId) {
|
|
|
|
return useQuery(
|
|
|
|
['environments', environmentId, 'kubernetes', 'namespaces'],
|
|
|
|
() => getNamespaces(environmentId),
|
|
|
|
{
|
|
|
|
onError: (err) => {
|
|
|
|
notifyError('Failure', err as Error, 'Unable to get namespaces.');
|
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function useNamespace(environmentId: EnvironmentId, namespace: string) {
|
|
|
|
return useQuery(
|
|
|
|
['environments', environmentId, 'kubernetes', 'namespaces', namespace],
|
|
|
|
() => getNamespace(environmentId, namespace),
|
|
|
|
{
|
|
|
|
onError: (err) => {
|
|
|
|
notifyError('Failure', err as Error, 'Unable to get namespace.');
|
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|