-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/index-operation' into index-op…
…eration Signed-off-by: Hailong Cui <[email protected]> # Conflicts: # cypress/integration/indices_spec.js # public/pages/Indices/containers/Indices/Indices.tsx # public/pages/Indices/containers/IndicesActions/index.tsx
- Loading branch information
Showing
19 changed files
with
2,123 additions
and
2 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
31 changes: 31 additions & 0 deletions
31
public/pages/Indices/components/CloseIndexModal/CloseIndexModal.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,31 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React from "react"; | ||
import "@testing-library/jest-dom/extend-expect"; | ||
import { render, fireEvent } from "@testing-library/react"; | ||
import userEvent from "@testing-library/user-event"; | ||
import CloseIndexModal from "./CloseIndexModal"; | ||
|
||
describe("<CloseIndexModal /> spec", () => { | ||
it("renders the component", async () => { | ||
render(<CloseIndexModal selectedItems={[]} visible onConfirm={() => {}} onClose={() => {}} />); | ||
expect(document.body.children).toMatchSnapshot(); | ||
}); | ||
|
||
it("calls close when cancel button clicked", () => { | ||
const onClose = jest.fn(); | ||
const { getByTestId } = render(<CloseIndexModal selectedItems={[]} visible onConfirm={() => {}} onClose={onClose} />); | ||
fireEvent.click(getByTestId("Close Cancel button")); | ||
expect(onClose).toHaveBeenCalled(); | ||
}); | ||
|
||
it("Close button should be disabled unless a 'close' was input", async () => { | ||
const { getByPlaceholderText } = render(<CloseIndexModal selectedItems={[]} visible onConfirm={() => {}} onClose={() => {}} />); | ||
expect(document.querySelector(".euiButton")).toHaveAttribute("disabled"); | ||
userEvent.type(getByPlaceholderText("close"), "close"); | ||
expect(document.querySelector(".euiButton")).not.toHaveAttribute("disabled"); | ||
}); | ||
}); |
84 changes: 84 additions & 0 deletions
84
public/pages/Indices/components/CloseIndexModal/CloseIndexModal.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,84 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React, { Component } from "react"; | ||
import { | ||
EuiButton, | ||
EuiButtonEmpty, | ||
EuiFieldText, | ||
EuiModal, | ||
EuiModalBody, | ||
EuiModalFooter, | ||
EuiModalHeader, | ||
EuiModalHeaderTitle, | ||
EuiSpacer, | ||
EuiText, | ||
} from "@elastic/eui"; | ||
|
||
interface CloseIndexModalProps { | ||
selectedItems: string[]; | ||
visible: boolean; | ||
onClose: () => void; | ||
onConfirm: () => void; | ||
} | ||
|
||
export default class CloseIndexModal extends Component<CloseIndexModalProps> { | ||
state: { | ||
value: string; | ||
} = { | ||
value: "", | ||
}; | ||
componentWillReceiveProps(nextProps: CloseIndexModalProps) { | ||
if (nextProps.visible !== this.props.visible && nextProps.visible) { | ||
this.setState({ | ||
value: "", | ||
}); | ||
} | ||
} | ||
render() { | ||
const { onClose, onConfirm, visible } = this.props; | ||
if (!visible) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<EuiModal onClose={onClose}> | ||
<EuiModalHeader> | ||
<EuiModalHeaderTitle>Close indices</EuiModalHeaderTitle> | ||
</EuiModalHeader> | ||
|
||
<EuiModalBody> | ||
<div style={{ lineHeight: 1.5 }}> | ||
<p>The following index will be closed. It is not possible to index documents or to search for documents in a closed index.</p> | ||
<ul style={{ listStyleType: "disc", listStylePosition: "inside" }}> | ||
{this.props.selectedItems.map((item) => ( | ||
<li key={item}>{item}</li> | ||
))} | ||
</ul> | ||
<EuiSpacer /> | ||
<EuiText color="subdued"> | ||
To confirm your action, type <b style={{ color: "#000" }}>close</b>. | ||
</EuiText> | ||
<EuiFieldText | ||
placeholder="close" | ||
fullWidth | ||
value={this.state.value} | ||
onChange={(e) => this.setState({ value: e.target.value })} | ||
/> | ||
</div> | ||
</EuiModalBody> | ||
|
||
<EuiModalFooter> | ||
<EuiButtonEmpty data-test-subj="Close Cancel button" onClick={onClose}> | ||
Cancel | ||
</EuiButtonEmpty> | ||
<EuiButton data-test-subj="Close Confirm button" onClick={onConfirm} fill disabled={this.state.value !== "close"}> | ||
Close | ||
</EuiButton> | ||
</EuiModalFooter> | ||
</EuiModal> | ||
); | ||
} | ||
} |
142 changes: 142 additions & 0 deletions
142
public/pages/Indices/components/CloseIndexModal/__snapshots__/CloseIndexModal.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,142 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`<CloseIndexModal /> spec renders the component 1`] = ` | ||
HTMLCollection [ | ||
<div | ||
aria-hidden="true" | ||
data-aria-hidden="true" | ||
/>, | ||
<div | ||
class="euiOverlayMask euiOverlayMask--aboveHeader" | ||
> | ||
<div | ||
aria-hidden="true" | ||
data-aria-hidden="true" | ||
data-focus-guard="true" | ||
style="width: 1px; height: 0px; padding: 0px; overflow: hidden; position: fixed; top: 1px; left: 1px;" | ||
tabindex="0" | ||
/> | ||
<div | ||
data-focus-lock-disabled="false" | ||
> | ||
<div | ||
class="euiModal euiModal--maxWidth-default" | ||
tabindex="0" | ||
> | ||
<button | ||
aria-label="Closes this modal window" | ||
class="euiButtonIcon euiButtonIcon--text euiButtonIcon--empty euiButtonIcon--xSmall euiModal__closeIcon" | ||
type="button" | ||
> | ||
EuiIconMock | ||
</button> | ||
<div | ||
class="euiModal__flex" | ||
> | ||
<div | ||
class="euiModalHeader" | ||
> | ||
<div | ||
class="euiModalHeader__title" | ||
> | ||
Close indices | ||
</div> | ||
</div> | ||
<div | ||
class="euiModalBody" | ||
> | ||
<div | ||
class="euiModalBody__overflow" | ||
> | ||
<div | ||
style="line-height: 1.5;" | ||
> | ||
<p> | ||
The following index will be closed. It is not possible to index documents or to search for documents in a closed index. | ||
</p> | ||
<ul | ||
style="list-style-type: disc; list-style-position: inside;" | ||
/> | ||
<div | ||
class="euiSpacer euiSpacer--l" | ||
/> | ||
<div | ||
class="euiText euiText--medium" | ||
> | ||
<div | ||
class="euiTextColor euiTextColor--subdued" | ||
> | ||
To confirm your action, type | ||
<b | ||
style="color: rgb(0, 0, 0);" | ||
> | ||
close | ||
</b> | ||
. | ||
</div> | ||
</div> | ||
<div | ||
class="euiFormControlLayout euiFormControlLayout--fullWidth" | ||
> | ||
<div | ||
class="euiFormControlLayout__childrenWrapper" | ||
> | ||
<input | ||
class="euiFieldText euiFieldText--fullWidth" | ||
placeholder="close" | ||
type="text" | ||
value="" | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<div | ||
class="euiModalFooter" | ||
> | ||
<button | ||
class="euiButtonEmpty euiButtonEmpty--primary" | ||
data-test-subj="Close Cancel button" | ||
type="button" | ||
> | ||
<span | ||
class="euiButtonContent euiButtonEmpty__content" | ||
> | ||
<span | ||
class="euiButtonEmpty__text" | ||
> | ||
Cancel | ||
</span> | ||
</span> | ||
</button> | ||
<button | ||
class="euiButton euiButton--primary euiButton--fill euiButton-isDisabled" | ||
data-test-subj="Close Confirm button" | ||
disabled="" | ||
type="button" | ||
> | ||
<span | ||
class="euiButtonContent euiButton__content" | ||
> | ||
<span | ||
class="euiButton__text" | ||
> | ||
Close | ||
</span> | ||
</span> | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<div | ||
aria-hidden="true" | ||
data-aria-hidden="true" | ||
data-focus-guard="true" | ||
style="width: 1px; height: 0px; padding: 0px; overflow: hidden; position: fixed; top: 1px; left: 1px;" | ||
tabindex="0" | ||
/> | ||
</div>, | ||
] | ||
`; |
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,8 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import CloseIndexModal from "./CloseIndexModal"; | ||
|
||
export default CloseIndexModal; |
Oops, something went wrong.