-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build a signing key table with modals
- Loading branch information
Showing
12 changed files
with
567 additions
and
8 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
58 changes: 58 additions & 0 deletions
58
static/js/brand-store/components/SigningKeys/DisableModal.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,58 @@ | ||
import React from "react"; | ||
import { Modal, Button } from "@canonical/react-components"; | ||
import { useRecoilValue } from "recoil"; | ||
|
||
import { filteredSigningKeysListState } from "../../selectors"; | ||
|
||
import type { SigningKey } from "../../types/shared"; | ||
|
||
type Props = { | ||
disableModalOpen: boolean; | ||
setDisableModalOpen: Function; | ||
handleDisable: Function; | ||
isDeleting: boolean; | ||
signingKey: SigningKey; | ||
}; | ||
|
||
function DisableModal({ | ||
disableModalOpen, | ||
setDisableModalOpen, | ||
handleDisable, | ||
isDeleting, | ||
signingKey, | ||
}: Props) { | ||
|
||
const closeHandler = () => setDisableModalOpen(false); | ||
const signingKeysList = useRecoilValue<Array<SigningKey>>(filteredSigningKeysListState); | ||
|
||
if (!disableModalOpen) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<Modal | ||
close={closeHandler} | ||
title="Confirm disable" | ||
buttonRow={ | ||
<> | ||
<Button dense className="u-no-margin--bottom" onClick={closeHandler}> | ||
Cancel | ||
</Button> | ||
|
||
<Button | ||
dense | ||
className="p-button--negative u-no-margin--bottom" | ||
onClick={() => handleDisable()} | ||
disabled={isDeleting} | ||
> | ||
Disable | ||
</Button> | ||
</> | ||
} | ||
> | ||
<p>{`Warning: This will permanently disable the signing key ${signingKey.name}.`}</p> | ||
</Modal> | ||
); | ||
} | ||
|
||
export default DisableModal; |
63 changes: 63 additions & 0 deletions
63
static/js/brand-store/components/SigningKeys/ModelsModal.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,63 @@ | ||
import React from "react"; | ||
import { Modal, Icon } from "@canonical/react-components"; | ||
import { useRecoilValue } from "recoil"; | ||
|
||
import { filteredModelsListState, filteredPoliciesListState } from "../../selectors"; | ||
|
||
import type { SigningKey, Model, Policy } from "../../types/shared"; | ||
|
||
type Props = { | ||
modelsModalOpen: boolean; | ||
setModelsModalOpen: Function; | ||
signingKey: SigningKey; | ||
}; | ||
|
||
function ModelsModal({ | ||
modelsModalOpen, | ||
setModelsModalOpen, | ||
signingKey, | ||
}: Props) { | ||
|
||
const closeHandler = () => setModelsModalOpen(false); | ||
const filteredModels = useRecoilValue<Array<Model>>(filteredModelsListState); | ||
const filteredPolicies = useRecoilValue<Array<Policy>>(filteredPoliciesListState); | ||
|
||
if (!modelsModalOpen) { | ||
return null; | ||
} | ||
|
||
const relatedModels = filteredModels.filter((model) => | ||
signingKey.models.includes(model.name) | ||
); | ||
|
||
const relatedPolicies = filteredPolicies.filter((policy) => | ||
signingKey.models.includes(policy["model-name"]) | ||
); | ||
|
||
return ( | ||
<Modal | ||
title={ | ||
<React.Fragment> | ||
<Icon name="warning" /> | ||
{` Deactivate ${signingKey.name}`} | ||
</React.Fragment>} | ||
close={closeHandler} | ||
> | ||
<h3>{signingKey.name} is used in :</h3> | ||
<ul> | ||
{relatedModels.map((model) => { | ||
const relatedPolicy = relatedPolicies.find((policy) => policy["model-name"] === model.name); | ||
return ( | ||
<React.Fragment key={model.name}> | ||
<li>{model.name}</li> | ||
<li>{relatedPolicy ? relatedPolicy["created-by"] : "No policy found"}</li> | ||
</React.Fragment> | ||
); | ||
})} | ||
</ul> | ||
<p>You need to update each policy with a new key first to be able to delete this one.</p> | ||
</Modal> | ||
); | ||
} | ||
|
||
export default ModelsModal; |
47 changes: 47 additions & 0 deletions
47
static/js/brand-store/components/SigningKeys/SigningKeys.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,47 @@ | ||
import React from "react"; | ||
import { BrowserRouter } from "react-router-dom"; | ||
import { RecoilRoot } from "recoil"; | ||
import { QueryClient, QueryClientProvider } from "react-query"; | ||
import { render, screen } from "@testing-library/react"; | ||
import userEvent from "@testing-library/user-event"; | ||
|
||
import "@testing-library/jest-dom"; | ||
|
||
import SigningKeys from "./SigningKeys"; | ||
|
||
let mockFilterQuery = "signing-key-1"; | ||
|
||
jest.mock("react-router-dom", () => { | ||
return { | ||
...jest.requireActual("react-router-dom"), | ||
useSearchParams: () => [new URLSearchParams({ filter: mockFilterQuery })], | ||
}; | ||
}); | ||
|
||
const queryClient = new QueryClient({ | ||
defaultOptions: { | ||
queries: { | ||
refetchOnWindowFocus: false, | ||
refetchOnReconnect: false, | ||
}, | ||
}, | ||
}); | ||
|
||
function renderComponent() { | ||
return render( | ||
<RecoilRoot> | ||
<BrowserRouter> | ||
<QueryClientProvider client={queryClient}> | ||
<SigningKeys /> | ||
</QueryClientProvider> | ||
</BrowserRouter> | ||
</RecoilRoot> | ||
); | ||
} | ||
|
||
describe("Models", () => { | ||
it("displays a table of models", () => { | ||
renderComponent(); | ||
expect(screen.getByTestId("signing-keys-table")).toBeInTheDocument(); | ||
}); | ||
}); |
96 changes: 92 additions & 4 deletions
96
static/js/brand-store/components/SigningKeys/SigningKeys.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
Oops, something went wrong.