Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge alias management to index-operation-common #510

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 119 additions & 0 deletions cypress/integration/aliases.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
import { PLUGIN_NAME } from "../support/constants";

const SAMPLE_INDEX_PREFIX = "index-for-alias-test";
const SAMPLE_ALIAS_PREFIX = "alias-for-test";
const CREATE_ALIAS = "create-alias";
const EDIT_INDEX = "index-edit-index-for-alias-test";

describe("Aliases", () => {
before(() => {
// Set welcome screen tracking to false
localStorage.setItem("home:welcome:show", "false");
cy.deleteAllIndices();
for (let i = 0; i < 11; i++) {
cy.createIndex(`${SAMPLE_INDEX_PREFIX}-${i}`, null);
}
cy.createIndex(EDIT_INDEX, null);
for (let i = 0; i < 30; i++) {
cy.addAlias(`${SAMPLE_ALIAS_PREFIX}-${i}`, `${SAMPLE_INDEX_PREFIX}-${i % 11}`);
}
cy.removeAlias(`${SAMPLE_ALIAS_PREFIX}-0`);
cy.addAlias(`${SAMPLE_ALIAS_PREFIX}-0`, `${SAMPLE_INDEX_PREFIX}-*`);
});

beforeEach(() => {
// Visit ISM OSD
cy.visit(`${Cypress.env("opensearch_dashboards")}/app/${PLUGIN_NAME}#/aliases`);

// Common text to wait for to confirm page loaded, give up to 60 seconds for initial load
cy.contains("Rows per page", { timeout: 60000 });
});

describe("can be searched / sorted / paginated", () => {
it("successfully", () => {
cy.get('[data-test-subj="pagination-button-1"]').should("exist");
cy.get('[placeholder="Search..."]').type("alias-for-test-0{enter}");
cy.contains("alias-for-test-0");
cy.get(".euiTableRow").should("have.length", 1);
cy.get('[data-test-subj="comboBoxSearchInput"]').type("closed{enter}");

cy.contains("You have no aliases.");
});
});

describe("shows more flyout", () => {
it("successfully", () => {
cy.get('[placeholder="Search..."]').type("alias-for-test-0{enter}");
cy.contains("alias-for-test-0");
cy.get(".euiTableRow").should("have.length", 1);
cy.get('.euiTableRowCell [data-test-subj="8 more"]')
.click()
.get('[data-test-subj="indices-table"] .euiTableRow')
.should("have.length", 10);
});
});

describe("can create a alias with wildcard and specific name", () => {
it("successfully", () => {
cy.get('[data-test-subj="Create AliasButton"]').click();
cy.get('[data-test-subj="form-name-alias"]').type(CREATE_ALIAS);
cy.get('[data-test-subj="form-name-indexArray"] [data-test-subj="comboBoxSearchInput"]').type(
`${EDIT_INDEX}{enter}${SAMPLE_INDEX_PREFIX}-*{enter}`
);
cy.get(".euiFlyoutFooter .euiButton--fill").click().get('[data-test-subj="9 more"]').should("exist");
});
});

describe("can edit / delete a alias", () => {
it("successfully", () => {
cy.get('[placeholder="Search..."]').type(`${SAMPLE_ALIAS_PREFIX}-0{enter}`);
cy.contains(`${SAMPLE_ALIAS_PREFIX}-0`);
cy.get('[data-test-subj="moreAction"] button')
.click()
.get('[data-test-subj="editAction"]')
.should("be.disabled")
.get(`#_selection_column_${SAMPLE_ALIAS_PREFIX}-0-checkbox`)
.click()
.get('[data-test-subj="moreAction"] button')
.click()
.get('[data-test-subj="editAction"]')
.click()
.get('[data-test-subj="form-name-indexArray"] [data-test-subj="comboBoxInput"]')
.click()
.type(`${EDIT_INDEX}{enter}`)
.get(`[title="${SAMPLE_INDEX_PREFIX}-0"] button`)
.click()
.get(`[title="${SAMPLE_INDEX_PREFIX}-1"] button`)
.click()
.get(".euiFlyoutFooter .euiButton--fill")
.click()
.end();

cy.get('[data-test-subj="7 more"]').should("exist");

cy.get('[data-test-subj="moreAction"] button').click().get('[data-test-subj="deleteAction"]').click();
// The confirm button should be disabled
cy.get('[data-test-subj="deleteConfirmButton"]').should("be.disabled");
// type delete
cy.wait(500).get('[data-test-subj="deleteInput"]').type("delete");
cy.get('[data-test-subj="deleteConfirmButton"]').should("not.be.disabled");
// click to delete
cy.get('[data-test-subj="deleteConfirmButton"]').click();
// the alias should not exist
cy.wait(500);
cy.get(`#_selection_column_${SAMPLE_ALIAS_PREFIX}-0-checkbox`).should("not.exist");
});
});

after(() => {
cy.deleteAllIndices();
for (let i = 0; i < 30; i++) {
cy.removeAlias(`${SAMPLE_ALIAS_PREFIX}-${i}`);
}
cy.removeAlias(CREATE_ALIAS);
});
});
92 changes: 84 additions & 8 deletions models/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,70 @@ export interface ManagedIndexMetaData {
info?: object;
}

export type MappingsPropertiesObject = Record<
string,
{
type: string;
properties?: MappingsPropertiesObject;
}
>;

