From 130bb42c85ee4d35e57a1f0f28f63a48326df6a7 Mon Sep 17 00:00:00 2001 From: David Edler Date: Thu, 23 May 2024 10:54:05 +0200 Subject: [PATCH] fix(instance) filter volume snapshots on selecting custom volume to add to an instance or profile. only show the custom volumes to select from. fixes #777 Signed-off-by: David Edler --- src/context/loadCustomVolumes.tsx | 29 +++++++------------ src/context/loadIsoVolumes.tsx | 9 ++++-- src/pages/storage/CustomVolumeSelectModal.tsx | 4 ++- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/context/loadCustomVolumes.tsx b/src/context/loadCustomVolumes.tsx index 7d0f304ab3..72ed267870 100644 --- a/src/context/loadCustomVolumes.tsx +++ b/src/context/loadCustomVolumes.tsx @@ -1,28 +1,21 @@ -import { fetchStoragePools, fetchStorageVolumes } from "api/storage-pools"; import { LxdStorageVolume } from "types/storage"; +import { isSnapshot } from "util/storageVolume"; +import { loadVolumes } from "context/loadIsoVolumes"; export const loadCustomVolumes = async ( project: string, + hasStorageVolumesAll: boolean, ): Promise => { const result: LxdStorageVolume[] = []; - const pools = await fetchStoragePools(project); - const volumePromises = pools.map(async (pool) => - fetchStorageVolumes(pool.name, project), - ); - const poolVolumes = await Promise.all(volumePromises); - - poolVolumes.forEach((volumes, index) => { - const pool = pools[index]; - volumes.forEach((volume) => { - const contentTypes = ["filesystem", "block"]; - const isFilesystemOrBlock = contentTypes.includes(volume.content_type); - const isCustom = volume.type === "custom"; - - if (isCustom && isFilesystemOrBlock) { - result.push({ ...volume, pool: pool.name }); - } - }); + const volumes = await loadVolumes(project, hasStorageVolumesAll); + volumes.forEach((volume) => { + const contentTypes = ["filesystem", "block"]; + const isFilesystemOrBlock = contentTypes.includes(volume.content_type); + const isCustom = volume.type === "custom"; + if (isCustom && isFilesystemOrBlock && !isSnapshot(volume)) { + result.push(volume); + } }); return result; diff --git a/src/context/loadIsoVolumes.tsx b/src/context/loadIsoVolumes.tsx index 9cdcc9cbd6..21736faad8 100644 --- a/src/context/loadIsoVolumes.tsx +++ b/src/context/loadIsoVolumes.tsx @@ -42,9 +42,14 @@ export const collectAllStorageVolumes = async ( pools.map(async (pool) => fetchStorageVolumes(pool.name, project)), ); - poolVolumes.forEach((result) => { + poolVolumes.forEach((result, index) => { if (result.status === "fulfilled") { - allVolumes.push(...result.value); + const pool = pools[index]; + const volumes = result.value.map((volume) => ({ + ...volume, + pool: pool.name, + })); + allVolumes.push(...volumes); } else { throw new Error("Failed to load iso images"); } diff --git a/src/pages/storage/CustomVolumeSelectModal.tsx b/src/pages/storage/CustomVolumeSelectModal.tsx index d37f7340cb..3c85f2a4ae 100644 --- a/src/pages/storage/CustomVolumeSelectModal.tsx +++ b/src/pages/storage/CustomVolumeSelectModal.tsx @@ -8,6 +8,7 @@ import ScrollableTable from "components/ScrollableTable"; import { LxdStorageVolume } from "types/storage"; import NotificationRow from "components/NotificationRow"; import { renderContentType } from "util/storageVolume"; +import { useSupportedFeatures } from "context/useSupportedFeatures"; interface Props { project: string; @@ -25,6 +26,7 @@ const CustomVolumeSelectModal: FC = ({ onCreate, }) => { const notify = useNotify(); + const { hasStorageVolumesAll } = useSupportedFeatures(); const { data: volumes = [], @@ -34,7 +36,7 @@ const CustomVolumeSelectModal: FC = ({ } = useQuery({ queryKey: [queryKeys.customVolumes], refetchOnMount: (query) => query.state.isInvalidated, - queryFn: () => loadCustomVolumes(project), + queryFn: () => loadCustomVolumes(project, hasStorageVolumesAll), }); if (error) {