-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(zones): Add delete zones as a table action MAASENG-4308 (#5590)
- Loading branch information
1 parent
b12b50b
commit 1480b3d
Showing
13 changed files
with
137 additions
and
227 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 0 additions & 49 deletions
49
src/app/zones/views/ZoneDetails/ZoneDetailsHeader/DeleteConfirm/DeleteConfirm.test.tsx
This file was deleted.
Oops, something went wrong.
50 changes: 0 additions & 50 deletions
50
src/app/zones/views/ZoneDetails/ZoneDetailsHeader/DeleteConfirm/DeleteConfirm.tsx
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
src/app/zones/views/ZoneDetails/ZoneDetailsHeader/DeleteConfirm/index.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/app/zones/views/ZonesList/ZonesListTable/DeleteZone/DeleteZone.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Formik } from "formik"; | ||
|
||
import DeleteZone from "./DeleteZone"; | ||
|
||
import { userEvent, screen, renderWithBrowserRouter } from "@/testing/utils"; | ||
|
||
describe("DeleteZone", () => { | ||
it("calls closeForm on cancel click", async () => { | ||
const closeForm = vi.fn(); | ||
renderWithBrowserRouter( | ||
<Formik initialValues={{ images: [] }} onSubmit={vi.fn()}> | ||
<DeleteZone closeForm={closeForm} id={2} /> | ||
</Formik> | ||
); | ||
|
||
await userEvent.click(screen.getByRole("button", { name: "Cancel" })); | ||
expect(closeForm).toHaveBeenCalled(); | ||
}); | ||
}); |
42 changes: 42 additions & 0 deletions
42
src/app/zones/views/ZonesList/ZonesListTable/DeleteZone/DeleteZone.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import React from "react"; | ||
|
||
import { useDispatch, useSelector } from "react-redux"; | ||
|
||
import ModelActionForm from "@/app/base/components/ModelActionForm"; | ||
import type { RootState } from "@/app/store/root/types"; | ||
import { zoneActions } from "@/app/store/zone"; | ||
import { ZONE_ACTIONS } from "@/app/store/zone/constants"; | ||
import zoneSelectors from "@/app/store/zone/selectors"; | ||
|
||
type DeleteZoneProps = { | ||
closeForm: () => void; | ||
id: number; | ||
}; | ||
|
||
const DeleteZone: React.FC<DeleteZoneProps> = ({ closeForm, id }) => { | ||
const dispatch = useDispatch(); | ||
const deleteStatus = useSelector((state: RootState) => | ||
zoneSelectors.getModelActionStatus(state, ZONE_ACTIONS.delete, id) | ||
); | ||
|
||
return ( | ||
<ModelActionForm | ||
aria-label="Confirm AZ deletion" | ||
initialValues={{}} | ||
message="Are you sure you want to delete this AZ?" | ||
modelType="zone" | ||
onCancel={closeForm} | ||
onSubmit={() => { | ||
dispatch(zoneActions.delete({ id })); | ||
}} | ||
onSuccess={() => { | ||
dispatch(zoneActions.cleanup([ZONE_ACTIONS.delete])); | ||
closeForm(); | ||
}} | ||
saved={deleteStatus === "success"} | ||
saving={deleteStatus === "loading"} | ||
/> | ||
); | ||
}; | ||
|
||
export default DeleteZone; |
1 change: 1 addition & 0 deletions
1
src/app/zones/views/ZonesList/ZonesListTable/DeleteZone/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from "./DeleteZone"; |
Oops, something went wrong.