forked from opensearch-project/observability
-
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.
Make common delete modal for components (opensearch-project#766)
Signed-off-by: Eugene Lee <[email protected]>
- Loading branch information
1 parent
0d253e8
commit abb19e0
Showing
10 changed files
with
105 additions
and
80 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
79 changes: 79 additions & 0 deletions
79
dashboards-observability/public/components/common/helpers/delete_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,79 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React, { useState } from 'react'; | ||
import { | ||
EuiOverlayMask, | ||
EuiModal, | ||
EuiButton, | ||
EuiButtonEmpty, | ||
EuiFieldText, | ||
EuiForm, | ||
EuiFormRow, | ||
EuiModalBody, | ||
EuiModalFooter, | ||
EuiModalHeader, | ||
EuiModalHeaderTitle, | ||
EuiSpacer, | ||
EuiText, | ||
} from '@elastic/eui'; | ||
|
||
export const DeleteModal = ({ | ||
onCancel, | ||
onConfirm, | ||
title, | ||
message, | ||
}: { | ||
onCancel: ( | ||
event?: React.KeyboardEvent<HTMLDivElement> | React.MouseEvent<HTMLButtonElement, MouseEvent> | ||
) => void; | ||
onConfirm: (event?: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void; | ||
title: string; | ||
message: string; | ||
}) => { | ||
const [value, setValue] = useState(''); | ||
const onChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
setValue(e.target.value); | ||
}; | ||
return ( | ||
<EuiOverlayMask> | ||
<EuiModal onClose={onCancel} initialFocus="[name=input]"> | ||
<EuiModalHeader> | ||
<EuiModalHeaderTitle>{title}</EuiModalHeaderTitle> | ||
</EuiModalHeader> | ||
|
||
<EuiModalBody> | ||
<EuiText>{message}</EuiText> | ||
<EuiText>The action cannot be undone.</EuiText> | ||
<EuiSpacer /> | ||
<EuiForm> | ||
<EuiFormRow label={'To confirm deletion, enter "delete" in the text field'}> | ||
<EuiFieldText | ||
name="input" | ||
placeholder="delete" | ||
value={value} | ||
onChange={(e) => onChange(e)} | ||
data-test-subj="popoverModal__deleteTextInput" | ||
/> | ||
</EuiFormRow> | ||
</EuiForm> | ||
</EuiModalBody> | ||
|
||
<EuiModalFooter> | ||
<EuiButtonEmpty onClick={onCancel}>Cancel</EuiButtonEmpty> | ||
<EuiButton | ||
onClick={() => onConfirm()} | ||
color="danger" | ||
fill | ||
disabled={value !== 'delete'} | ||
data-test-subj="popoverModal__deleteButton" | ||
> | ||
Delete | ||
</EuiButton> | ||
</EuiModalFooter> | ||
</EuiModal> | ||
</EuiOverlayMask> | ||
); | ||
}; |
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
2 changes: 1 addition & 1 deletion
2
...ic/components/custom_panels/helpers/__tests__/__snapshots__/modal_container.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
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