mirror of
https://github.com/portainer/portainer.git
synced 2025-07-23 15:29:42 +02:00
refactor(namespace): migrate namespace edit to react [r8s-125] (#38)
This commit is contained in:
parent
40c7742e46
commit
ce7e0d8d60
108 changed files with 3183 additions and 2194 deletions
43
app/react/kubernetes/services/useNamespaceServices.ts
Normal file
43
app/react/kubernetes/services/useNamespaceServices.ts
Normal file
|
@ -0,0 +1,43 @@
|
|||
import { useQuery, UseQueryOptions } from '@tanstack/react-query';
|
||||
|
||||
import { EnvironmentId } from '@/react/portainer/environments/types';
|
||||
import { error as notifyError } from '@/portainer/services/notifications';
|
||||
import axios, { parseAxiosError } from '@/portainer/services/axios';
|
||||
|
||||
import { Service } from './types';
|
||||
|
||||
export function useNamespaceServices<T = Service[]>(
|
||||
environmentId: EnvironmentId,
|
||||
namespace: string,
|
||||
queryOptions?: UseQueryOptions<Service[], unknown, T>
|
||||
) {
|
||||
return useQuery({
|
||||
queryKey: [
|
||||
'environments',
|
||||
environmentId,
|
||||
'kubernetes',
|
||||
'namespaces',
|
||||
namespace,
|
||||
'services',
|
||||
],
|
||||
queryFn: () => getServices(environmentId, namespace),
|
||||
onError: (err) => {
|
||||
notifyError('Failure', err as Error, 'Unable to get services');
|
||||
},
|
||||
...queryOptions,
|
||||
});
|
||||
}
|
||||
|
||||
export async function getServices(
|
||||
environmentId: EnvironmentId,
|
||||
namespace: string
|
||||
) {
|
||||
try {
|
||||
const { data: services } = await axios.get<Service[]>(
|
||||
`kubernetes/${environmentId}/namespaces/${namespace}/services`
|
||||
);
|
||||
return services;
|
||||
} catch (e) {
|
||||
throw parseAxiosError(e as Error, 'Unable to retrieve services');
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue