diff --git a/src/components/Modal/DeleteBlueprint.js b/src/components/Modal/DeleteBlueprint.js index 8e1e5ffea..8168c53c5 100644 --- a/src/components/Modal/DeleteBlueprint.js +++ b/src/components/Modal/DeleteBlueprint.js @@ -1,14 +1,16 @@ import React from "react"; import PropTypes from "prop-types"; -import { useDispatch } from "react-redux"; +import { useDispatch, useSelector } from "react-redux"; import { useIntl, FormattedMessage } from "react-intl"; import { Modal, ModalVariant, Button } from "@patternfly/react-core"; import { deleteBlueprint } from "../../slices/blueprintsSlice"; +import { selectAllImages } from "../../slices/imagesSlice"; export const DeleteBlueprint = (props) => { const dispatch = useDispatch(); const intl = useIntl(); + const images = useSelector((state) => selectAllImages(state)); const [isModalOpen, setIsModalOpen] = React.useState(false); @@ -17,7 +19,11 @@ export const DeleteBlueprint = (props) => { }; const handleSubmit = () => { - dispatch(deleteBlueprint(props.blueprint.name)); + const args = { + blueprintName: props.blueprint.name, + images: images, + }; + dispatch(deleteBlueprint(args)); setIsModalOpen(false); }; @@ -43,7 +49,10 @@ export const DeleteBlueprint = (props) => { , ]} > -

Are you sure you want to delete the blueprint

+

+ Are you sure you want to delete the blueprint and all associated + images? +

This action cannot be undone.

diff --git a/src/slices/blueprintsSlice.js b/src/slices/blueprintsSlice.js index f60a200f3..629405fe7 100644 --- a/src/slices/blueprintsSlice.js +++ b/src/slices/blueprintsSlice.js @@ -5,6 +5,7 @@ import { createSelector, } from "@reduxjs/toolkit"; import * as api from "../api"; +import { deleteImage } from "./imagesSlice"; export const blueprintsAdapter = createEntityAdapter({ // the id for each blueprint is the blueprint name @@ -63,8 +64,14 @@ export const depsolveBlueprint = createAsyncThunk( export const deleteBlueprint = createAsyncThunk( "blueprints/delete", - async (blueprintName) => { + async (args, { dispatch }) => { + const { blueprintName, images } = args; await api.deleteBlueprint(blueprintName); + images.forEach(async (image) => { + if (image.blueprint === blueprintName) { + dispatch(deleteImage(image.id)); + } + }); return blueprintName; } );