mirror of
https://github.com/portainer/portainer.git
synced 2025-07-24 15:59:41 +02:00
fix(k8s-services): avoid rerendering services table [r8s-387] (#832)
This commit is contained in:
parent
8d29b5ae71
commit
303047656e
9 changed files with 216 additions and 99 deletions
|
@ -36,7 +36,7 @@ export function useDeleteVolumes(environmentId: EnvironmentId) {
|
|||
);
|
||||
}
|
||||
queryClient.invalidateQueries(queryKeys.storages(environmentId));
|
||||
queryClient.invalidateQueries(queryKeys.volumes(environmentId));
|
||||
return queryClient.invalidateQueries(queryKeys.volumes(environmentId));
|
||||
},
|
||||
...withGlobalError('Unable to remove volumes'),
|
||||
});
|
||||
|
|
|
@ -1,51 +0,0 @@
|
|||
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');
|
||||
}
|
||||
}
|
|
@ -14,10 +14,11 @@ import { appOwnerLabel } from '../../applications/constants';
|
|||
import { queryKeys } from './query-keys';
|
||||
|
||||
// useQuery to get a list of all volumes in a cluster
|
||||
export function useAllVolumesQuery(
|
||||
export function useAllVolumesQuery<T = K8sVolumeInfo>(
|
||||
environmentId: EnvironmentId,
|
||||
queryOptions?: {
|
||||
refetchInterval?: number;
|
||||
select?: (volumes: K8sVolumeInfo[]) => T[];
|
||||
}
|
||||
) {
|
||||
return useQuery(
|
||||
|
@ -25,7 +26,7 @@ export function useAllVolumesQuery(
|
|||
() => getAllVolumes(environmentId, { withApplications: true }),
|
||||
{
|
||||
refetchInterval: queryOptions?.refetchInterval,
|
||||
select: convertToVolumeViewModels,
|
||||
select: queryOptions?.select,
|
||||
...withGlobalError('Unable to retrieve volumes'),
|
||||
}
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue