Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/index-operation' into index-op…
Browse files Browse the repository at this point in the history
…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
Hailong-am committed Nov 9, 2022
2 parents 2ac9f83 + 8c9edb2 commit 8b1a583
Show file tree
Hide file tree
Showing 19 changed files with 2,123 additions and 2 deletions.
115 changes: 115 additions & 0 deletions cypress/integration/indices_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,121 @@ describe("Indices", () => {
});
});

describe("can shrink an index", () => {
before(() => {
cy.deleteAllIndices();
cy.createIndex(SAMPLE_INDEX, null, {
settings: { "index.blocks.write": true, "index.number_of_shards": 2, "index.number_of_replicas": 0 },
});
});

it("successfully shrink an index", () => {
// Type in SAMPLE_INDEX in search input
cy.get(`input[type="search"]`).focus().type(SAMPLE_INDEX);

// Confirm we have our initial index
cy.contains(SAMPLE_INDEX);

cy.get('[data-test-subj="More Action"]').click();
// Shrink btn should be disabled if no items selected
cy.get('[data-test-subj="Shrink Action"]').should("have.class", "euiContextMenuItem-isDisabled");

// Select an index
cy.get(`[data-test-subj="checkboxSelectRow-${SAMPLE_INDEX}"]`).check({ force: true });

cy.get('[data-test-subj="More Action"]').click();
// Shrink btn should be enabled
cy.get('[data-test-subj="Shrink Action"]').should("exist").should("not.have.class", "euiContextMenuItem-isDisabled").click();

// Check for Shrink index flyout
cy.contains("Shrink index");

// Enter target index name
cy.get(`input[data-test-subj="targetIndexNameInput"]`).type(`${SAMPLE_INDEX}_shrunken`);

// Click shrink index button
cy.get("button").contains("Shrink index").click({ force: true });

// Check for success toast
cy.contains("Shrink index successfully");
});
});

describe("can close and open an index", () => {
before(() => {
cy.deleteAllIndices();
cy.createIndex(SAMPLE_INDEX);
});

it("successfully close an index", () => {
cy.contains(SAMPLE_INDEX);

cy.get('[data-test-subj="More Action"]').click();
// Close btn should be disabled if no items selected
cy.get('[data-test-subj="Close Action"]').should("have.class", "euiContextMenuItem-isDisabled");

// Select an index
cy.get(`[data-test-subj="checkboxSelectRow-${SAMPLE_INDEX}"]`).check({ force: true });

cy.get('[data-test-subj="More Action"]').click();
// Close btn should be enabled
cy.get('[data-test-subj="Close Action"]').should("exist").should("not.have.class", "euiContextMenuItem-isDisabled").click();

// Check for close index modal
cy.contains("Close indices");

// Close confirm button should be disabled
cy.get('[data-test-subj="Close Confirm button"]').should("have.class", "euiButton-isDisabled");
// type close
cy.get('[placeholder="close"]').type("close");
cy.get('[data-test-subj="Close Confirm button"]').should("not.have.class", "euiContextMenuItem-isDisabled");

// Click close confirm button
cy.get('[data-test-subj="Close Confirm button"]').click();

// Check for success toast
cy.contains("Close index successfully");

// Confirm the index is closed
cy.get(`input[type="search"]`).focus().type(SAMPLE_INDEX);
cy.get("tbody > tr").should(($tr) => {
expect($tr, "1 row").to.have.length(1);
expect($tr, "item").to.contain("close");
});
});

it("successfully open an index", () => {
// Confirm we have our initial index
cy.contains(SAMPLE_INDEX);

cy.get('[data-test-subj="More Action"]').click();
// Open btn should be disabled if no items selected
cy.get('[data-test-subj="Open Action"]').should("have.class", "euiContextMenuItem-isDisabled");

// Select an index
cy.get(`[data-test-subj="checkboxSelectRow-${SAMPLE_INDEX}"]`).check({ force: true });

cy.get('[data-test-subj="More Action"]').click();
// Open btn should be enabled
cy.get('[data-test-subj="Open Action"]').should("exist").should("not.have.class", "euiContextMenuItem-isDisabled").click();

// Check for open index modal
cy.contains("Open indices");

cy.get('[data-test-subj="Open Confirm button"]').click();

// Check for success toast
cy.contains("Open index successfully");

// Confirm the index is open
cy.get(`input[type="search"]`).focus().type(SAMPLE_INDEX);
cy.get("tbody > tr").should(($tr) => {
expect($tr, "1 row").to.have.length(1);
expect($tr, "item").to.contain("open");
});
});
});

describe("can perform reindex", () => {
before(() => {
cy.deleteAllIndices();
Expand Down
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");
});
});
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>
);
}
}
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>,
]
`;
8 changes: 8 additions & 0 deletions public/pages/Indices/components/CloseIndexModal/index.ts
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;
Loading

0 comments on commit 8b1a583

Please sign in to comment.