-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(HMS-2994): add delete confirmation modal
This change introduce the delete confirmation modal dialog. This dialog will show up when we click on the kebab menu of the list domains view to delete the item, or when we click on the kebab menu from the detail view of the domain to delete the domain that is being displayed. In both cases, the deletion confirmation modal is showed up, and when we press Delete button the item is eventually deleted from the database. Making click on the modal cross icon or cancel link will dismiss the deletion confirmation modal with no effect on the data stored. Signed-off-by: Alejandro Visiedo <[email protected]>
- Loading branch information
Showing
5 changed files
with
145 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
@import '~@redhat-cloud-services/frontend-components-utilities/styles/variables'; |
50 changes: 50 additions & 0 deletions
50
src/Components/ConfirmDeleteDomain/ConfirmDeleteDomain.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,50 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import ConfirmDeleteDomain from './ConfirmDeleteDomain'; | ||
import '@testing-library/jest-dom'; | ||
import { Domain } from '../../Api'; | ||
|
||
const domain: Domain = { | ||
domain_name: 'mydomain.test', | ||
} as unknown as Domain; | ||
|
||
test('expect empty when isOpen is false', () => { | ||
const root = render(<ConfirmDeleteDomain domain={domain} isOpen={false} />); | ||
expect(root.container).toBeEmptyDOMElement(); | ||
}); | ||
|
||
test('expect modal displayed', () => { | ||
render(<ConfirmDeleteDomain domain={domain} isOpen={true} />); | ||
expect(screen.getByRole('heading')).toHaveTextContent(/^Warning alert:Delete identity domain registration\?$/); | ||
expect(screen.getByRole('button', { name: 'Close' })).toHaveTextContent(/^$/); | ||
expect(screen.getByRole('button', { name: 'Delete' })).toHaveTextContent(/^Delete$/); | ||
expect(screen.getByRole('button', { name: 'Cancel' })).toHaveTextContent(/^Cancel$/); | ||
}); | ||
|
||
test('expect handler onDelete to be called', () => { | ||
// given | ||
const confirmHandler = jest.fn(); | ||
const cancelHandler = jest.fn(); | ||
render(<ConfirmDeleteDomain domain={domain} isOpen={true} onDelete={confirmHandler} onCancel={cancelHandler} />); | ||
|
||
// when the OK button is clicked | ||
screen.getByRole('button', { name: 'Delete' }).click(); | ||
|
||
// then the confirmHandler should be called with the domain as argument and cancelHandler should not | ||
expect(confirmHandler).toBeCalledWith(domain); | ||
expect(cancelHandler).toBeCalledTimes(0); | ||
}); | ||
|
||
test('expect handler onCancel to be called', () => { | ||
// given | ||
const confirmHandler = jest.fn(); | ||
const cancelHandler = jest.fn(); | ||
render(<ConfirmDeleteDomain domain={domain} isOpen={true} onDelete={confirmHandler} onCancel={cancelHandler} />); | ||
|
||
// when the OK button is clicked | ||
screen.getByRole('button', { name: 'Cancel' }).click(); | ||
|
||
// then the confirmHandler should be called with the domain as argument and cancelHandler should not | ||
expect(cancelHandler).toBeCalledTimes(1); | ||
expect(confirmHandler).toBeCalledTimes(0); | ||
}); |
44 changes: 44 additions & 0 deletions
44
src/Components/ConfirmDeleteDomain/ConfirmDeleteDomain.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,44 @@ | ||
import { Button, Modal } from '@patternfly/react-core'; | ||
import './ConfirmDeleteDomain.scss'; | ||
import React from 'react'; | ||
import { Domain } from '../../Api/api'; | ||
|
||
interface ConfirmDeleteDomainProps { | ||
domain?: Domain; | ||
isOpen?: boolean; | ||
onDelete?: (domain?: Domain) => void; | ||
onCancel?: () => void; | ||
} | ||
|
||
/** | ||
* Modal dialog to confirm a domain deletion. | ||
* | ||
* @param props the props given by the smart component. | ||
*/ | ||
const ConfirmDeleteDomain: React.FC<ConfirmDeleteDomainProps> = (props) => { | ||
const onDeleteWrapper = () => { | ||
props.onDelete && props.onDelete(props.domain); | ||
}; | ||
return ( | ||
<Modal | ||
isOpen={props.isOpen} | ||
titleIconVariant={'warning'} | ||
variant="small" | ||
title="Delete identity domain registration?" | ||
ouiaId="ModalConfirmDeletion" | ||
onClose={props.onCancel} | ||
actions={[ | ||
<Button key="delete" variant="danger" onClick={onDeleteWrapper} ouiaId="ButtonModalConfirmDeletionDelete"> | ||
Delete | ||
</Button>, | ||
<Button key="cancel" variant="link" onClick={props.onCancel} ouiaId="ButtonModalConfirmDeletionCancel"> | ||
Cancel | ||
</Button>, | ||
]} | ||
> | ||
No new host enrollment from HCC will be allowed on <b>{props.domain?.title || ''}</b> domain after registration deletion. | ||
</Modal> | ||
); | ||
}; | ||
|
||
export default ConfirmDeleteDomain; |
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