-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: move file system forms to side panel (#5365)
- Loading branch information
1 parent
2bcd18b
commit 0bf1d6f
Showing
15 changed files
with
500 additions
and
234 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
...components/node/StorageTables/FilesystemsTable/DeleteFilesystem/DeleteFilesystem.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,60 @@ | ||
import configureStore from "redux-mock-store"; | ||
|
||
import DeleteFilesystem from "./DeleteFilesystem"; | ||
|
||
import { actions as machineActions } from "@/app/store/machine"; | ||
import type { RootState } from "@/app/store/root/types"; | ||
import * as factory from "@/testing/factories"; | ||
import { renderWithBrowserRouter, screen, userEvent } from "@/testing/utils"; | ||
|
||
const mockStore = configureStore<RootState>(); | ||
const filesystem = factory.nodeFilesystem({ mount_point: "/disk-fs/path" }); | ||
const disk = factory.nodeDisk({ filesystem, partitions: [] }); | ||
const machine = factory.machineDetails({ | ||
disks: [disk], | ||
system_id: "abc123", | ||
}); | ||
const state = factory.rootState({ | ||
machine: factory.machineState({ | ||
items: [machine], | ||
statuses: factory.machineStatuses({ | ||
abc123: factory.machineStatus(), | ||
}), | ||
}), | ||
}); | ||
|
||
it("renders a delete confirmation form", () => { | ||
renderWithBrowserRouter( | ||
<DeleteFilesystem close={vi.fn()} storageDevice={disk} systemId="abc123" />, | ||
{ state } | ||
); | ||
|
||
expect( | ||
screen.getByRole("form", { name: "Delete filesystem" }) | ||
).toBeInTheDocument(); | ||
}); | ||
|
||
it("can remove a disk's filesystem", async () => { | ||
const store = mockStore(state); | ||
renderWithBrowserRouter( | ||
<DeleteFilesystem close={vi.fn()} storageDevice={disk} systemId="abc123" />, | ||
{ store } | ||
); | ||
|
||
expect( | ||
screen.getByRole("form", { name: "Delete filesystem" }) | ||
).toBeInTheDocument(); | ||
expect( | ||
screen.getByText("Are you sure you want to remove this filesystem?") | ||
).toBeInTheDocument(); | ||
await userEvent.click(screen.getByRole("button", { name: "Remove" })); | ||
const expectedAction = machineActions.deleteFilesystem({ | ||
blockDeviceId: disk.id, | ||
filesystemId: filesystem.id, | ||
systemId: machine.system_id, | ||
}); | ||
|
||
expect( | ||
store.getActions().find((action) => action.type === expectedAction.type) | ||
).toStrictEqual(expectedAction); | ||
}); |
59 changes: 59 additions & 0 deletions
59
...base/components/node/StorageTables/FilesystemsTable/DeleteFilesystem/DeleteFilesystem.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,59 @@ | ||
import { useDispatch } from "react-redux"; | ||
|
||
import ModelActionForm from "@/app/base/components/ModelActionForm"; | ||
import { actions as machineActions } from "@/app/store/machine"; | ||
import type { Machine } from "@/app/store/machine/types"; | ||
import type { Disk, Partition } from "@/app/store/types/node"; | ||
import { isDisk, isMounted } from "@/app/store/utils"; | ||
|
||
type Props = { | ||
close: () => void; | ||
systemId: Machine["system_id"]; | ||
storageDevice: Disk | Partition; | ||
}; | ||
|
||
const DeleteFilesystem = ({ close, systemId, storageDevice }: Props) => { | ||
const dispatch = useDispatch(); | ||
const deviceIsDisk = isDisk(storageDevice); | ||
const storageFs = storageDevice.filesystem; | ||
const isDiskFsDelete = deviceIsDisk && isMounted(storageFs); | ||
|
||
return ( | ||
<ModelActionForm | ||
aria-label="Delete filesystem" | ||
initialValues={{}} | ||
message={<>Are you sure you want to remove this filesystem?</>} | ||
modelType="filesystem" | ||
onCancel={close} | ||
onSaveAnalytics={{ | ||
action: `Delete ${isDiskFsDelete ? "disk" : "partition"} filesystem`, | ||
category: "Machine storage", | ||
label: "Remove", | ||
}} | ||
onSubmit={() => { | ||
dispatch(machineActions.cleanup()); | ||
if (isDiskFsDelete) { | ||
dispatch( | ||
machineActions.deleteFilesystem({ | ||
blockDeviceId: storageDevice.id, | ||
filesystemId: storageFs.id, | ||
systemId, | ||
}) | ||
); | ||
} else { | ||
dispatch( | ||
machineActions.deletePartition({ | ||
partitionId: storageDevice.id, | ||
systemId, | ||
}) | ||
); | ||
} | ||
close(); | ||
}} | ||
submitAppearance="negative" | ||
submitLabel="Remove" | ||
/> | ||
); | ||
}; | ||
|
||
export default DeleteFilesystem; |
1 change: 1 addition & 0 deletions
1
src/app/base/components/node/StorageTables/FilesystemsTable/DeleteFilesystem/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 "./DeleteFilesystem"; |
67 changes: 67 additions & 0 deletions
67
...e/StorageTables/FilesystemsTable/DeleteSpecialFilesystem/DeleteSpecialFilesystem.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,67 @@ | ||
import configureStore from "redux-mock-store"; | ||
|
||
import DeleteSpecialFilesystem from "./DeleteSpecialFilesystem"; | ||
|
||
import { actions as machineActions } from "@/app/store/machine"; | ||
import type { RootState } from "@/app/store/root/types"; | ||
import * as factory from "@/testing/factories"; | ||
import { renderWithBrowserRouter, screen, userEvent } from "@/testing/utils"; | ||
|
||
const mockStore = configureStore<RootState>(); | ||
const filesystem = factory.nodeFilesystem({ mount_point: "/disk-fs/path" }); | ||
const disk = factory.nodeDisk({ filesystem, partitions: [] }); | ||
const machine = factory.machineDetails({ | ||
disks: [disk], | ||
system_id: "abc123", | ||
}); | ||
const state = factory.rootState({ | ||
machine: factory.machineState({ | ||
items: [machine], | ||
statuses: factory.machineStatuses({ | ||
abc123: factory.machineStatus(), | ||
}), | ||
}), | ||
}); | ||
|
||
it("renders a delete confirmation form", () => { | ||
renderWithBrowserRouter( | ||
<DeleteSpecialFilesystem | ||
close={vi.fn()} | ||
mountPoint={filesystem.mount_point} | ||
systemId="abc123" | ||
/>, | ||
{ state } | ||
); | ||
|
||
expect( | ||
screen.getByRole("form", { name: "Delete special filesystem" }) | ||
).toBeInTheDocument(); | ||
}); | ||
|
||
it("can remove a special filesystem", async () => { | ||
const store = mockStore(state); | ||
renderWithBrowserRouter( | ||
<DeleteSpecialFilesystem | ||
close={vi.fn()} | ||
mountPoint={filesystem.mount_point} | ||
systemId="abc123" | ||
/>, | ||
{ store } | ||
); | ||
|
||
expect( | ||
screen.getByRole("form", { name: "Delete special filesystem" }) | ||
).toBeInTheDocument(); | ||
expect( | ||
screen.getByText("Are you sure you want to remove this special filesystem?") | ||
).toBeInTheDocument(); | ||
await userEvent.click(screen.getByRole("button", { name: "Remove" })); | ||
const expectedAction = machineActions.unmountSpecial({ | ||
mountPoint: filesystem.mount_point, | ||
systemId: machine.system_id, | ||
}); | ||
|
||
expect( | ||
store.getActions().find((action) => action.type === expectedAction.type) | ||
).toStrictEqual(expectedAction); | ||
}); |
45 changes: 45 additions & 0 deletions
45
...s/node/StorageTables/FilesystemsTable/DeleteSpecialFilesystem/DeleteSpecialFilesystem.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,45 @@ | ||
import { useDispatch } from "react-redux"; | ||
|
||
import ModelActionForm from "@/app/base/components/ModelActionForm"; | ||
import { actions as machineActions } from "@/app/store/machine"; | ||
import type { Machine } from "@/app/store/machine/types"; | ||
import type { Filesystem } from "@/app/store/types/node"; | ||
|
||
type Props = { | ||
close: () => void; | ||
mountPoint: Filesystem["mount_point"]; | ||
systemId: Machine["system_id"]; | ||
}; | ||
|
||
const DeleteSpecialFilesystem = ({ close, systemId, mountPoint }: Props) => { | ||
const dispatch = useDispatch(); | ||
|
||
return ( | ||
<ModelActionForm | ||
aria-label="Delete special filesystem" | ||
initialValues={{}} | ||
message={<>Are you sure you want to remove this special filesystem?</>} | ||
modelType="special filesystem" | ||
onCancel={close} | ||
onSaveAnalytics={{ | ||
action: "Unmount special filesystem", | ||
category: "Machine storage", | ||
label: "Remove", | ||
}} | ||
onSubmit={() => { | ||
dispatch(machineActions.cleanup()); | ||
dispatch( | ||
machineActions.unmountSpecial({ | ||
mountPoint, | ||
systemId, | ||
}) | ||
); | ||
close(); | ||
}} | ||
submitAppearance="negative" | ||
submitLabel="Remove" | ||
/> | ||
); | ||
}; | ||
|
||
export default DeleteSpecialFilesystem; |
1 change: 1 addition & 0 deletions
1
src/app/base/components/node/StorageTables/FilesystemsTable/DeleteSpecialFilesystem/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 "./DeleteSpecialFilesystem"; |
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
Oops, something went wrong.