Skip to content

Commit

Permalink
feat: merge
Browse files Browse the repository at this point in the history
Signed-off-by: SuZhou-Joe <suzhou@amazon.com>
  • Loading branch information
SuZhou-Joe committed Jul 17, 2023
2 parents 205646e + 165b91c commit d1ab5eb
Show file tree
Hide file tree
Showing 66 changed files with 1,909 additions and 502 deletions.
33 changes: 33 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

const LICENSE_HEADER = `
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
`;

module.exports = {
root: true,
extends: ["@elastic/eslint-config-kibana", "plugin:@elastic/eui/recommended"],
rules: {
// "@osd/eslint/require-license-header": "off"
},
overrides: [
{
files: ["**/*.{js,ts,tsx}"],
rules: {
"@osd/eslint/require-license-header": [
"error",
{
licenses: [LICENSE_HEADER],
},
],
"no-console": 0,
},
},
],
};
2 changes: 1 addition & 1 deletion .github/workflows/cypress-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
- name: Run OpenSearch-Dashboards server
run: |
cd OpenSearch-Dashboards
yarn start --no-base-path --no-watch &
yarn start --no-base-path --no-watch --server.host="0.0.0.0" &
sleep 300
# timeout 300 bash -c 'while [[ "$(curl -s localhost:5601/api/status | jq -r '.status.overall.state')" != "green" ]]; do sleep 5; done'
# for now just chrome, use matrix to do all browsers later
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"policy": {
"policy_id": "test_alias_policy_id",
"description": "Example policy with an alias action.",
"default_state": "alias-state",
"states": [
{
"name": "alias-state",
"actions": [
{
"alias": {
"actions": [
{
"remove": {
"aliases": ["alias1", "alias2"]
}
},
{
"remove": {
"alias": "alias3"
}
},
{
"add": {
"aliases": ["alias4", "alias5"]
}
},
{
"add": {
"aliases": "alias6"
}
}
]
}
}
],
"transitions": []
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import { BASE_PATH, IM_PLUGIN_NAME } from "../../../utils/constants";
import samplePolicy from "../../../fixtures/plugins/index-management-dashboards-plugin/sample_policy";
import sampleAliasPolicy from "../../../fixtures/plugins/index-management-dashboards-plugin/sample_policy_alias_action.json";

const POLICY_ID = "test_policy_id";

Expand Down Expand Up @@ -64,13 +65,106 @@ describe("Policies", () => {
// Confirm we can see the created policy's description in table
cy.contains("A simple description");
});

it("with an alias action using the visual editor", () => {
/* Create a policy with an alias action */
const aliasPolicyId = "visual-editor-alias-policy";
const testInputs = {
add: ["alias1", "alias2"],
remove: ["alias3", "alias5", "alias6"],
};

// Route us to create policy page
cy.contains("Create policy").click({ force: true });

// Use the visual editor
cy.contains("Visual editor").click({ force: true });
cy.contains("Continue").click({ force: true });

// Wait for input to load and then type in the policy ID
cy.get(`input[placeholder="hot_cold_workflow"]`).type(aliasPolicyId, {
force: true,
});

// Type in the policy description
cy.get(`[data-test-subj="create-policy-description"]`).type("{selectall}{backspace}" + sampleAliasPolicy.policy.description);

// Add a state
cy.get("button").contains("Add state").click({ force: true });

// Enter a state name
cy.get(`[data-test-subj="create-state-state-name"]`).type(sampleAliasPolicy.policy.states[0].name);

// Add a new action
cy.get("button").contains("+ Add action").click({ force: true });

// Select 'Alias' type
cy.get(`[data-test-subj="create-state-action-type"]`).select("Add / remove aliases");

// Confirm 'Add action' button is disabled
cy.get(`[data-test-subj="flyout-footer-action-button"]`).should("be.disabled");

// Toggle the add alias combo box
cy.get(`[data-test-subj="add-alias-toggle"]`).click({ force: true });

// Enter aliases to add
cy.get(`[data-test-subj="add-alias-combo-box"]`).click({ force: true }).type(testInputs.add.join("{enter}"));

// Toggle the add alias combo box
cy.get(`[data-test-subj="remove-alias-toggle"]`).click({ force: true });

// Enter aliases to remove
cy.get(`[data-test-subj="remove-alias-combo-box"]`).click({ force: true }).type(testInputs.remove.join("{enter}"));

// Click the 'Add action' button
cy.get(`[data-test-subj="flyout-footer-action-button"]`).click({ force: true });

// Click the 'Save action' button
cy.get("button").contains("Save state").click({ force: true });

// Click the 'Create' button
cy.get("button").contains("Create").click({ force: true });

/* Confirm policy was created as expected */

// Wait for the 'State management' dashboard to load
cy.contains("State management policies (", { timeout: 60000 });

// Click on the test alias to navigate to the details page
cy.contains(aliasPolicyId).click({ force: true });

// Wait for the details page to load, and click the 'Edit' button
cy.url({ timeout: 60000 }).should("include", "policy-details");
cy.contains("Edit").click({ force: true });

// Use the visual editor
cy.contains("Visual editor").click({ force: true });
cy.contains("Continue").click({ force: true });

// Click the state edit icon
cy.get(`[aria-label="Edit"]`).click({ force: true });
cy.get(`[data-test-subj="draggable"]`).within(() => {
cy.get(`[aria-label="Edit"]`).click({ force: true });
});

// Confirm all of the expected inputs are in the 'Add' combo box
testInputs.add.forEach((alias) => {
cy.get(`[data-test-subj="add-alias-combo-box"]`).contains(alias);
});

// Confirm all of the expected inputs are in the 'Remove' combo box
testInputs.remove.forEach((alias) => {
cy.get(`[data-test-subj="remove-alias-combo-box"]`).contains(alias);
});
});
});

describe("can be edited", () => {
before(() => {
cy.deleteAllIndices();
cy.deleteIMJobs();
cy.createPolicy(POLICY_ID, samplePolicy);
cy.createPolicy(sampleAliasPolicy.policy.policy_id, sampleAliasPolicy);
});

it("successfully", () => {
Expand Down Expand Up @@ -116,6 +210,79 @@ describe("Policies", () => {
// Confirm new description shows in table
cy.contains("A new description");
});

it("with more aliases", () => {
// Click on the test alias to navigate to the details page
const testInputs = {
add: ["alias4", "alias6"],
remove: ["alias1", "alias2", "alias3", "alias7"],
};
/* Edit the policy */

// Click on the test alias to navigate to the details page
cy.contains(sampleAliasPolicy.policy.policy_id).click({ force: true });

// Wait for the details page to load, and click the 'Edit' button
cy.url({ timeout: 60000 }).should("include", "policy-details");
cy.contains("Edit").click({ force: true });

// Use the visual editor
cy.contains("Visual editor").click({ force: true });
cy.contains("Continue").click({ force: true });

// Click the 'Edit state' icon
cy.get(`[aria-label="Edit"]`).click({ force: true });

// Click the 'Edit action' icon
cy.get(`[data-test-subj="draggable"]`).within(() => {
cy.get(`[aria-label="Edit"]`).click({ force: true });
});

// Remove an alias from the 'Add' combo box
cy.get(`[aria-label="Remove alias5 from selection in this group"]`).click({ force: true });

// Add a new alias to the 'Remove' combo box
cy.get(`[data-test-subj="remove-alias-combo-box"]`).click({ force: true }).type("alias7{enter}");

// Save the edits
cy.get(`[data-test-subj="flyout-footer-action-button"]`).click({ force: true });
cy.get("button").contains("Update state").click({ force: true });
cy.get("button").contains("Update").click({ force: true });

/* Confirm policy was edited as expected */

// Wait for the 'State management' dashboard to load
cy.contains("State management policies (", { timeout: 60000 });

// Click on the test alias to navigate to the details page
cy.contains(sampleAliasPolicy.policy.policy_id).click({ force: true });

// Wait for the details page to load, and click the 'Edit' button
cy.url({ timeout: 60000 }).should("include", "policy-details");
cy.contains("Edit").click({ force: true });

// Use the visual editor
cy.contains("Visual editor").click({ force: true });
cy.contains("Continue").click({ force: true });

// Click the 'Edit state' icon
cy.get(`[aria-label="Edit"]`).click({ force: true });

// Click the 'Edit action' icon
cy.get(`[data-test-subj="draggable"]`).within(() => {
cy.get(`[aria-label="Edit"]`).click({ force: true });
});

// Confirm all of the expected inputs are in the 'Add' combo box
testInputs.add.forEach((alias) => {
cy.get(`[data-test-subj="add-alias-combo-box"]`).contains(alias);
});

// Confirm all of the expected inputs are in the 'Remove' combo box
testInputs.remove.forEach((alias) => {
cy.get(`[data-test-subj="remove-alias-combo-box"]`).contains(alias);
});
});
});

describe("can be deleted", () => {
Expand Down
19 changes: 19 additions & 0 deletions models/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ export interface UIAction<Data> {
clone: (action: Data) => UIAction<Data>;
content: () => JSX.Element | string | null;
toAction: () => Action;
customDisplayText?: string;
}

export interface ForceMergeAction extends Action {
Expand Down Expand Up @@ -433,6 +434,24 @@ export interface IndexPriorityAction extends Action {
};
}

export enum AliasActions {
ADD = "add",
REMOVE = "remove",
}

export type AliasActionItem = {
[key in AliasActions]: {
alias?: string;
aliases?: string[];
};
};

export interface AliasAction extends Action {
alias: {
actions: AliasActionItem[];
};
}

export interface AllocationAction extends Action {
allocation: {
// TODO: These require a complete UI and we are only supporting JSON editor for allocation for now
Expand Down
15 changes: 5 additions & 10 deletions opensearch_dashboards.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
{
"id": "indexManagementDashboards",
"version": "2.8.0.0",
"opensearchDashboardsVersion": "2.8.0",
"configPath": [
"opensearch_index_management"
],
"requiredPlugins": [
"navigation",
"opensearchDashboardsReact",
"dataSource"
],
"version": "2.9.0.0",
"opensearchDashboardsVersion": "2.9.0",
"configPath": ["opensearch_index_management"],
"requiredPlugins": ["navigation", "opensearchDashboardsReact", "dataSource"],
"optionalPlugins": ["managementOverview"],
"server": true,
"ui": true
}
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "opensearch_index_management_dashboards",
"version": "2.8.0.0",
"version": "2.9.0.0",
"description": "Opensearch Dashboards plugin for Index Management",
"main": "index.js",
"license": "Apache-2.0",
Expand All @@ -17,7 +17,7 @@
"cypress:open": "cypress open",
"osd": "node ../../scripts/osd",
"opensearch": "node ../../scripts/opensearch",
"lint": "node ../../scripts/eslint .",
"lint": "node ../../scripts/eslint . && node ../../scripts/stylelint",
"plugin-helpers": "node ../../scripts/plugin_helpers",
"test:jest": "../../node_modules/.bin/jest --config ./test/jest.config.js",
"build": "yarn plugin-helpers build",
Expand Down Expand Up @@ -46,7 +46,9 @@
"minimist": "^1.2.6",
"moment": "^2.29.4",
"async": "^3.2.3",
"terser": "^4.8.1"
"semver": "^7.5.3",
"terser": "^4.8.1",
"tough-cookie": "^4.1.3"
},
"devDependencies": {
"@elastic/elastic-eslint-config-kibana": "link:../../packages/opensearch-eslint-config-opensearch-dashboards",
Expand Down
Loading

0 comments on commit d1ab5eb

Please sign in to comment.