mirror of
https://github.com/portainer/portainer.git
synced 2025-07-24 07:49:41 +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
51
app/react/kubernetes/volumes/queries/useNamespaceVolumes.ts
Normal file
51
app/react/kubernetes/volumes/queries/useNamespaceVolumes.ts
Normal file
|
@ -0,0 +1,51 @@
|
|||
import { useQuery } from '@tanstack/react-query';
|
||||
|
||||
import { EnvironmentId } from '@/react/portainer/environments/types';
|
||||
import { withGlobalError } from '@/react-tools/react-query';
|
||||
import axios, { parseAxiosError } from '@/portainer/services/axios';
|
||||
|
||||
import { K8sVolumeInfo } from '../types';
|
||||
|
||||
import { queryKeys } from './query-keys';
|
||||
import { convertToVolumeViewModels } from './useVolumesQuery';
|
||||
|
||||
// useQuery to get a list of all volumes in a cluster
|
||||
export function useNamespaceVolumes(
|
||||
environmentId: EnvironmentId,
|
||||
namespace: string,
|
||||
queryOptions?: {
|
||||
refetchInterval?: number;
|
||||
withApplications?: boolean;
|
||||
}
|
||||
) {
|
||||
return useQuery(
|
||||
queryKeys.volumes(environmentId),
|
||||
() =>
|
||||
getNamespaceVolumes(environmentId, namespace, {
|
||||
withApplications: queryOptions?.withApplications ?? false,
|
||||
}),
|
||||
{
|
||||
enabled: !!namespace,
|
||||
refetchInterval: queryOptions?.refetchInterval,
|
||||
select: convertToVolumeViewModels,
|
||||
...withGlobalError('Unable to retrieve volumes'),
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// get all volumes in a cluster
|
||||
async function getNamespaceVolumes(
|
||||
environmentId: EnvironmentId,
|
||||
namespace: string,
|
||||
params?: { withApplications: boolean }
|
||||
) {
|
||||
try {
|
||||
const { data } = await axios.get<K8sVolumeInfo[]>(
|
||||
`/kubernetes/${environmentId}/namespaces/${namespace}/volumes`,
|
||||
{ params }
|
||||
);
|
||||
return data;
|
||||
} catch (e) {
|
||||
throw parseAxiosError(e, 'Unable to retrieve volumes');
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue