Skip to content

Commit

Permalink
fix(instance) filter volume snapshots on selecting custom volume to a…
Browse files Browse the repository at this point in the history
…dd to an instance or profile. only show the custom volumes to select from. fixes #777

Signed-off-by: David Edler <[email protected]>
  • Loading branch information
edlerd authored and mas-who committed May 23, 2024
1 parent 487ba59 commit 130bb42
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
29 changes: 11 additions & 18 deletions src/context/loadCustomVolumes.tsx
Original file line number Diff line number Diff line change
@@ -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<LxdStorageVolume[]> => {
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;
Expand Down
9 changes: 7 additions & 2 deletions src/context/loadIsoVolumes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
4 changes: 3 additions & 1 deletion src/pages/storage/CustomVolumeSelectModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,6 +26,7 @@ const CustomVolumeSelectModal: FC<Props> = ({
onCreate,
}) => {
const notify = useNotify();
const { hasStorageVolumesAll } = useSupportedFeatures();

const {
data: volumes = [],
Expand All @@ -34,7 +36,7 @@ const CustomVolumeSelectModal: FC<Props> = ({
} = useQuery({
queryKey: [queryKeys.customVolumes],
refetchOnMount: (query) => query.state.isInvalidated,
queryFn: () => loadCustomVolumes(project),
queryFn: () => loadCustomVolumes(project, hasStorageVolumesAll),
});

if (error) {
Expand Down

0 comments on commit 130bb42

Please sign in to comment.