export type MappingsProperties = {
fieldName: string;
type: string;
path?: string;
analyzer?: string;
properties?: MappingsProperties;
}[];

export interface IndexItem {
index: string;
indexUuid?: string;
data_stream: string | null;
settings?: {
index?: {
number_of_shards?: number;
number_of_replicas?: number;
creation_date?: string;
[key: string]: any;
};
"index.number_of_shards"?: number;
"index.number_of_replicas"?: number;
"index.refresh_interval"?: string;
[key: string]: any;
};
aliases?: Record<string, {}>;
mappings?: {
properties?: MappingsProperties;
[key: string]: any;
};
}

export interface IndexItemRemote extends Omit<IndexItem, "mappings"> {
mappings?: {
properties?: MappingsPropertiesObject;
};
}

interface ITemplateExtras {
name: string;
data_stream?: {};
version: number;
priority: number;
index_patterns: string[];
}

export interface TemplateItem extends ITemplateExtras {
template: Pick<IndexItem, "aliases" | "mappings" | "settings">;
}
export interface TemplateItemRemote extends ITemplateExtras {
template: Pick<IndexItemRemote, "aliases" | "mappings" | "settings">;
}

/**
* ManagedIndex item shown in the Managed Indices table
*/
export interface ManagedIndexItem {
index: string;
indexUuid: string;
export interface ManagedIndexItem extends IndexItem {
dataStream: string | null;
policyId: string;
policySeqNo: number;
Expand All @@ -38,10 +96,6 @@ export interface ManagedIndexItem {
managedIndexMetaData: ManagedIndexMetaData | null;
}

export interface IndexItem {
index: string;
}

/**
* Interface what the Policy Opensearch Document
*/
Expand Down Expand Up @@ -168,7 +222,7 @@ export interface SMDeleteCondition {
export interface ErrorNotification {
destination?: Destination;
channel?: Channel;
message_template: MessageTemplate;
message_template?: MessageTemplate;
}

export interface Notification {
Expand Down Expand Up @@ -564,3 +618,25 @@ export enum TRANSFORM_AGG_TYPE {
histogram = "histogram",
date_histogram = "date_histogram",
}
export interface IAPICaller {
endpoint: string;
method?: string;
data?: any;
}

export interface IRecoveryItem {
index: string;
stage: "done" | "translog";
}

export interface ITaskItem {
action: string;
description: string;
}

export interface IReindexItem extends ITaskItem {
fromIndex: string;
toIndex: string;
}

export type IAliasAction = Record<string, { index: string; alias: string }>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import React from "react";
import "@testing-library/jest-dom/extend-expect";
import { render, waitFor } from "@testing-library/react";
// @ts-ignore
import userEvent from "@testing-library/user-event";
import IndexControls from "./IndexControls";

describe("<IndexControls /> spec", () => {
it("renders the component", async () => {
const { container } = render(<IndexControls value={{ search: "testing", status: "1" }} onSearchChange={() => {}} />);

expect(container.firstChild).toMatchSnapshot();
});

it("onChange with right data", async () => {
const onSearchChangeMock = jest.fn();
const { getByTestId, getByPlaceholderText } = render(
<IndexControls value={{ search: "", status: "" }} onSearchChange={onSearchChangeMock} />
);

userEvent.type(getByTestId("comboBoxSearchInput"), "closed{enter}");
expect(onSearchChangeMock).toBeCalledTimes(1);
expect(onSearchChangeMock).toBeCalledWith({
search: "",
status: "closed",
});
userEvent.type(getByPlaceholderText("Search..."), "test");
await waitFor(() => {
expect(onSearchChangeMock).toBeCalledTimes(5);
expect(onSearchChangeMock).toBeCalledWith({
search: "test",
status: "closed",
});
});
});
});
52 changes: 52 additions & 0 deletions public/pages/Aliases/components/IndexControls/IndexControls.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import React, { useEffect, useState } from "react";
import { EuiComboBox, EuiFieldSearch, EuiFlexGroup, EuiFlexItem } from "@elastic/eui";
import { ALIAS_STATUS_OPTIONS } from "../../../../utils/constants";

export interface SearchControlsProps {
value: {
search: string;
status: string;
};
onSearchChange: (args: SearchControlsProps["value"]) => void;
}

export default function SearchControls(props: SearchControlsProps) {
const [state, setState] = useState<SearchControlsProps["value"]>(props.value);
const onChange = <T extends keyof SearchControlsProps["value"]>(field: T, value: SearchControlsProps["value"][T]) => {
const payload = {
...state,
[field]: value,
};
setState(payload);
props.onSearchChange(payload);
};
useEffect(() => {
setState(props.value);
}, [props.value]);
return (
<EuiFlexGroup style={{ padding: "0px 5px" }} alignItems="center">
<EuiFlexItem>
<EuiFieldSearch fullWidth placeholder="Search..." value={state.search} onChange={(e) => onChange("search", e.target.value)} />
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiComboBox
style={{
width: 150,
}}
singleSelection={{
asPlainText: true,
}}
placeholder="Status"
options={ALIAS_STATUS_OPTIONS}
selectedOptions={state.status ? [{ label: state.status }] : []}
onChange={(val) => onChange("status", val[0]?.label)}
/>
</EuiFlexItem>
</EuiFlexGroup>
);
}
Loading