forked from opensearch-project/dashboards-maps
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds error modal and lint fixes (opensearch-project#13)
* adds error modal and fixes lint Signed-off-by: Shivam Dhar <[email protected]> Co-authored-by: Shivam Dhar <[email protected]>
- Loading branch information
1 parent
50317b9
commit 0b3296c
Showing
15 changed files
with
235 additions
and
67 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
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
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
31 changes: 31 additions & 0 deletions
31
src/plugins/custom_import_map/public/components/__snapshots__/show_error_modal.test.tsx.snap
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,31 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`display error modal renders the error modal based on the props passed 1`] = ` | ||
<div | ||
aria-label="showModalOption" | ||
data-testid="showModalOption" | ||
id="showModalOption" | ||
> | ||
<button | ||
className="euiButton euiButton--primary" | ||
disabled={false} | ||
onClick={[Function]} | ||
style={ | ||
Object { | ||
"minWidth": undefined, | ||
} | ||
} | ||
type="button" | ||
> | ||
<span | ||
className="euiButtonContent euiButton__content" | ||
> | ||
<span | ||
className="euiButton__text" | ||
> | ||
testButtonText | ||
</span> | ||
</span> | ||
</button> | ||
</div> | ||
`; |
35 changes: 35 additions & 0 deletions
35
src/plugins/custom_import_map/public/components/show_error_modal.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,35 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import * as React from 'react'; | ||
import { ShowErrorModal } from './show_error_modal'; | ||
import renderer, { act } from 'react-test-renderer'; | ||
import { fireEvent } from '@testing-library/dom'; | ||
import { screen, render } from '@testing-library/react'; | ||
|
||
describe('display error modal', () => { | ||
const props = { | ||
modalTitle: 'testModalTitle', | ||
modalBody: 'testModalBody', | ||
buttonText: 'testButtonText', | ||
}; | ||
|
||
it('renders the error modal based on the props passed', async () => { | ||
let tree; | ||
await act(async () => { | ||
tree = renderer.create(<ShowErrorModal {...props} />); | ||
}); | ||
expect(tree.toJSON().props.id).toBe('showModalOption'); | ||
expect(tree.toJSON()).toMatchSnapshot(); | ||
}); | ||
|
||
it('renders the error modal when showModal button is clicked', () => { | ||
render(<ShowErrorModal {...props} />); | ||
const button = screen.getByRole('button'); | ||
fireEvent.click(button); | ||
const closeButton = screen.getByTestId('closeModal'); | ||
fireEvent.click(closeButton); | ||
}); | ||
}); |
67 changes: 67 additions & 0 deletions
67
src/plugins/custom_import_map/public/components/show_error_modal.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 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React, { useState } from 'react'; | ||
import { | ||
EuiButton, | ||
EuiModal, | ||
EuiModalBody, | ||
EuiModalFooter, | ||
EuiModalHeader, | ||
EuiModalHeaderTitle, | ||
EuiCodeBlock, | ||
} from '@elastic/eui'; | ||
|
||
export interface ShowErrorModalProps { | ||
modalTitle: string; | ||
modalBody: string; | ||
buttonText: string; | ||
} | ||
|
||
const ShowErrorModal = (props: ShowErrorModalProps) => { | ||
const [isModalVisible, setIsModalVisible] = useState(false); | ||
|
||
const closeModal = () => setIsModalVisible(false); | ||
const showModal = () => setIsModalVisible(true); | ||
|
||
let modal; | ||
|
||
if (isModalVisible) { | ||
modal = ( | ||
<EuiModal onClose={closeModal}> | ||
<EuiModalHeader> | ||
<EuiModalHeaderTitle> | ||
<h1>{props.modalTitle}</h1> | ||
</EuiModalHeaderTitle> | ||
</EuiModalHeader> | ||
|
||
<EuiModalBody> | ||
<EuiCodeBlock isCopyable>{props.modalBody}</EuiCodeBlock> | ||
</EuiModalBody> | ||
|
||
<EuiModalFooter> | ||
<EuiButton | ||
id="closeModal" | ||
aria-label="closeModal" | ||
data-testid="closeModal" | ||
onClick={closeModal} | ||
fill | ||
> | ||
Close | ||
</EuiButton> | ||
</EuiModalFooter> | ||
</EuiModal> | ||
); | ||
} | ||
|
||
return ( | ||
<div id="showModalOption" aria-label="showModalOption" data-testid="showModalOption"> | ||
<EuiButton onClick={showModal}>{props.buttonText}</EuiButton> | ||
{modal} | ||
</div> | ||
); | ||
}; | ||
|
||
export { ShowErrorModal }; |
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.