From 3a78419127feea10379454fc15e88c69cb1cf1ce Mon Sep 17 00:00:00 2001 From: suzhou Date: Tue, 3 Jan 2023 15:57:37 +0800 Subject: [PATCH] Feature/unittest fix 2.5 (#525) * Feature/common 2.5 (#506) * feat: split to common change Signed-off-by: suzhou * feat: update Signed-off-by: suzhou 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 Signed-off-by: suzhou --- .../components/DefinePolicy/DefinePolicy.tsx | 2 +- .../containers/CreatePolicy/CreatePolicy.tsx | 10 ++++++++++ .../AdvancedAggregation.tsx | 2 +- .../MetricsCalculation/MetricsCalculation.tsx | 18 +++++++++++------ .../RollupIndices/RollupIndices.tsx | 20 ++++++++++++++++--- .../TimeAggregations/TimeAggregation.tsx | 2 +- .../CreateRollupForm/CreateRollupForm.tsx | 10 +++++++++- .../CreateTransformSteps.tsx | 8 ++++---- .../TransformIndices/TransformIndices.tsx | 14 ++++++++++++- .../CreateTransformForm.tsx | 9 +++++++++ .../Rollups/containers/Rollups/Rollups.tsx | 2 +- .../components/States/State.tsx | 8 ++++---- .../components/States/States.tsx | 2 +- .../ErrorNotification.test.tsx | 17 ++++++++++++---- .../ErrorNotification/ErrorNotification.tsx | 2 +- 15 files changed, 97 insertions(+), 29 deletions(-) diff --git a/public/pages/CreatePolicy/components/DefinePolicy/DefinePolicy.tsx b/public/pages/CreatePolicy/components/DefinePolicy/DefinePolicy.tsx index 9593c1998..d891e7591 100644 --- a/public/pages/CreatePolicy/components/DefinePolicy/DefinePolicy.tsx +++ b/public/pages/CreatePolicy/components/DefinePolicy/DefinePolicy.tsx @@ -60,7 +60,7 @@ const DefinePolicy = ({ jsonString, onChange, onAutoIndent, hasJSONError }: Defi - {isDarkMode => ( + {(isDarkMode) => ( { static contextType = CoreServicesContext; + _isMount: boolean; constructor(props: CreatePolicyProps) { super(props); @@ -47,6 +48,8 @@ export default class CreatePolicy extends Component => { @@ -71,6 +74,10 @@ export default class CreatePolicy extends Component => { try { const { policyService } = this.props; @@ -169,6 +176,9 @@ export default class CreatePolicy extends Component ( - + ( - + this.setChecked(e, "all", item)} @@ -277,8 +278,9 @@ export default class MetricsCalculation extends Component ( - + this.setChecked(e, "min", item)} @@ -294,8 +296,9 @@ export default class MetricsCalculation extends Component ( - + this.setChecked(e, "max", item)} @@ -311,8 +314,9 @@ export default class MetricsCalculation extends Component ( - + this.setChecked(e, "sum", item)} @@ -328,8 +332,9 @@ export default class MetricsCalculation extends Component ( - + this.setChecked(e, "avg", item)} @@ -345,8 +350,9 @@ export default class MetricsCalculation extends Component ( - + this.setChecked(e, "value_count", item)} diff --git a/public/pages/CreateRollup/components/RollupIndices/RollupIndices.tsx b/public/pages/CreateRollup/components/RollupIndices/RollupIndices.tsx index 1140b66a6..9dedf48af 100644 --- a/public/pages/CreateRollup/components/RollupIndices/RollupIndices.tsx +++ b/public/pages/CreateRollup/components/RollupIndices/RollupIndices.tsx @@ -4,9 +4,10 @@ */ import React, { Component, Fragment } from "react"; -import { EuiSpacer, EuiFormRow, EuiComboBox, EuiCallOut, EuiText, EuiLink } from "@elastic/eui"; +import { EuiSpacer, EuiFormRow, EuiCallOut, EuiText, EuiLink } from "@elastic/eui"; import { EuiComboBoxOptionOption } from "@elastic/eui/src/components/combo_box/types"; import _ from "lodash"; +import EuiComboBox from "../../../../components/BetterComboBox"; import { ContentPanel } from "../../../../components/ContentPanel"; import { IndexItem } from "../../../../../models/interfaces"; import IndexService from "../../../../services/IndexService"; @@ -34,6 +35,7 @@ export const ROLLUP_RESULTS_HELP_TEXT_LINK = "https://opensearch.org/docs/latest export default class RollupIndices extends Component { static contextType = CoreServicesContext; + _isMount: boolean; constructor(props: RollupIndicesProps) { super(props); this.state = { @@ -42,6 +44,7 @@ export default class RollupIndices extends Component => { + if (!this._isMount) { + return; + } const { indexService } = this.props; this.setState({ isLoading: true, indexOptions: [] }); try { @@ -59,7 +69,9 @@ export default class RollupIndices extends Component ({ label })); const indices = dataStreamsAndIndicesNamesResponse.response.indices.map((label) => ({ label })); - this.setState({ indexOptions: options.concat(dataStreams, indices), targetIndexOptions: indices }); + if (this._isMount) { + this.setState({ indexOptions: options.concat(dataStreams, indices), targetIndexOptions: indices }); + } } else { if (dataStreamsAndIndicesNamesResponse.error.startsWith("[index_not_found_exception]")) { this.context.notifications.toasts.addDanger("No index available"); @@ -71,7 +83,9 @@ export default class RollupIndices extends Component { diff --git a/public/pages/CreateRollup/components/TimeAggregations/TimeAggregation.tsx b/public/pages/CreateRollup/components/TimeAggregations/TimeAggregation.tsx index d2be4bf2f..e5cd94eca 100644 --- a/public/pages/CreateRollup/components/TimeAggregations/TimeAggregation.tsx +++ b/public/pages/CreateRollup/components/TimeAggregations/TimeAggregation.tsx @@ -7,7 +7,6 @@ import React, { ChangeEvent, Component, Fragment } from "react"; import { EuiSpacer, EuiFormRow, - EuiComboBox, EuiSelect, EuiFlexGroup, EuiFlexItem, @@ -21,6 +20,7 @@ import { EuiText, } from "@elastic/eui"; import moment from "moment-timezone"; +import EuiComboBox from "../../../../components/BetterComboBox"; import { RollupService } from "../../../../services"; import { FieldItem } from "../../../../../models/interfaces"; import { CalendarTimeunitOptions, FixedTimeunitOptions } from "../../../../utils/constants"; diff --git a/public/pages/CreateRollup/containers/CreateRollupForm/CreateRollupForm.tsx b/public/pages/CreateRollup/containers/CreateRollupForm/CreateRollupForm.tsx index d3002db0d..85ce8d1b1 100644 --- a/public/pages/CreateRollup/containers/CreateRollupForm/CreateRollupForm.tsx +++ b/public/pages/CreateRollup/containers/CreateRollupForm/CreateRollupForm.tsx @@ -77,6 +77,7 @@ interface CreateRollupFormState { export default class CreateRollupForm extends Component { static contextType = CoreServicesContext; + _isMount: boolean; constructor(props: CreateRollupFormProps) { super(props); @@ -131,12 +132,17 @@ export default class CreateRollupForm extends Component => { this.context.chrome.setBreadcrumbs([BREADCRUMBS.INDEX_MANAGEMENT, BREADCRUMBS.ROLLUPS, BREADCRUMBS.CREATE_ROLLUP]); }; + componentWillUnmount() { + this._isMount = false; + } + getMappings = async (srcIndex: string): Promise => { if (!srcIndex.length) return; try { @@ -481,7 +487,9 @@ export default class CreateRollupForm extends Component { diff --git a/public/pages/CreateTransform/components/CreateTransformSteps/CreateTransformSteps.tsx b/public/pages/CreateTransform/components/CreateTransformSteps/CreateTransformSteps.tsx index 838c89215..8f5404825 100644 --- a/public/pages/CreateTransform/components/CreateTransformSteps/CreateTransformSteps.tsx +++ b/public/pages/CreateTransform/components/CreateTransformSteps/CreateTransformSteps.tsx @@ -14,21 +14,21 @@ const setOfSteps = (step: number) => { return [ { title: "Set up indices", - children: null, + children: <>, }, { title: "Define transforms", - children: null, + children: <>, status: step < 2 ? "disabled" : null, }, { title: "Specify schedule", - children: null, + children: <>, status: step < 3 ? "disabled" : null, }, { title: "Review and create", - children: null, + children: <>, status: step < 4 ? "disabled" : null, }, ]; diff --git a/public/pages/CreateTransform/components/TransformIndices/TransformIndices.tsx b/public/pages/CreateTransform/components/TransformIndices/TransformIndices.tsx index f60457038..0e8b8583c 100644 --- a/public/pages/CreateTransform/components/TransformIndices/TransformIndices.tsx +++ b/public/pages/CreateTransform/components/TransformIndices/TransformIndices.tsx @@ -7,7 +7,6 @@ import React, { Component, Fragment } from "react"; import { EuiSpacer, EuiFormRow, - EuiComboBox, EuiCallOut, EuiPopover, EuiFlexGroup, @@ -20,6 +19,7 @@ import { EuiLink, } from "@elastic/eui"; import _ from "lodash"; +import EuiComboBox from "../../../../components/BetterComboBox"; import { ContentPanel } from "../../../../components/ContentPanel"; import IndexFilterPopover from "../IndexFilterPopover"; import { FieldItem, IndexItem } from "../../../../../models/interfaces"; @@ -53,6 +53,7 @@ interface TransformIndicesState { export default class TransformIndices extends Component { static contextType = CoreServicesContext; + _isMount: boolean; constructor(props: TransformIndicesProps) { super(props); this.state = { @@ -63,6 +64,7 @@ export default class TransformIndices extends Component => { + if (!this._isMount) { + return; + } const { indexService } = this.props; this.setState({ isLoading: true, indexOptions: [] }); try { const dataStreamsAndIndicesNamesResponse = await indexService.getDataStreamsAndIndicesNames(searchValue); + if (!this._isMount) { + return; + } if (dataStreamsAndIndicesNamesResponse.ok) { // Adding wildcard to search value const options = searchValue.trim() ? [{ label: wildcardOption(searchValue) }] : []; diff --git a/public/pages/CreateTransform/containers/CreateTransformForm/CreateTransformForm.tsx b/public/pages/CreateTransform/containers/CreateTransformForm/CreateTransformForm.tsx index 4a5df05c3..326daff6c 100644 --- a/public/pages/CreateTransform/containers/CreateTransformForm/CreateTransformForm.tsx +++ b/public/pages/CreateTransform/containers/CreateTransformForm/CreateTransformForm.tsx @@ -80,6 +80,7 @@ interface CreateTransformFormState { export default class CreateTransformForm extends Component { static contextType = CoreServicesContext; + _isMount: boolean; constructor(props: CreateTransformFormProps) { super(props); @@ -129,12 +130,17 @@ export default class CreateTransformForm extends Component => { this.context.chrome.setBreadcrumbs([BREADCRUMBS.INDEX_MANAGEMENT, BREADCRUMBS.TRANSFORMS, BREADCRUMBS.CREATE_TRANSFORM]); }; + componentWillUnmount() { + this._isMount = false; + } + getMappings = async (srcIndex: string): Promise => { if (!srcIndex.length) return; try { @@ -485,6 +491,9 @@ export default class CreateTransformForm extends Component { pageIndex: page, pageSize: size, pageSizeOptions: DEFAULT_PAGE_SIZE_OPTIONS, - totalItemCount: totalRollups, + totalItemCount: totalRollups || 0, }; const sorting: EuiTableSortingType = { diff --git a/public/pages/VisualCreatePolicy/components/States/State.tsx b/public/pages/VisualCreatePolicy/components/States/State.tsx index f9d90a582..47e0ce6e4 100644 --- a/public/pages/VisualCreatePolicy/components/States/State.tsx +++ b/public/pages/VisualCreatePolicy/components/States/State.tsx @@ -113,8 +113,8 @@ const State = ({ state, isInitialState, idx, onClickEditState, onClickDeleteStat No actions. Edit state to add actions. ) : ( - {state.actions.map((action) => ( - + {state.actions.map((action, index) => ( + {actionRepoSingleton.getUIActionFromData(action).content()} ))} @@ -131,8 +131,8 @@ const State = ({ state, isInitialState, idx, onClickEditState, onClickDeleteStat No transitions. Edit state to add transitions. ) : ( - {state.transitions.map((transition) => ( - + {state.transitions.map((transition, index) => ( + diff --git a/public/pages/VisualCreatePolicy/components/States/States.tsx b/public/pages/VisualCreatePolicy/components/States/States.tsx index 9090699af..5be62f12c 100644 --- a/public/pages/VisualCreatePolicy/components/States/States.tsx +++ b/public/pages/VisualCreatePolicy/components/States/States.tsx @@ -55,7 +55,7 @@ const States = ({ onOpenFlyout, policy, onClickEditState, onClickDeleteState, on
{!isReadOnly && ( <> - + + + + ); +} function renderErrorNotification(errorNotification: IErrorNotification) { return { @@ -19,7 +28,7 @@ function renderErrorNotification(errorNotification: IErrorNotification) { {(services: BrowserServices | null) => services && ( - {}} @@ -39,7 +48,7 @@ function renderErrorNotification(errorNotification: IErrorNotification) { describe(" spec", () => { it("renders the component", () => { const { container } = render( - {}} diff --git a/public/pages/VisualCreatePolicy/containers/ErrorNotification/ErrorNotification.tsx b/public/pages/VisualCreatePolicy/containers/ErrorNotification/ErrorNotification.tsx index 634b837b8..8ae46f301 100644 --- a/public/pages/VisualCreatePolicy/containers/ErrorNotification/ErrorNotification.tsx +++ b/public/pages/VisualCreatePolicy/containers/ErrorNotification/ErrorNotification.tsx @@ -17,7 +17,7 @@ import ChannelNotification from "../../components/ChannelNotification"; import LegacyNotification from "../../components/LegacyNotification"; import { ERROR_NOTIFICATION_DOCUMENTATION_URL } from "../../../../utils/constants"; -interface ErrorNotificationProps { +export interface ErrorNotificationProps { errorNotification: IErrorNotification | undefined; errorNotificationJsonString: string; onChangeChannelId: (value: ChangeEvent) => void;