-
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: move SSL key delete form to side panel (#5341)
- Loading branch information
1 parent
b674e98
commit 44d7ffb
Showing
7 changed files
with
154 additions
and
177 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
81 changes: 81 additions & 0 deletions
81
src/app/preferences/views/SSLKeys/DeleteSSLKey/DeleteSSLKey.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,81 @@ | ||
import configureStore from "redux-mock-store"; | ||
|
||
import DeleteSSLKey from "./DeleteSSLKey"; | ||
|
||
import { Label as SSLKeyListLabels } from "@/app/preferences/views/SSLKeys/SSLKeyList/SSLKeyList"; | ||
import type { RootState } from "@/app/store/root/types"; | ||
import { | ||
sslKey as sslKeyFactory, | ||
sslKeyState as sslKeyStateFactory, | ||
rootState as rootStateFactory, | ||
} from "@/testing/factories"; | ||
import { screen, renderWithBrowserRouter, userEvent } from "@/testing/utils"; | ||
|
||
const mockStore = configureStore<RootState>(); | ||
|
||
let state: RootState; | ||
|
||
beforeEach(() => { | ||
state = rootStateFactory({ | ||
sslkey: sslKeyStateFactory({ | ||
loading: false, | ||
loaded: true, | ||
items: [ | ||
sslKeyFactory({ | ||
id: 1, | ||
key: "ssh-rsa aabb", | ||
}), | ||
sslKeyFactory({ | ||
id: 2, | ||
key: "ssh-rsa ccdd", | ||
}), | ||
sslKeyFactory({ | ||
id: 3, | ||
key: "ssh-rsa eeff", | ||
}), | ||
sslKeyFactory({ | ||
id: 4, | ||
key: "ssh-rsa gghh", | ||
}), | ||
sslKeyFactory({ id: 5, key: "ssh-rsa gghh" }), | ||
], | ||
}), | ||
}); | ||
}); | ||
|
||
it("can show a delete confirmation", () => { | ||
renderWithBrowserRouter(<DeleteSSLKey />, { | ||
route: "/account/prefs/ssl-keys/1/delete", | ||
routePattern: "/account/prefs/ssl-keys/:id/delete", | ||
state, | ||
}); | ||
expect(screen.getByRole("form", { name: SSLKeyListLabels.DeleteConfirm })); | ||
expect( | ||
screen.getByText(/Are you sure you want to delete this SSL key?/i) | ||
).toBeInTheDocument(); | ||
}); | ||
|
||
it("can delete an SSL key", async () => { | ||
const store = mockStore(state); | ||
renderWithBrowserRouter(<DeleteSSLKey />, { | ||
route: "/account/prefs/ssl-keys/1/delete", | ||
routePattern: "/account/prefs/ssl-keys/:id/delete", | ||
store, | ||
}); | ||
|
||
await userEvent.click(screen.getByRole("button", { name: "Delete" })); | ||
expect( | ||
store.getActions().find((action) => action.type === "sslkey/delete") | ||
).toEqual({ | ||
type: "sslkey/delete", | ||
payload: { | ||
params: { | ||
id: 1, | ||
}, | ||
}, | ||
meta: { | ||
model: "sslkey", | ||
method: "delete", | ||
}, | ||
}); | ||
}); |
45 changes: 45 additions & 0 deletions
45
src/app/preferences/views/SSLKeys/DeleteSSLKey/DeleteSSLKey.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 { useOnEscapePressed } from "@canonical/react-components"; | ||
import { useDispatch, useSelector } from "react-redux"; | ||
import { useNavigate } from "react-router-dom-v5-compat"; | ||
|
||
import ModelActionForm from "@/app/base/components/ModelActionForm"; | ||
import { useAddMessage, useGetURLId } from "@/app/base/hooks"; | ||
import urls from "@/app/preferences/urls"; | ||
import { Label } from "@/app/preferences/views/SSLKeys/SSLKeyList/SSLKeyList"; | ||
import { actions as sslkeyActions } from "@/app/store/sslkey"; | ||
import sslkeySelectors from "@/app/store/sslkey/selectors"; | ||
import { isId } from "@/app/utils"; | ||
|
||
const DeleteSSLKey = () => { | ||
const id = useGetURLId("id"); | ||
const navigate = useNavigate(); | ||
const dispatch = useDispatch(); | ||
const saved = useSelector(sslkeySelectors.saved); | ||
const saving = useSelector(sslkeySelectors.saving); | ||
const onClose = () => navigate({ pathname: urls.sslKeys.index }); | ||
useOnEscapePressed(() => onClose()); | ||
useAddMessage(saved, sslkeyActions.cleanup, "SSL key removed successfully."); | ||
|
||
if (!isId(id)) { | ||
return <h4>SSL key not found</h4>; | ||
} | ||
|
||
return ( | ||
<ModelActionForm | ||
aria-label={Label.DeleteConfirm} | ||
initialValues={{}} | ||
modelType="SSL key" | ||
onCancel={onClose} | ||
onSubmit={() => { | ||
dispatch(sslkeyActions.delete(id)); | ||
}} | ||
saved={saved} | ||
savedRedirect={urls.sslKeys.index} | ||
saving={saving} | ||
submitAppearance="negative" | ||
submitLabel="Delete" | ||
/> | ||
); | ||
}; | ||
|
||
export default DeleteSSLKey; |
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 "./DeleteSSLKey"; |
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.