From dbfddf21ff83e32854e7a850e83471c562aba524 Mon Sep 17 00:00:00 2001 From: suzhou Date: Wed, 22 Feb 2023 13:20:57 +0800 Subject: [PATCH] [Backport main]Feature: rollover (#607) (#635) * Feature: rollover (#607) * feat: update Signed-off-by: suzhou * feat: update Signed-off-by: suzhou * feat: update Signed-off-by: suzhou * feat: add write index in aliases Signed-off-by: suzhou * feat: remove conditions section Signed-off-by: suzhou * feat: update Signed-off-by: suzhou * feat: update Signed-off-by: suzhou * feat: merge data streams Signed-off-by: suzhou * feat: update Signed-off-by: suzhou * feat: update Signed-off-by: suzhou * feat: add rollover cypress test Signed-off-by: suzhou * feat: update Signed-off-by: suzhou * feat: update Signed-off-by: suzhou * feat: make cypress run Signed-off-by: suzhou * feat cypress optimize Signed-off-by: suzhou * fix: rollover with mappings Signed-off-by: suzhou * feat: update Signed-off-by: suzhou * feat: make rollover works in index form Signed-off-by: suzhou * feat: update Signed-off-by: suzhou * feat: update Signed-off-by: suzhou * feat: update Signed-off-by: suzhou * feat: update Signed-off-by: suzhou * feat: update Signed-off-by: suzhou * feat: add placeholder Signed-off-by: suzhou * feat: alignment Signed-off-by: suzhou * feat: update Signed-off-by: suzhou * feat: update rollover description Signed-off-by: suzhou * feat: update Signed-off-by: suzhou * feat: update snapshot Signed-off-by: suzhou * feat: make cypress and unit test run Signed-off-by: suzhou * feat: update Signed-off-by: suzhou * feat: update Signed-off-by: suzhou * feat: update Signed-off-by: suzhou --------- Signed-off-by: suzhou (cherry picked from commit 497d5f18570352dc2ded0cc224c51aab32b9c3fb) * feat: revert modify on workflow Signed-off-by: suzhou --------- Signed-off-by: suzhou --- .github/workflows/cypress-workflow.yml | 2 +- .github/workflows/unit-tests-workflow.yml | 2 +- cypress/integration/data_streams.js | 90 ++ cypress/integration/rollover.js | 100 +++ models/interfaces.ts | 1 + .../AliasSelect/AliasSelect.test.tsx | 0 .../__snapshots__/AliasSelect.test.tsx.snap | 0 .../components/AliasSelect/index.tsx | 8 +- .../DescriptionListHoz/DescriptionListHoz.tsx | 10 +- .../DescriptionListHoz.test.tsx.snap | 2 +- .../built_in_components/index.tsx | 9 +- public/components/FormGenerator/index.tsx | 10 +- .../IndexDetail/IndexDetail.test.tsx | 0 .../components/IndexDetail/IndexDetail.tsx | 111 ++- .../__snapshots__/IndexDetail.test.tsx.snap | 0 .../components/IndexDetail/index.ts | 0 .../components/IndexMapping/IndexMapping.scss | 0 .../IndexMapping/IndexMapping.test.tsx | 2 +- .../components/IndexMapping/IndexMapping.tsx | 8 +- .../__snapshots__/IndexMapping.test.tsx.snap | 4 - .../components/IndexMapping/helper.ts | 2 +- .../components/IndexMapping/index.ts | 0 .../components/IndexMapping/interfaces.ts | 2 +- .../MappingLabel/MappingLabel.test.tsx | 0 .../components/MappingLabel/MappingLabel.tsx | 112 ++- .../__snapshots__/MappingLabel.test.tsx.snap | 2 - .../components/MappingLabel/index.ts | 0 .../containers/IndexForm/IndexForm.test.tsx | 50 ++ .../__snapshots__/IndexForm.test.tsx.snap | 766 ++++++++++++++++++ public/containers/IndexForm/index.tsx | 162 ++++ .../Aliases/containers/AliasActions/index.tsx | 12 +- .../Aliases/containers/Aliases/Aliases.tsx | 38 +- .../__snapshots__/Aliases.test.tsx.snap | 21 +- .../IndexSettings/IndexSettings.tsx | 158 ++++ .../components/IndexSettings/index.ts | 3 + .../BackingIndices/BackingIndices.tsx | 167 ++++ .../containers/BackingIndices/index.ts | 3 + .../CreateDataStream.test.tsx | 50 ++ .../CreateDataStream/CreateDataStream.tsx | 62 ++ .../CreateDataStream.test.tsx.snap | 235 ++++++ .../containers/CreateDataStream/index.ts | 8 + .../DataStreamDetail.test.tsx | 69 ++ .../DataStreamDetail/DataStreamDetail.tsx | 207 +++++ .../DataStreamDetail.test.tsx.snap | 231 ++++++ .../containers/DataStreamDetail/hooks.tsx | 71 ++ .../containers/DataStreamDetail/index.ts | 9 + .../DefineDataStream/DefineDataStream.tsx | 131 +++ .../containers/DefineDataStream/index.ts | 3 + .../containers/IndexAlias/IndexAlias.tsx | 75 ++ .../containers/IndexAlias/index.ts | 3 + .../TemplateMappings/TemplateMappings.tsx | 65 ++ .../containers/TemplateMappings/index.ts | 3 + public/pages/CreateDataStream/hooks.tsx | 10 + public/pages/CreateDataStream/index.ts | 8 + public/pages/CreateDataStream/interface.ts | 20 + .../containers/IndexForm/index.tsx | 27 +- .../CreateIndexTemplate.test.tsx.snap | 6 +- .../containers/IndexAlias/IndexAlias.tsx | 2 +- .../TemplateDetail/TemplateDetail.tsx | 2 +- .../containers/TemplateDetail/hooks.tsx | 2 +- .../TemplateMappings/TemplateMappings.tsx | 4 +- .../IndexControls/IndexControls.test.tsx | 32 + .../IndexControls/IndexControls.tsx | 36 + .../__snapshots__/IndexControls.test.tsx.snap | 47 ++ .../components/IndexControls/index.ts | 9 + .../DataStreams/DataStreams.test.tsx | 102 +++ .../containers/DataStreams/DataStreams.tsx | 414 ++++++++++ .../__snapshots__/DataStreams.test.tsx.snap | 448 ++++++++++ .../containers/DataStreams/index.ts | 3 + .../DataStreamsActions.test.tsx | 105 +++ .../DataStreamsActions.test.tsx.snap | 55 ++ .../containers/DataStreamsActions/index.tsx | 76 ++ .../DeleteDataStreamsModal.test.tsx | 17 + .../DeleteDataStreamsModal.tsx | 52 ++ .../DeleteDataStreamsModal.test.tsx.snap | 143 ++++ .../DeleteDataStreamsModal/index.ts | 8 + public/pages/DataStreams/index.ts | 8 + public/pages/DataStreams/interface.ts | 11 + public/pages/DataStreams/utils/constants.tsx | 27 + public/pages/Indices/utils/constants.tsx | 6 +- public/pages/Main/Main.tsx | 61 +- .../containers/Rollover/Rollover.test.tsx | 51 ++ .../Rollover/containers/Rollover/Rollover.tsx | 379 +++++++++ .../__snapshots__/Rollover.test.tsx.snap | 202 +++++ .../Rollover/containers/Rollover/index.ts | 3 + public/pages/Rollover/hooks.tsx | 216 +++++ public/pages/Rollover/index.ts | 8 + public/pages/Rollover/interface.ts | 19 + .../container/ShrinkIndex/ShrinkIndex.tsx | 2 +- .../__snapshots__/ShrinkIndex.test.tsx.snap | 2 +- .../SplitIndexForm/SplitIndexForm.tsx | 2 +- public/services/CommonService.ts | 1 + public/utils/constants.ts | 6 + server/models/types.ts | 4 +- server/routes/common.ts | 1 + server/services/CommonService.ts | 14 +- 96 files changed, 5565 insertions(+), 165 deletions(-) create mode 100644 cypress/integration/data_streams.js create mode 100644 cypress/integration/rollover.js rename public/{pages/CreateIndex => }/components/AliasSelect/AliasSelect.test.tsx (100%) rename public/{pages/CreateIndex => }/components/AliasSelect/__snapshots__/AliasSelect.test.tsx.snap (100%) rename public/{pages/CreateIndex => }/components/AliasSelect/index.tsx (89%) rename public/{pages/CreateIndex => }/components/IndexDetail/IndexDetail.test.tsx (100%) rename public/{pages/CreateIndex => }/components/IndexDetail/IndexDetail.tsx (90%) rename public/{pages/CreateIndex => }/components/IndexDetail/__snapshots__/IndexDetail.test.tsx.snap (100%) rename public/{pages/CreateIndex => }/components/IndexDetail/index.ts (100%) rename public/{pages/CreateIndex => }/components/IndexMapping/IndexMapping.scss (100%) rename public/{pages/CreateIndex => }/components/IndexMapping/IndexMapping.test.tsx (98%) rename public/{pages/CreateIndex => }/components/IndexMapping/IndexMapping.tsx (97%) rename public/{pages/CreateIndex => }/components/IndexMapping/__snapshots__/IndexMapping.test.tsx.snap (99%) rename public/{pages/CreateIndex => }/components/IndexMapping/helper.ts (97%) rename public/{pages/CreateIndex => }/components/IndexMapping/index.ts (100%) rename public/{pages/CreateIndex => }/components/IndexMapping/interfaces.ts (95%) rename public/{pages/CreateIndex => }/components/MappingLabel/MappingLabel.test.tsx (100%) rename public/{pages/CreateIndex => }/components/MappingLabel/MappingLabel.tsx (72%) rename public/{pages/CreateIndex => }/components/MappingLabel/__snapshots__/MappingLabel.test.tsx.snap (99%) rename public/{pages/CreateIndex => }/components/MappingLabel/index.ts (100%) create mode 100644 public/containers/IndexForm/IndexForm.test.tsx create mode 100644 public/containers/IndexForm/__snapshots__/IndexForm.test.tsx.snap create mode 100644 public/containers/IndexForm/index.tsx create mode 100644 public/pages/CreateDataStream/components/IndexSettings/IndexSettings.tsx create mode 100644 public/pages/CreateDataStream/components/IndexSettings/index.ts create mode 100644 public/pages/CreateDataStream/containers/BackingIndices/BackingIndices.tsx create mode 100644 public/pages/CreateDataStream/containers/BackingIndices/index.ts create mode 100644 public/pages/CreateDataStream/containers/CreateDataStream/CreateDataStream.test.tsx create mode 100644 public/pages/CreateDataStream/containers/CreateDataStream/CreateDataStream.tsx create mode 100644 public/pages/CreateDataStream/containers/CreateDataStream/__snapshots__/CreateDataStream.test.tsx.snap create mode 100644 public/pages/CreateDataStream/containers/CreateDataStream/index.ts create mode 100644 public/pages/CreateDataStream/containers/DataStreamDetail/DataStreamDetail.test.tsx create mode 100644 public/pages/CreateDataStream/containers/DataStreamDetail/DataStreamDetail.tsx create mode 100644 public/pages/CreateDataStream/containers/DataStreamDetail/__snapshots__/DataStreamDetail.test.tsx.snap create mode 100644 public/pages/CreateDataStream/containers/DataStreamDetail/hooks.tsx create mode 100644 public/pages/CreateDataStream/containers/DataStreamDetail/index.ts create mode 100644 public/pages/CreateDataStream/containers/DefineDataStream/DefineDataStream.tsx create mode 100644 public/pages/CreateDataStream/containers/DefineDataStream/index.ts create mode 100644 public/pages/CreateDataStream/containers/IndexAlias/IndexAlias.tsx create mode 100644 public/pages/CreateDataStream/containers/IndexAlias/index.ts create mode 100644 public/pages/CreateDataStream/containers/TemplateMappings/TemplateMappings.tsx create mode 100644 public/pages/CreateDataStream/containers/TemplateMappings/index.ts create mode 100644 public/pages/CreateDataStream/hooks.tsx create mode 100644 public/pages/CreateDataStream/index.ts create mode 100644 public/pages/CreateDataStream/interface.ts create mode 100644 public/pages/DataStreams/components/IndexControls/IndexControls.test.tsx create mode 100644 public/pages/DataStreams/components/IndexControls/IndexControls.tsx create mode 100644 public/pages/DataStreams/components/IndexControls/__snapshots__/IndexControls.test.tsx.snap create mode 100644 public/pages/DataStreams/components/IndexControls/index.ts create mode 100644 public/pages/DataStreams/containers/DataStreams/DataStreams.test.tsx create mode 100644 public/pages/DataStreams/containers/DataStreams/DataStreams.tsx create mode 100644 public/pages/DataStreams/containers/DataStreams/__snapshots__/DataStreams.test.tsx.snap create mode 100644 public/pages/DataStreams/containers/DataStreams/index.ts create mode 100644 public/pages/DataStreams/containers/DataStreamsActions/DataStreamsActions.test.tsx create mode 100644 public/pages/DataStreams/containers/DataStreamsActions/__snapshots__/DataStreamsActions.test.tsx.snap create mode 100644 public/pages/DataStreams/containers/DataStreamsActions/index.tsx create mode 100644 public/pages/DataStreams/containers/DeleteDataStreamsModal/DeleteDataStreamsModal.test.tsx create mode 100644 public/pages/DataStreams/containers/DeleteDataStreamsModal/DeleteDataStreamsModal.tsx create mode 100644 public/pages/DataStreams/containers/DeleteDataStreamsModal/__snapshots__/DeleteDataStreamsModal.test.tsx.snap create mode 100644 public/pages/DataStreams/containers/DeleteDataStreamsModal/index.ts create mode 100644 public/pages/DataStreams/index.ts create mode 100644 public/pages/DataStreams/interface.ts create mode 100644 public/pages/DataStreams/utils/constants.tsx create mode 100644 public/pages/Rollover/containers/Rollover/Rollover.test.tsx create mode 100644 public/pages/Rollover/containers/Rollover/Rollover.tsx create mode 100644 public/pages/Rollover/containers/Rollover/__snapshots__/Rollover.test.tsx.snap create mode 100644 public/pages/Rollover/containers/Rollover/index.ts create mode 100644 public/pages/Rollover/hooks.tsx create mode 100644 public/pages/Rollover/index.ts create mode 100644 public/pages/Rollover/interface.ts diff --git a/.github/workflows/cypress-workflow.yml b/.github/workflows/cypress-workflow.yml index ea11fd346..120c43b53 100644 --- a/.github/workflows/cypress-workflow.yml +++ b/.github/workflows/cypress-workflow.yml @@ -29,7 +29,7 @@ jobs: with: path: index-management repository: opensearch-project/index-management - ref: '2.5' + ref: 'main' - name: Run opensearch with plugin run: | cd index-management diff --git a/.github/workflows/unit-tests-workflow.yml b/.github/workflows/unit-tests-workflow.yml index 1bc935419..15a4ac604 100644 --- a/.github/workflows/unit-tests-workflow.yml +++ b/.github/workflows/unit-tests-workflow.yml @@ -7,7 +7,7 @@ on: branches: - "*" env: - OPENSEARCH_DASHBOARDS_VERSION: '2.5' + OPENSEARCH_DASHBOARDS_VERSION: '2.x' jobs: tests: name: Run unit tests diff --git a/cypress/integration/data_streams.js b/cypress/integration/data_streams.js new file mode 100644 index 000000000..ac5f6fe75 --- /dev/null +++ b/cypress/integration/data_streams.js @@ -0,0 +1,90 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ +import { PLUGIN_NAME } from "../support/constants"; + +describe("Data stream", () => { + before(() => { + // Set welcome screen tracking to false + localStorage.setItem("home:welcome:show", "false"); + cy.deleteTemplate("index-common-template"); + cy.createIndexTemplate("index-common-template", { + index_patterns: ["ds-*"], + data_stream: {}, + template: { + aliases: { + alias_for_common_1: {}, + alias_for_common_2: {}, + }, + settings: { + number_of_shards: 2, + number_of_replicas: 1, + }, + }, + }); + cy.request({ + url: `${Cypress.env("opensearch")}/_data_stream/*`, + method: "DELETE", + failOnStatusCode: false, + }); + }); + + beforeEach(() => { + // Visit ISM OSD + cy.visit(`${Cypress.env("opensearch_dashboards")}/app/${PLUGIN_NAME}#/data-streams`); + + // Common text to wait for to confirm page loaded, give up to 60 seconds for initial load + cy.contains("Data streams", { timeout: 60000 }); + }); + + describe("can create a data stream", () => { + it("successfully", () => { + cy.get('[data-test-subj="Create data streamButton"]').click(); + cy.get('[data-test-subj="form-row-name"]').type(`ds-{enter}`); + cy.get('[data-test-subj="CreateDataStreamCreateButton"]').click(); + cy.contains("ds- has been successfully created."); + }); + }); + + describe("can be searched / sorted / paginated", () => { + it("successfully", () => { + cy.contains("ds-"); + cy.contains("index-common-template"); + }); + }); + + describe("can delete a data stream", () => { + it("successfully", () => { + cy.get('[data-test-subj="moreAction"] button') + .click() + .get('[data-test-subj="deleteAction"]') + .should("be.disabled") + .get(`#_selection_column_ds--checkbox`) + .click() + .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_ds--checkbox`).should("not.exist"); + }); + }); + + after(() => { + cy.request({ + url: `${Cypress.env("opensearch")}/_data_stream`, + method: "DELETE", + failOnStatusCode: false, + }); + cy.deleteTemplate("index-common-template"); + }); +}); diff --git a/cypress/integration/rollover.js b/cypress/integration/rollover.js new file mode 100644 index 000000000..9132220dc --- /dev/null +++ b/cypress/integration/rollover.js @@ -0,0 +1,100 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ +import { PLUGIN_NAME } from "../support/constants"; + +const rolloverValidAlias = "rollover-valid-alias"; +const rolloverAliasNeedTargetIndex = "rollover-alias-need-target-index"; +const rolloverDataStream = "data-stream-rollover"; +const validIndex = "index-000001"; +const invalidIndex = "index-test-rollover"; + +describe("Rollover", () => { + before(() => { + // Set welcome screen tracking to false + localStorage.setItem("home:welcome:show", "false"); + cy.deleteTemplate("index-common-template"); + cy.deleteAllIndices(); + cy.request({ + url: `${Cypress.env("opensearch")}/_data_stream/*`, + method: "DELETE", + failOnStatusCode: false, + }); + cy.createIndex(validIndex); + cy.createIndex(invalidIndex); + cy.addAlias(rolloverValidAlias, validIndex); + cy.addAlias(rolloverAliasNeedTargetIndex, invalidIndex); + cy.createIndexTemplate("index-common-template", { + index_patterns: ["data-stream-*"], + data_stream: {}, + template: { + aliases: { + alias_for_common_1: {}, + alias_for_common_2: {}, + }, + settings: { + number_of_shards: 2, + number_of_replicas: 1, + }, + }, + }); + cy.request({ + url: `${Cypress.env("opensearch")}/_data_stream/${rolloverDataStream}`, + method: "PUT", + failOnStatusCode: false, + }); + }); + + describe("rollover", () => { + it("rollover data stream successfully", () => { + // Visit ISM OSD + cy.visit(`${Cypress.env("opensearch_dashboards")}/app/${PLUGIN_NAME}#/rollover/${rolloverDataStream}`); + cy.contains("Configure source", { timeout: 60000 }); + + // click create + cy.get('[data-test-subj="rolloverSubmitButton"]').click({ force: true }); + + cy.contains(/has been successfully rollover./); + }); + + it("rollover valid alias successfully", () => { + // Visit ISM OSD + cy.visit(`${Cypress.env("opensearch_dashboards")}/app/${PLUGIN_NAME}#/rollover/${rolloverValidAlias}`); + cy.contains("Configure new rollover index", { timeout: 60000 }); + + // click create + cy.get('[data-test-subj="rolloverSubmitButton"]').click({ force: true }); + + cy.contains(/has been successfully rollover./); + }); + + it("rollover invalid alias successfully", () => { + // Visit ISM OSD + cy.visit(`${Cypress.env("opensearch_dashboards")}/app/${PLUGIN_NAME}#/rollover/${rolloverAliasNeedTargetIndex}`); + cy.contains("Configure new rollover index", { timeout: 60000 }); + + // click create + cy.get('[data-test-subj="rolloverSubmitButton"]').click({ force: true }); + + cy.contains("Invalid index name."); + + cy.get('[data-test-subj="form-name-index"] input').type("index-test-rollover-target"); + + // click create + cy.get('[data-test-subj="rolloverSubmitButton"]').click({ force: true }); + + cy.contains(/has been successfully rollover./); + }); + }); + + after(() => { + cy.deleteTemplate("index-common-template"); + cy.deleteAllIndices(); + cy.request({ + url: `${Cypress.env("opensearch")}/_data_stream/*`, + method: "DELETE", + failOnStatusCode: false, + }); + }); +}); diff --git a/models/interfaces.ts b/models/interfaces.ts index 5ab513986..52c025fa1 100644 --- a/models/interfaces.ts +++ b/models/interfaces.ts @@ -622,6 +622,7 @@ export interface IAPICaller { endpoint: string; method?: string; data?: any; + hideLog?: boolean; } export interface IRecoveryItem { diff --git a/public/pages/CreateIndex/components/AliasSelect/AliasSelect.test.tsx b/public/components/AliasSelect/AliasSelect.test.tsx similarity index 100% rename from public/pages/CreateIndex/components/AliasSelect/AliasSelect.test.tsx rename to public/components/AliasSelect/AliasSelect.test.tsx diff --git a/public/pages/CreateIndex/components/AliasSelect/__snapshots__/AliasSelect.test.tsx.snap b/public/components/AliasSelect/__snapshots__/AliasSelect.test.tsx.snap similarity index 100% rename from public/pages/CreateIndex/components/AliasSelect/__snapshots__/AliasSelect.test.tsx.snap rename to public/components/AliasSelect/__snapshots__/AliasSelect.test.tsx.snap diff --git a/public/pages/CreateIndex/components/AliasSelect/index.tsx b/public/components/AliasSelect/index.tsx similarity index 89% rename from public/pages/CreateIndex/components/AliasSelect/index.tsx rename to public/components/AliasSelect/index.tsx index d321499fb..8b8087787 100644 --- a/public/pages/CreateIndex/components/AliasSelect/index.tsx +++ b/public/components/AliasSelect/index.tsx @@ -5,10 +5,10 @@ import React, { forwardRef, useRef } from "react"; import { EuiComboBoxProps } from "@elastic/eui"; -import RemoteSelect, { RemoteSelectProps } from "../../../../components/RemoteSelect"; -import { ServerResponse } from "../../../../../server/models/types"; -import { filterByMinimatch } from "../../../../../utils/helper"; -import { SYSTEM_ALIAS } from "../../../../../utils/constants"; +import RemoteSelect, { RemoteSelectProps } from "../RemoteSelect"; +import { ServerResponse } from "../../../server/models/types"; +import { filterByMinimatch } from "../../../utils/helper"; +import { SYSTEM_ALIAS } from "../../../utils/constants"; export interface AliasSelectProps extends Omit, "value" | "onChange"> { value?: Record; diff --git a/public/components/DescriptionListHoz/DescriptionListHoz.tsx b/public/components/DescriptionListHoz/DescriptionListHoz.tsx index 02f24d025..70725850b 100644 --- a/public/components/DescriptionListHoz/DescriptionListHoz.tsx +++ b/public/components/DescriptionListHoz/DescriptionListHoz.tsx @@ -1,4 +1,4 @@ -import { EuiDescriptionList, EuiDescriptionListProps, EuiFlexGroup, EuiFlexItem } from "@elastic/eui"; +import { EuiDescriptionList, EuiDescriptionListProps, EuiFlexGrid, EuiFlexGridProps, EuiFlexGroup, EuiFlexItem } from "@elastic/eui"; import React from "react"; const DisplayItem = ( @@ -20,15 +20,15 @@ const DisplayItem = ( ); }; -export default function DescriptionListHoz(props: EuiDescriptionListProps) { - const { listItems, ...others } = props; +export default function DescriptionListHoz(props: EuiDescriptionListProps & Pick) { + const { listItems, columns = 4, ...others } = props; return ( - + {listItems?.map((item) => ( ))} - + ); } diff --git a/public/components/DescriptionListHoz/__snapshots__/DescriptionListHoz.test.tsx.snap b/public/components/DescriptionListHoz/__snapshots__/DescriptionListHoz.test.tsx.snap index 46662e1b7..5c890d139 100644 --- a/public/components/DescriptionListHoz/__snapshots__/DescriptionListHoz.test.tsx.snap +++ b/public/components/DescriptionListHoz/__snapshots__/DescriptionListHoz.test.tsx.snap @@ -3,7 +3,7 @@ exports[` spec renders the component 1`] = `
{ - const findItem = options.find((item: { label: string }) => item.label === searchValue); + const allOptions = (options as { label: string; options?: { label: string }[] }[]).reduce((total, current) => { + if (current.options) { + return [...total, ...current.options]; + } else { + return [...total, current]; + } + }, [] as { label: string }[]); + const findItem = allOptions.find((item: { label: string }) => item.label === searchValue); if (findItem) { onChange(searchValue); } diff --git a/public/components/FormGenerator/index.tsx b/public/components/FormGenerator/index.tsx index 29b2278bf..9ca7d7241 100644 --- a/public/components/FormGenerator/index.tsx +++ b/public/components/FormGenerator/index.tsx @@ -2,7 +2,7 @@ import React, { forwardRef, useRef, useImperativeHandle, useEffect, useMemo } fr import { EuiForm, EuiFormProps, EuiSpacer } from "@elastic/eui"; import { isEqual, omit, pick } from "lodash"; import AllBuiltInComponents, { IFieldComponentProps } from "./built_in_components"; -import useField, { InitOption, FieldOption, Rule, FieldInstance, FieldName } from "../../lib/field"; +import useField, { InitOption, FieldOption, Rule, FieldInstance, FieldName, transformNameToString } from "../../lib/field"; import AdvancedSettings, { IAdvancedSettingsProps, IAdvancedSettingsRef } from "../AdvancedSettings"; import CustomFormRow, { CustomFormRowProps } from "../CustomFormRow"; @@ -23,7 +23,7 @@ interface IFormGeneratorAdvancedSettings extends IAdvancedSettingsProps { export interface IField { rowProps: Pick; - name: string; + name: FieldName; type?: keyof typeof AllBuiltInComponents; component?: React.ComponentType; options?: Omit; @@ -129,10 +129,10 @@ function FormGenerator(props: IFormGeneratorProps, ref: React.Ref void; + docVersion: string; + refreshOptions: AliasSelectProps["refreshOptions"]; value?: Partial; oldValue?: Partial; - onChange: (value: IndexDetailProps["value"]) => void; isEdit?: boolean; readonly?: boolean; - refreshOptions: AliasSelectProps["refreshOptions"]; mode?: IndicesUpdateMode; onSimulateIndexTemplate?: (indexName: string) => Promise>; onGetIndexDetail?: (indexName: string) => Promise; sourceIndices?: string[]; onSubmit?: () => Promise<{ ok: boolean }>; refreshIndex?: () => void; - docVersion: string; + withoutPanel?: boolean; } export interface IIndexDetailRef { validate: () => Promise; hasUnsavedChanges: (mode: IndicesUpdateMode) => number; getMappingsJSONEditorValue: () => string; + simulateFromTemplate: () => Promise; + importSettings: (args: { index: string }) => Promise; } const TemplateInfoCallout = (props: { visible: boolean }) => { @@ -110,6 +113,7 @@ const IndexDetail = ( onSubmit, refreshIndex, docVersion, + withoutPanel, }: IndexDetailProps, ref: Ref ) => { @@ -132,18 +136,6 @@ const IndexDetail = ( const aliasesRef = useRef(null); const settingsRef = useRef(null); const mappingsRef = useRef(null); - useImperativeHandle(ref, () => ({ - validate: async () => { - const result = await Promise.all([ - aliasesRef.current?.validatePromise().then((result) => result.errors), - mappingsRef.current?.validate(), - settingsRef.current?.validatePromise().then((result) => result.errors), - ]); - return result.every((item) => !item); - }, - hasUnsavedChanges: (mode: IndicesUpdateMode) => diffJson(oldValue?.[mode], finalValue[mode]), - getMappingsJSONEditorValue: () => mappingsRef.current?.getJSONEditorValue() || "", - })); const onIndexInputBlur = useCallback(async () => { await new Promise((resolve) => setTimeout(resolve, 200)); if (destroyRef.current) { @@ -229,6 +221,7 @@ const IndexDetail = ( // omit alias ...omit(indexDetail, ["aliases", "data_stream"]), mappings: { + ...indexDetail?.mappings, properties: transformObjectToArray(indexDetail?.mappings?.properties || {}), }, // pick some metadata in index @@ -238,6 +231,20 @@ const IndexDetail = ( hasEdit.current = false; } }; + useImperativeHandle(ref, () => ({ + validate: async () => { + const result = await Promise.all([ + aliasesRef.current?.validatePromise().then((result) => result.errors), + mappingsRef.current?.validate(), + settingsRef.current?.validatePromise().then((result) => result.errors), + ]); + return result.every((item) => !item); + }, + hasUnsavedChanges: (mode: IndicesUpdateMode) => diffJson(oldValue?.[mode], finalValue[mode]), + getMappingsJSONEditorValue: () => mappingsRef.current?.getJSONEditorValue() || "", + simulateFromTemplate: onIndexInputBlur, + importSettings: onImportSettings, + })); const formFields: IField[] = useMemo(() => { return [ { @@ -406,9 +413,25 @@ const IndexDetail = ( if (mode && mode === IndicesUpdateMode.alias) { return content; } + + const title = "Define index"; + + if (withoutPanel) { + return ( + <> + + {title} + + + {content} + + + ); + } + return ( <> - + {content} @@ -508,6 +531,21 @@ const IndexDetail = ( return content; } + const title = "Index settings"; + + if (withoutPanel) { + return ( + <> + +

{title}

+
+ + {content} + + + ); + } + return ( <> @@ -538,6 +576,19 @@ const IndexDetail = ( return content; } + if (withoutPanel) { + return ( + <> + +
Index mapping
+
+ + {content} + + + ); + } + return ( , ref: Ref) => { diff --git a/public/pages/CreateIndex/components/IndexMapping/IndexMapping.tsx b/public/components/IndexMapping/IndexMapping.tsx similarity index 97% rename from public/pages/CreateIndex/components/IndexMapping/IndexMapping.tsx rename to public/components/IndexMapping/IndexMapping.tsx index d4cfeed79..621c9b6dd 100644 --- a/public/pages/CreateIndex/components/IndexMapping/IndexMapping.tsx +++ b/public/components/IndexMapping/IndexMapping.tsx @@ -6,10 +6,10 @@ import React, { forwardRef, useCallback, useState, Ref, useRef, useMemo, useImperativeHandle } from "react"; import { EuiTreeView, EuiIcon, EuiTreeViewProps, EuiButton, EuiSpacer, EuiButtonGroup, EuiLink } from "@elastic/eui"; import { set, get, isEmpty } from "lodash"; -import JSONEditor, { IJSONEditorRef } from "../../../../components/JSONEditor"; -import { Modal } from "../../../../components/Modal"; -import { MappingsProperties } from "../../../../../models/interfaces"; -import CustomFormRow from "../../../../components/CustomFormRow"; +import JSONEditor, { IJSONEditorRef } from "../JSONEditor"; +import { Modal } from "../Modal"; +import { MappingsProperties } from "../../../models/interfaces"; +import CustomFormRow from "../CustomFormRow"; import MappingLabel, { IMappingLabelRef } from "../MappingLabel"; import { transformObjectToArray, transformArrayToObject, countNodesInTree } from "./helper"; import { IndexMappingsObjectAll, IndexMappingProps, EDITOR_MODE, IIndexMappingsRef } from "./interfaces"; diff --git a/public/pages/CreateIndex/components/IndexMapping/__snapshots__/IndexMapping.test.tsx.snap b/public/components/IndexMapping/__snapshots__/IndexMapping.test.tsx.snap similarity index 99% rename from public/pages/CreateIndex/components/IndexMapping/__snapshots__/IndexMapping.test.tsx.snap rename to public/components/IndexMapping/__snapshots__/IndexMapping.test.tsx.snap index 95eb79bc3..9d6b2373f 100644 --- a/public/pages/CreateIndex/components/IndexMapping/__snapshots__/IndexMapping.test.tsx.snap +++ b/public/components/IndexMapping/__snapshots__/IndexMapping.test.tsx.snap @@ -139,7 +139,6 @@ exports[` spec render mappings with object type 1`] = ` spec render mappings with object type 1`] = ` spec render mappings with object type 1`] = ` spec render component 1`] = ` +
+
+ +
+
+ Must be in lowercase letters. Cannot begin with underscores or hyphens. Spaces, commas, and characters :, ", *, +, /, , |, ?, #, > are not allowed. +
+
+
+ +
+
+
+
+
+ +
+
+
+ Allow this index to be referenced by existing aliases or specify a new alias. +
+ + +
+
+
+ +
+
+
+
+

+ Index settings + + + + +

+
+
+
+
+
+
+
+ +
+
+
+
+ Specify the number of primary shards for the index. Default is 1. +
+
+ The number of primary shards cannot be changed after the index is created. +
+
+ +
+
+ +
+
+
+
+
+
+
+ +
+
+
+ Specify the number of replicas each primary shard should have. Default is 1. +
+ +
+
+ +
+
+
+
+
+
+
+ +
+
+
+ Specify how often the index should refresh, which publishes the most recent changes and make them available for search. Default is 1 second. +
+ +
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+

+ Specify a comma-delimited list of settings. + + + View index settings. + EuiIconMock + + (opens in a new tab or window) + + +

+

+ All the settings will be handled in flat structure. + + + Learn more. + EuiIconMock + + (opens in a new tab or window) + + +

+
+ +
+ +
+