From 9ef5c9025d6a1bd9b1c9ecb756f360bb55d3e979 Mon Sep 17 00:00:00 2001 From: Ramakrishna Chilaka Date: Thu, 21 Mar 2024 07:00:54 +0530 Subject: [PATCH] refactoring to common hooks and MDSEnabledComponent Signed-off-by: Ramakrishna Chilaka --- .../MDSEnabledComponent.tsx | 52 +++++++++++++++++++ .../components/MDSEnabledComponent/index.ts | 4 ++ public/index_management_app.tsx | 2 +- .../Aliases/containers/Aliases/Aliases.tsx | 30 +++-------- .../ComposableTemplates.tsx | 32 ++++-------- .../CreateComposableTemplate.tsx | 25 ++------- .../TemplateDetail/TemplateDetail.tsx | 1 + .../CreateDataStream/CreateDataStream.tsx | 25 ++------- .../containers/CreateIndex/CreateIndex.tsx | 23 ++------ .../containers/IndexForm/index.tsx | 23 ++++---- .../CreateIndexTemplate.tsx | 25 ++------- .../TemplateDetail/TemplateDetail.tsx | 1 + .../containers/DataStreams/DataStreams.tsx | 32 +++--------- .../DeleteDataStreamsModal.tsx | 4 -- .../container/ForceMerge/ForceMerge.tsx | 17 +----- .../containers/IndexDetail/IndexDetail.tsx | 37 ++----------- .../Indices/containers/IndexDetail/index.tsx | 14 +---- .../containers/Indices/Indices.test.tsx | 11 ++-- .../Indices/containers/Indices/Indices.tsx | 51 +++--------------- public/pages/Main/Main.tsx | 18 +++---- .../Reindex/container/Reindex/Reindex.tsx | 9 +++- .../Rollover/containers/Rollover/Rollover.tsx | 17 ++---- .../container/SplitIndex/SplitIndex.tsx | 3 ++ .../containers/Templates/Templates.tsx | 30 +++-------- public/services/DataSourceMenuContext.ts | 2 +- server/plugin.ts | 2 +- server/routes/aliases.ts | 4 +- 27 files changed, 166 insertions(+), 328 deletions(-) create mode 100644 public/components/MDSEnabledComponent/MDSEnabledComponent.tsx create mode 100644 public/components/MDSEnabledComponent/index.ts diff --git a/public/components/MDSEnabledComponent/MDSEnabledComponent.tsx b/public/components/MDSEnabledComponent/MDSEnabledComponent.tsx new file mode 100644 index 000000000..305b16840 --- /dev/null +++ b/public/components/MDSEnabledComponent/MDSEnabledComponent.tsx @@ -0,0 +1,52 @@ +import React, { useContext, useEffect } from "react"; +import { DataSourceMenuContext, DataSourceMenuProperties } from "../../services/DataSourceMenuContext"; +import { useHistory } from "react-router"; +import queryString from "query-string"; + +export default class MDSEnabledComponent< + Props extends DataSourceMenuProperties, + State extends DataSourceMenuProperties +> extends React.Component { + constructor(props: Props) { + super(props); + this.state = { + dataSourceId: props.dataSourceId, + dataSourceLabel: props.dataSourceLabel, + multiDataSourceEnabled: props.multiDataSourceEnabled, + } as State; + } + + static getDerivedStateFromProps( + nextProps: Props, + prevState: State + ) { + // static members cannot reference class type parameters + if ( + nextProps.multiDataSourceEnabled && + (nextProps.dataSourceId != prevState.dataSourceId || nextProps.dataSourceLabel != prevState.dataSourceLabel) + ) { + return { + dataSourceId: nextProps.dataSourceId, + dataSourceLabel: nextProps.dataSourceLabel, + }; + } + return null; + } +} + +export function useUpdateUrlWithDataSourceProperties() { + const dataSourceMenuProps = useContext(DataSourceMenuContext); + const { dataSourceId, dataSourceLabel, multiDataSourceEnabled } = dataSourceMenuProps; + if (multiDataSourceEnabled) { + // mds flag can't change while the app is loaded + const history = useHistory(); + useEffect(() => { + history.replace({ + search: queryString.stringify({ + dataSourceId, + dataSourceLabel, + }), + }); + }, [dataSourceId, dataSourceLabel]); + } +} diff --git a/public/components/MDSEnabledComponent/index.ts b/public/components/MDSEnabledComponent/index.ts new file mode 100644 index 000000000..f711b2b29 --- /dev/null +++ b/public/components/MDSEnabledComponent/index.ts @@ -0,0 +1,4 @@ +import MDSEnabledComponent from "./MDSEnabledComponent"; + +export default MDSEnabledComponent; +export * from "./MDSEnabledComponent"; diff --git a/public/index_management_app.tsx b/public/index_management_app.tsx index 40e5c7b6f..17429d6c9 100644 --- a/public/index_management_app.tsx +++ b/public/index_management_app.tsx @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { CoreStart, AppMountParameters } from "opensearch-dashboards/public"; +import { AppMountParameters, CoreStart } from "opensearch-dashboards/public"; import React from "react"; import ReactDOM from "react-dom"; import { HashRouter as Router, Route } from "react-router-dom"; diff --git a/public/pages/Aliases/containers/Aliases/Aliases.tsx b/public/pages/Aliases/containers/Aliases/Aliases.tsx index 0725ecbf7..b63f51a62 100644 --- a/public/pages/Aliases/containers/Aliases/Aliases.tsx +++ b/public/pages/Aliases/containers/Aliases/Aliases.tsx @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -import React, { Component, useContext, useState } from "react"; +import React, { useContext, useState } from "react"; import _, { isEqual } from "lodash"; import { RouteComponentProps } from "react-router-dom"; import queryString from "query-string"; @@ -36,16 +36,14 @@ import IndexControls, { SearchControlsProps } from "../../components/IndexContro import CreateAlias from "../CreateAlias"; import AliasesActions from "../AliasActions"; import { CoreStart } from "opensearch-dashboards/public"; -import { DataSourceMenuContext } from "../../../../services/DataSourceMenuContext"; +import { DataSourceMenuContext, DataSourceMenuProperties } from "../../../../services/DataSourceMenuContext"; +import MDSEnabledComponent from "../../../../components/MDSEnabledComponent"; -interface AliasesProps extends RouteComponentProps { +interface AliasesProps extends RouteComponentProps, DataSourceMenuProperties { commonService: CommonService; - dataSourceId: string; - dataSourceLabel: string; - multiDataSourceEnabled: boolean; } -interface AliasesState { +interface AliasesState extends DataSourceMenuProperties { totalAliases: number; from: string; size: string; @@ -59,8 +57,6 @@ interface AliasesState { loading: boolean; aliasCreateFlyoutVisible: boolean; aliasEditFlyoutVisible: boolean; - dataSourceId: string; - dataSourceLabel: string; } function IndexNameDisplay(props: { indices: string[]; alias: string }) { @@ -117,9 +113,8 @@ const defaultFilter = { status: DEFAULT_QUERY_PARAMS.status, }; -class Aliases extends Component { +class Aliases extends MDSEnabledComponent { static contextType = CoreServicesContext; - constructor(props: AliasesProps) { super(props); const { @@ -139,6 +134,7 @@ class Aliases extends Component { }; this.state = { ...defaultFilter, + ...this.state, totalAliases: 0, from, size, @@ -152,8 +148,6 @@ class Aliases extends Component { aliasCreateFlyoutVisible: false, aliasEditFlyoutVisible: false, editingItem: null, - dataSourceId: this.props.dataSourceId, - dataSourceLabel: this.props.dataSourceLabel, }; this.getAliases = _.debounce(this.getAliases, 500, { leading: true }); @@ -173,16 +167,6 @@ class Aliases extends Component { }, {} as AliasesState); }; - static getDerivedStateFromProps(nextProps: AliasesProps, prevState: AliasesState) { - if (nextProps.dataSourceId != prevState.dataSourceId || nextProps.dataSourceLabel != prevState.dataSourceLabel) { - return { - dataSourceId: nextProps.dataSourceId, - dataSourceLabel: nextProps.dataSourceLabel, - }; - } - return null; - } - async componentDidUpdate(prevProps: AliasesProps, prevState: AliasesState) { const prevQuery = this.getQueryState(prevState); const currQuery = this.getQueryState(this.state); diff --git a/public/pages/ComposableTemplates/containers/ComposableTemplates/ComposableTemplates.tsx b/public/pages/ComposableTemplates/containers/ComposableTemplates/ComposableTemplates.tsx index 18999b929..066f63ac5 100644 --- a/public/pages/ComposableTemplates/containers/ComposableTemplates/ComposableTemplates.tsx +++ b/public/pages/ComposableTemplates/containers/ComposableTemplates/ComposableTemplates.tsx @@ -3,8 +3,8 @@ * SPDX-License-Identifier: Apache-2.0 */ -import React, { Component, useContext } from "react"; -import _, { debounce, isEqual, get } from "lodash"; +import React, { useContext } from "react"; +import { debounce, isEqual, get } from "lodash"; import { Link, RouteComponentProps } from "react-router-dom"; import queryString from "query-string"; import { @@ -38,15 +38,13 @@ import ComponentTemplateBadge from "../../../../components/ComponentTemplateBadg import AssociatedTemplatesModal from "../AssociatedTemplatesModal"; import { useComponentMapTemplate } from "../../utils/hooks"; import "./index.scss"; -import { DataSourceMenuContext } from "../../../../services/DataSourceMenuContext"; +import { DataSourceMenuContext, DataSourceMenuProperties } from "../../../../services/DataSourceMenuContext"; +import MDSEnabledComponent from "../../../../components/MDSEnabledComponent"; -interface ComposableTemplatesProps extends RouteComponentProps { +interface ComposableTemplatesProps extends RouteComponentProps, DataSourceMenuProperties { commonService: CommonService; componentMapTemplate: Record; loading: boolean; - dataSourceId: string; - dataSourceLabel: string; - multiDataSourceEnabled: boolean; } type ComposableTemplatesState = { @@ -58,15 +56,14 @@ type ComposableTemplatesState = { selectedItems: ICatComposableTemplate[]; composableTemplates: ICatComposableTemplate[]; loading: boolean; - dataSourceId: string; - dataSourceLabel: string; -} & SearchControlsProps["value"]; +} & SearchControlsProps["value"] & + DataSourceMenuProperties; const defaultFilter = { search: DEFAULT_QUERY_PARAMS.search, }; -class ComposableTemplates extends Component { +class ComposableTemplates extends MDSEnabledComponent { static contextType = CoreServicesContext; constructor(props: ComposableTemplatesProps) { super(props); @@ -85,6 +82,7 @@ class ComposableTemplates extends Component Promise | undefined; - static getDerivedStateFromProps(nextProps: ComposableTemplatesProps, prevState: ComposableTemplatesState) { - if (nextProps.dataSourceId != prevState.dataSourceId || nextProps.dataSourceLabel != prevState.dataSourceLabel) { - return { - dataSourceId: nextProps.dataSourceId, - dataSourceLabel: nextProps.dataSourceLabel, - }; - } - return null; - } - async componentDidUpdate(prevProps: ComposableTemplatesProps, prevState: ComposableTemplatesState) { const prevQuery = this.getQueryState(prevState); const currQuery = this.getQueryState(this.state); diff --git a/public/pages/CreateComposableTemplate/containers/CreateComposableTemplate/CreateComposableTemplate.tsx b/public/pages/CreateComposableTemplate/containers/CreateComposableTemplate/CreateComposableTemplate.tsx index b69af0954..2d31b6c0d 100644 --- a/public/pages/CreateComposableTemplate/containers/CreateComposableTemplate/CreateComposableTemplate.tsx +++ b/public/pages/CreateComposableTemplate/containers/CreateComposableTemplate/CreateComposableTemplate.tsx @@ -9,14 +9,10 @@ import TemplateDetail from "../TemplateDetail"; import { BREADCRUMBS, ROUTES } from "../../../../utils/constants"; import { CoreServicesContext } from "../../../../components/core_services"; import { isEqual } from "lodash"; -import queryString from "query-string"; -import { DataSourceMenuContext } from "../../../../services/DataSourceMenuContext"; +import { DataSourceMenuContext, DataSourceMenuProperties } from "../../../../services/DataSourceMenuContext"; +import { useUpdateUrlWithDataSourceProperties } from "../../../../components/MDSEnabledComponent"; -interface CreateComposableTemplateProps extends RouteComponentProps<{ template?: string; mode?: string }> { - dataSourceId: string; - dataSourceLabel: string; - multiDataSourceEnabled: boolean; -} +interface CreateComposableTemplateProps extends RouteComponentProps<{ template?: string; mode?: string }>, DataSourceMenuProperties {} class CreateComposableTemplate extends Component { static contextType = CoreServicesContext; @@ -49,28 +45,14 @@ class CreateComposableTemplate extends Component this.context.chrome.setBreadcrumbs([BREADCRUMBS.INDEX_MANAGEMENT, BREADCRUMBS.COMPOSABLE_TEMPLATES, lastBread]); } - updateDataSourcePropsInUrl() { - if (this.props.multiDataSourceEnabled) { - this.props.history.replace({ - ...this.props.location, - search: queryString.stringify({ - dataSourceId: this.props.dataSourceId, - dataSourceLabel: this.props.dataSourceLabel, - }), - }); - } - } - componentDidUpdate(prevProps: Readonly): void { if (!isEqual(prevProps, this.props)) { this.setBreadCrumb(); - this.updateDataSourcePropsInUrl(); } } componentDidMount = async (): Promise => { this.setBreadCrumb(); - this.updateDataSourcePropsInUrl(); }; onCancel = (): void => { @@ -95,5 +77,6 @@ class CreateComposableTemplate extends Component export default function (props: CreateComposableTemplateProps) { const dataSourceMenuProps = useContext(DataSourceMenuContext); + useUpdateUrlWithDataSourceProperties(); return ; } diff --git a/public/pages/CreateComposableTemplate/containers/TemplateDetail/TemplateDetail.tsx b/public/pages/CreateComposableTemplate/containers/TemplateDetail/TemplateDetail.tsx index cb76dd64d..a475cda3c 100644 --- a/public/pages/CreateComposableTemplate/containers/TemplateDetail/TemplateDetail.tsx +++ b/public/pages/CreateComposableTemplate/containers/TemplateDetail/TemplateDetail.tsx @@ -211,6 +211,7 @@ const TemplateDetail = (props: TemplateDetailProps, ref: Ref + {/*{^ Passing dataSourceId as the key to force unmount and remount IndexAlias so as to refresh aliases in case of datasource changes }*/} diff --git a/public/pages/CreateDataStream/containers/CreateDataStream/CreateDataStream.tsx b/public/pages/CreateDataStream/containers/CreateDataStream/CreateDataStream.tsx index a37f54a26..fda04b2ce 100644 --- a/public/pages/CreateDataStream/containers/CreateDataStream/CreateDataStream.tsx +++ b/public/pages/CreateDataStream/containers/CreateDataStream/CreateDataStream.tsx @@ -9,14 +9,10 @@ import DataStreamDetail from "../DataStreamDetail"; import { BREADCRUMBS, ROUTES } from "../../../../utils/constants"; import { CoreServicesContext } from "../../../../components/core_services"; import { isEqual } from "lodash"; -import queryString from "query-string"; -import { DataSourceMenuContext } from "../../../../services/DataSourceMenuContext"; +import { DataSourceMenuContext, DataSourceMenuProperties } from "../../../../services/DataSourceMenuContext"; +import { useUpdateUrlWithDataSourceProperties } from "../../../../components/MDSEnabledComponent"; -interface CreateDataStreamProps extends RouteComponentProps<{ dataStream?: string }> { - dataSourceId: string; - dataSourceLabel: string; - multiDataSourceEnabled: boolean; -} +interface CreateDataStreamProps extends RouteComponentProps<{ dataStream?: string }>, DataSourceMenuProperties {} class CreateDataStream extends Component { static contextType = CoreServicesContext; @@ -39,28 +35,14 @@ class CreateDataStream extends Component { this.context.chrome.setBreadcrumbs([BREADCRUMBS.INDEX_MANAGEMENT, BREADCRUMBS.DATA_STREAMS, lastBread]); } - updateDataSourcePropsInUrl() { - if (this.props.multiDataSourceEnabled) { - this.props.history.replace({ - ...this.props.location, - search: queryString.stringify({ - dataSourceId: this.props.dataSourceId, - dataSourceLabel: this.props.dataSourceLabel, - }), - }); - } - } - componentDidUpdate(prevProps: Readonly): void { if (!isEqual(prevProps, this.props)) { this.setBreadCrumb(); - this.updateDataSourcePropsInUrl(); } } componentDidMount = async (): Promise => { this.setBreadCrumb(); - this.updateDataSourcePropsInUrl(); }; onCancel = (): void => { @@ -84,5 +66,6 @@ class CreateDataStream extends Component { export default function (props: CreateDataStreamProps) { const dataSourceMenuProps = useContext(DataSourceMenuContext); + useUpdateUrlWithDataSourceProperties(); return ; } diff --git a/public/pages/CreateIndex/containers/CreateIndex/CreateIndex.tsx b/public/pages/CreateIndex/containers/CreateIndex/CreateIndex.tsx index 2319d5696..f39eca7a3 100644 --- a/public/pages/CreateIndex/containers/CreateIndex/CreateIndex.tsx +++ b/public/pages/CreateIndex/containers/CreateIndex/CreateIndex.tsx @@ -10,15 +10,12 @@ import IndexForm from "../IndexForm"; import { BREADCRUMBS, IndicesUpdateMode, ROUTES } from "../../../../utils/constants"; import { CoreServicesContext } from "../../../../components/core_services"; import { CommonService } from "../../../../services/index"; -import { DataSourceMenuContext } from "../../../../services/DataSourceMenuContext"; -import queryString from "query-string"; +import { DataSourceMenuContext, DataSourceMenuProperties } from "../../../../services/DataSourceMenuContext"; +import { useUpdateUrlWithDataSourceProperties } from "../../../../components/MDSEnabledComponent"; -interface CreateIndexProps extends RouteComponentProps<{ index?: string; mode?: IndicesUpdateMode }> { +interface CreateIndexProps extends RouteComponentProps<{ index?: string; mode?: IndicesUpdateMode }>, DataSourceMenuProperties { isEdit?: boolean; commonService: CommonService; - dataSourceId: string; - dataSourceLabel: string; - multiDataSourceEnabled: boolean; } export class CreateIndex extends Component { @@ -45,19 +42,6 @@ export class CreateIndex extends Component { this.props.history.push(ROUTES.INDICES); }; - componentDidUpdate(prevProps: Readonly) { - if (this.props.multiDataSourceEnabled) { - if (prevProps.dataSourceId !== this.props.dataSourceId || prevProps.dataSourceLabel !== this.props.dataSourceLabel) { - this.props.history.replace({ - search: queryString.stringify({ - dataSourceId: this.props.dataSourceId, - dataSourceLabel: this.props.dataSourceLabel, - }), - }); - } - } - } - render() { const isEdit = this.isEdit; @@ -81,5 +65,6 @@ export class CreateIndex extends Component { export default function (props: CreateIndexProps) { const dataSourceMenuProperties = useContext(DataSourceMenuContext); + useUpdateUrlWithDataSourceProperties(); return ; } diff --git a/public/pages/CreateIndex/containers/IndexForm/index.tsx b/public/pages/CreateIndex/containers/IndexForm/index.tsx index c47d8c681..46300c96b 100644 --- a/public/pages/CreateIndex/containers/IndexForm/index.tsx +++ b/public/pages/CreateIndex/containers/IndexForm/index.tsx @@ -5,7 +5,7 @@ import React, { Component, forwardRef, useContext } from "react"; import { EuiSpacer, EuiFlexGroup, EuiFlexItem, EuiButton, EuiButtonEmpty, EuiLoadingSpinner } from "@elastic/eui"; -import _, { get, set, differenceWith, isEqual, merge } from "lodash"; +import { get, set, differenceWith, isEqual, merge } from "lodash"; import { diffArrays } from "diff"; import flattern from "flat"; import { CoreStart } from "opensearch-dashboards/public"; @@ -17,6 +17,7 @@ import { transformArrayToObject, transformObjectToArray } from "../../../../comp import { ServerResponse } from "../../../../../server/models/types"; import { BrowserServices } from "../../../../models/interfaces"; import { ServicesContext } from "../../../../services"; +import { DataSourceMenuProperties } from "../../../../services/DataSourceMenuContext"; export const getAliasActionsByDiffArray = ( oldAliases: string[], @@ -45,14 +46,13 @@ export const getAliasActionsByDiffArray = ( }, [] as IAliasAction[]); }; -export interface IndexFormProps extends Pick { +export interface IndexFormProps extends Pick, DataSourceMenuProperties { index?: string; value?: Partial; mode?: IndicesUpdateMode; onCancel?: () => void; onSubmitSuccess?: (indexName: string) => void; hideButtons?: boolean; - dataSourceId: string; } interface CreateIndexState { @@ -60,7 +60,6 @@ interface CreateIndexState { oldIndexDetail?: IndexItem; isSubmitting: boolean; loading: boolean; - dataSourceId: string; } const findLineNumber = (regexp: RegExp, str: string): number => { @@ -98,7 +97,6 @@ export class IndexForm extends Component (this.indexDetailRef = ref)} diff --git a/public/pages/CreateIndexTemplate/containers/CreateIndexTemplate/CreateIndexTemplate.tsx b/public/pages/CreateIndexTemplate/containers/CreateIndexTemplate/CreateIndexTemplate.tsx index bb2980398..44c693074 100644 --- a/public/pages/CreateIndexTemplate/containers/CreateIndexTemplate/CreateIndexTemplate.tsx +++ b/public/pages/CreateIndexTemplate/containers/CreateIndexTemplate/CreateIndexTemplate.tsx @@ -9,14 +9,10 @@ import { isEqual } from "lodash"; import TemplateDetail from "../TemplateDetail"; import { BREADCRUMBS, ROUTES } from "../../../../utils/constants"; import { CoreServicesContext } from "../../../../components/core_services"; -import { DataSourceMenuContext } from "../../../../services/DataSourceMenuContext"; -import queryString from "query-string"; +import { DataSourceMenuContext, DataSourceMenuProperties } from "../../../../services/DataSourceMenuContext"; +import { useUpdateUrlWithDataSourceProperties } from "../../../../components/MDSEnabledComponent"; -interface CreateIndexTemplateProps extends RouteComponentProps<{ template?: string; mode?: string }> { - dataSourceId: string; - dataSourceLabel: string; - multiDataSourceEnabled: boolean; -} +interface CreateIndexTemplateProps extends RouteComponentProps<{ template?: string; mode?: string }>, DataSourceMenuProperties {} class CreateIndexTemplate extends Component { static contextType = CoreServicesContext; @@ -48,28 +44,14 @@ class CreateIndexTemplate extends Component { this.context.chrome.setBreadcrumbs([BREADCRUMBS.INDEX_MANAGEMENT, BREADCRUMBS.TEMPLATES, lastBread]); } - updateDataSourcePropsInUrl() { - if (this.props.multiDataSourceEnabled) { - this.props.history.replace({ - ...this.props.location, - search: queryString.stringify({ - dataSourceId: this.props.dataSourceId, - dataSourceLabel: this.props.dataSourceLabel, - }), - }); - } - } - componentDidUpdate(prevProps: Readonly): void { if (!isEqual(prevProps, this.props)) { this.setBreadCrumb(); - this.updateDataSourcePropsInUrl(); } } componentDidMount = async (): Promise => { this.setBreadCrumb(); - this.updateDataSourcePropsInUrl(); }; onCancel = (): void => { @@ -94,5 +76,6 @@ class CreateIndexTemplate extends Component { export default function (props: CreateIndexTemplateProps) { const dataSourceMenuProps = useContext(DataSourceMenuContext); + useUpdateUrlWithDataSourceProperties(); return ; } diff --git a/public/pages/CreateIndexTemplate/containers/TemplateDetail/TemplateDetail.tsx b/public/pages/CreateIndexTemplate/containers/TemplateDetail/TemplateDetail.tsx index 63c4e90ab..a1c747e9b 100644 --- a/public/pages/CreateIndexTemplate/containers/TemplateDetail/TemplateDetail.tsx +++ b/public/pages/CreateIndexTemplate/containers/TemplateDetail/TemplateDetail.tsx @@ -318,6 +318,7 @@ const TemplateDetail = (props: TemplateDetailProps, ref: Ref) => > + {/*{^ Passing dataSourceId as the key to force unmount and remount IndexAlias so as to refresh aliases in case of datasource changes }*/} diff --git a/public/pages/DataStreams/containers/DataStreams/DataStreams.tsx b/public/pages/DataStreams/containers/DataStreams/DataStreams.tsx index f911defe2..eb33cc573 100644 --- a/public/pages/DataStreams/containers/DataStreams/DataStreams.tsx +++ b/public/pages/DataStreams/containers/DataStreams/DataStreams.tsx @@ -4,7 +4,7 @@ */ import React, { Component, useContext } from "react"; -import _, { debounce, isEqual } from "lodash"; +import { debounce, isEqual } from "lodash"; import { Link, RouteComponentProps } from "react-router-dom"; import queryString from "query-string"; import { @@ -35,13 +35,11 @@ import IndexControls, { SearchControlsProps } from "../../components/IndexContro import DataStreamsActions from "../DataStreamsActions"; import { CoreStart } from "opensearch-dashboards/public"; import { DataStream } from "../../../../../server/models/interfaces"; -import { DataSourceMenuContext } from "../../../../services/DataSourceMenuContext"; +import { DataSourceMenuContext, DataSourceMenuProperties } from "../../../../services/DataSourceMenuContext"; +import MDSEnabledComponent from "../../../../components/MDSEnabledComponent"; -interface DataStreamsProps extends RouteComponentProps { +interface DataStreamsProps extends RouteComponentProps, DataSourceMenuProperties { commonService: CommonService; - dataSourceId: string; - dataSourceLabel: string; - multiDataSourceEnabled: boolean; } type DataStreamsState = { @@ -53,9 +51,8 @@ type DataStreamsState = { selectedItems: DataStreamWithStats[]; dataStreams: DataStreamWithStats[]; loading: boolean; - dataSourceId: string; - dataSourceLabel: string; -} & SearchControlsProps["value"]; +} & SearchControlsProps["value"] & + DataSourceMenuProperties; const defaultFilter = { search: DEFAULT_QUERY_PARAMS.search, @@ -67,7 +64,7 @@ export const healthExplanation = { red: "One or more primary shards are unassigned, so some data is unavailable.", }; -class DataStreams extends Component { +class DataStreams extends MDSEnabledComponent { static contextType = CoreServicesContext; constructor(props: DataStreamsProps) { super(props); @@ -86,6 +83,7 @@ class DataStreams extends Component { }; this.state = { ...defaultFilter, + ...this.state, totalDataStreams: 0, from, size, @@ -95,23 +93,10 @@ class DataStreams extends Component { selectedItems: [], dataStreams: [], loading: false, - dataSourceId: props.dataSourceId, - dataSourceLabel: props.dataSourceLabel, }; this.getDataStreams = debounce(this.getDataStreams, 500, { leading: true }); } - - static getDerivedStateFromProps(nextProps: DataStreamsProps, prevState: DataStreamsState) { - if (nextProps.dataSourceId != prevState.dataSourceId || nextProps.dataSourceLabel != prevState.dataSourceLabel) { - return { - dataSourceId: nextProps.dataSourceId, - dataSourceLabel: nextProps.dataSourceLabel, - }; - } - return null; - } - async componentDidUpdate(prevProps: DataStreamsProps, prevState: DataStreamsState) { const prevQuery = this.getQueryState(prevState); const currQuery = this.getQueryState(this.state); @@ -119,7 +104,6 @@ class DataStreams extends Component { await this.getDataStreams(); } } - componentDidMount() { this.context.chrome.setBreadcrumbs([BREADCRUMBS.INDEX_MANAGEMENT, BREADCRUMBS.DATA_STREAMS]); this.getDataStreams(); diff --git a/public/pages/DataStreams/containers/DeleteDataStreamsModal/DeleteDataStreamsModal.tsx b/public/pages/DataStreams/containers/DeleteDataStreamsModal/DeleteDataStreamsModal.tsx index 2a56bd3bf..0caf47937 100644 --- a/public/pages/DataStreams/containers/DeleteDataStreamsModal/DeleteDataStreamsModal.tsx +++ b/public/pages/DataStreams/containers/DeleteDataStreamsModal/DeleteDataStreamsModal.tsx @@ -8,7 +8,6 @@ import { CoreStart } from "opensearch-dashboards/public"; import { ServicesContext } from "../../../../services"; import { CoreServicesContext } from "../../../../components/core_services"; import DeleteModal from "../../../../components/DeleteModal"; -import { DataSourceMenuContext } from "../../../../services/DataSourceMenuContext"; interface DeleteTemplateModalProps { selectedItems: string[]; @@ -21,8 +20,6 @@ export default function DeleteTemplateModal(props: DeleteTemplateModalProps) { const { onClose, visible, selectedItems, onDelete } = props; const services = useContext(ServicesContext); const coreServices = useContext(CoreServicesContext) as CoreStart; - const dataSourceMenuProps = useContext(DataSourceMenuContext); - const { dataSourceId } = dataSourceMenuProps; const onConfirm = useCallback(async () => { if (services) { @@ -31,7 +28,6 @@ export default function DeleteTemplateModal(props: DeleteTemplateModalProps) { data: { path: `/_data_stream/${selectedItems.join(",")}`, method: "DELETE", - dataSourceId, }, }); if (result && result.ok) { diff --git a/public/pages/ForceMerge/container/ForceMerge/ForceMerge.tsx b/public/pages/ForceMerge/container/ForceMerge/ForceMerge.tsx index 5b9299567..58a4fef0e 100644 --- a/public/pages/ForceMerge/container/ForceMerge/ForceMerge.tsx +++ b/public/pages/ForceMerge/container/ForceMerge/ForceMerge.tsx @@ -4,7 +4,6 @@ */ import { EuiButton, EuiButtonEmpty, EuiButtonIcon, EuiCallOut, EuiFlexGroup, EuiFlexItem, EuiSpacer, EuiTitle } from "@elastic/eui"; -import _ from "lodash"; import React, { useContext, useEffect, useRef, useState } from "react"; import { RouteComponentProps } from "react-router-dom"; import { CoreStart } from "opensearch-dashboards/public"; @@ -24,8 +23,7 @@ import { ListenType } from "../../../../lib/JobScheduler"; import NotificationConfig, { NotificationConfigRef } from "../../../../containers/NotificationConfig"; import { ActionType } from "../../../Notifications/constant"; import { getClusterInfo } from "../../../../utils/helpers"; -import { DataSourceMenuContext } from "../../../../services/DataSourceMenuContext"; -import { useHistory } from "react-router"; +import { useUpdateUrlWithDataSourceProperties } from "../../../../components/MDSEnabledComponent"; interface ForceMergeProps extends RouteComponentProps<{ indexes?: string }> { services: BrowserServices; @@ -60,22 +58,11 @@ export default function ForceMergeWrapper(props: Omit { - history.replace({ - search: `?dataSourceId=${dataSourceId}&dataSourceLabel=${dataSourceLabel}`, - }); - }, [dataSourceId, dataSourceLabel]); - } + useUpdateUrlWithDataSourceProperties(); const onCancel = () => { props.history.push(ROUTES.INDICES); }; - const onClickAction = async () => { const { errors, values } = await field.validatePromise(); if (advancedSettingsOpen) { diff --git a/public/pages/IndexDetail/containers/IndexDetail/IndexDetail.tsx b/public/pages/IndexDetail/containers/IndexDetail/IndexDetail.tsx index 78a012392..cf798138b 100644 --- a/public/pages/IndexDetail/containers/IndexDetail/IndexDetail.tsx +++ b/public/pages/IndexDetail/containers/IndexDetail/IndexDetail.tsx @@ -30,8 +30,7 @@ import { Modal } from "../../../../components/Modal"; import { IFinalDetail } from "./interface"; import { OVERVIEW_DISPLAY_INFO } from "./constants"; import { EVENT_MAP, destroyListener, listenEvent } from "../../../../JobHandler"; -import { DataSourceMenuContext } from "../../../../services/DataSourceMenuContext"; -import { useHistory } from "react-router"; +import { useUpdateUrlWithDataSourceProperties } from "../../../../components/MDSEnabledComponent"; export interface IndexDetailModalProps extends RouteComponentProps<{ index: string }> {} @@ -52,17 +51,7 @@ export default function IndexDetail(props: IndexDetailModalProps) { }; }, [record, detail]); const services = useContext(ServicesContext) as BrowserServices; - const dataSourceMenuProps = useContext(DataSourceMenuContext); - const { dataSourceId, dataSourceLabel, multiDataSourceEnabled } = dataSourceMenuProps; - if (multiDataSourceEnabled) { - // mds flag can't change while the app is loaded - const history = useHistory(); - useEffect(() => { - history.replace({ - search: `?dataSourceId=${dataSourceId}&dataSourceLabel=${dataSourceLabel}`, - }); - }, [dataSourceId, dataSourceLabel]); - } + useUpdateUrlWithDataSourceProperties(); const fetchIndicesDetail = () => services.commonService @@ -70,7 +59,6 @@ export default function IndexDetail(props: IndexDetailModalProps) { endpoint: "indices.get", data: { index, - dataSourceId, }, }) .then((res) => { @@ -160,12 +148,7 @@ export default function IndexDetail(props: IndexDetailModalProps) { - + ), @@ -207,12 +190,7 @@ export default function IndexDetail(props: IndexDetailModalProps) { } > - + ), @@ -226,12 +204,7 @@ export default function IndexDetail(props: IndexDetailModalProps) { - + ), diff --git a/public/pages/Indices/containers/IndexDetail/index.tsx b/public/pages/Indices/containers/IndexDetail/index.tsx index 0de363709..7104b54d0 100644 --- a/public/pages/Indices/containers/IndexDetail/index.tsx +++ b/public/pages/Indices/containers/IndexDetail/index.tsx @@ -3,11 +3,10 @@ * SPDX-License-Identifier: Apache-2.0 */ -import React, { useContext } from "react"; +import React from "react"; import { EuiButtonEmpty, EuiCopy, EuiLink } from "@elastic/eui"; import { RouteComponentProps } from "react-router-dom"; import { ROUTES } from "../../../../utils/constants"; -import { DataSourceMenuContext } from "../../../../services/DataSourceMenuContext"; export interface IndexDetailModalProps { index: string; @@ -15,8 +14,6 @@ export interface IndexDetailModalProps { } export default function IndexDetail(props: IndexDetailModalProps) { - const dataSourceMenuProps = useContext(DataSourceMenuContext); - const { dataSourceId, dataSourceLabel, multiDataSourceEnabled } = dataSourceMenuProps; const { index, history } = props; return ( @@ -24,14 +21,7 @@ export default function IndexDetail(props: IndexDetailModalProps) { {(copy) => } - { - multiDataSourceEnabled - ? history.push(`${ROUTES.INDEX_DETAIL}/${index}?dataSourceId=${dataSourceId}&dataSourceLabel=${dataSourceLabel}`) - : history.push(`${ROUTES.INDEX_DETAIL}/${index}`); - }} - data-test-subj={`viewIndexDetailButton-${index}`} - > + history.push(`${ROUTES.INDEX_DETAIL}/${index}`)} data-test-subj={`viewIndexDetailButton-${index}`}> {index} diff --git a/public/pages/Indices/containers/Indices/Indices.test.tsx b/public/pages/Indices/containers/Indices/Indices.test.tsx index 2e07a3fe6..4224efc51 100644 --- a/public/pages/Indices/containers/Indices/Indices.test.tsx +++ b/public/pages/Indices/containers/Indices/Indices.test.tsx @@ -5,11 +5,10 @@ import React from "react"; import "@testing-library/jest-dom/extend-expect"; -import { render, fireEvent, waitFor } from "@testing-library/react"; +import { fireEvent, render, waitFor } from "@testing-library/react"; // @ts-ignore import userEvent from "@testing-library/user-event"; -import { Redirect, Route, Switch } from "react-router-dom"; -import { HashRouter as Router } from "react-router-dom"; +import { HashRouter as Router, Redirect, Route, Switch } from "react-router-dom"; import { CoreStart } from "opensearch-dashboards/public"; import { browserServicesMock, coreServicesMock } from "../../../../../test/mocks"; import Indices from "./Indices"; @@ -18,16 +17,16 @@ import { ModalProvider, ModalRoot } from "../../../../components/Modal"; import { ServicesConsumer, ServicesContext } from "../../../../services"; import { BREADCRUMBS, ROUTES } from "../../../../utils/constants"; import { CoreServicesConsumer, CoreServicesContext } from "../../../../components/core_services"; -import { DataSourceMenuContext } from "../../../../services/DataSourceMenuContext"; +import { DataSourceMenuContext, DataSourceMenuProperties } from "../../../../services/DataSourceMenuContext"; function renderWithRouter( Component: React.ComponentType, - data: any = { + data: DataSourceMenuProperties = { dataSourceId: "", dataSourceLabel: "", multiDataSourceEnabled: false, }, - renderFn: any = render + renderFn = render ) { return { ...renderFn( diff --git a/public/pages/Indices/containers/Indices/Indices.tsx b/public/pages/Indices/containers/Indices/Indices.tsx index a0c3ea57f..3955fc507 100644 --- a/public/pages/Indices/containers/Indices/Indices.tsx +++ b/public/pages/Indices/containers/Indices/Indices.tsx @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -import React, { Component, useContext } from "react"; +import React, { useContext } from "react"; import _ from "lodash"; import { RouteComponentProps } from "react-router-dom"; import queryString from "query-string"; @@ -37,17 +37,15 @@ import { SECURITY_EXCEPTION_PREFIX } from "../../../../../server/utils/constants import IndicesActions from "../IndicesActions"; import { destroyListener, EVENT_MAP, listenEvent } from "../../../../JobHandler"; import "./index.scss"; -import { DataSourceMenuContext } from "../../../../services/DataSourceMenuContext"; +import { DataSourceMenuContext, DataSourceMenuProperties } from "../../../../services/DataSourceMenuContext"; +import MDSEnabledComponent from "../../../../components/MDSEnabledComponent"; -interface IndicesProps extends RouteComponentProps { +interface IndicesProps extends RouteComponentProps, DataSourceMenuProperties { indexService: IndexService; commonService: CommonService; - dataSourceId: string; - dataSourceLabel: string; - multiDataSourceEnabled: boolean; } -interface IndicesState { +interface IndicesState extends DataSourceMenuProperties { totalIndices: number; from: number; size: number; @@ -62,30 +60,13 @@ interface IndicesState { isDataStreamColumnVisible: boolean; } -interface IndicesState { - totalIndices: number; - from: number; - size: number; - search: string; - query: Query; - sortField: keyof ManagedCatIndex; - sortDirection: Direction; - selectedItems: ManagedCatIndex[]; - indices: ManagedCatIndex[]; - loadingIndices: boolean; - showDataStreams: boolean; - isDataStreamColumnVisible: boolean; - dataSourceId: string; - dataSourceLabel: string; -} - -export class Indices extends Component { +export class Indices extends MDSEnabledComponent { static contextType = CoreServicesContext; - constructor(props: IndicesProps) { super(props); const { from, size, search, sortField, sortDirection, showDataStreams } = getURLQueryParams(this.props.location); this.state = { + ...this.state, totalIndices: 0, from, size, @@ -98,23 +79,11 @@ export class Indices extends Component { loadingIndices: true, showDataStreams, isDataStreamColumnVisible: showDataStreams, - dataSourceId: props.dataSourceId, - dataSourceLabel: props.dataSourceLabel, }; this.getIndices = _.debounce(this.getIndices, 500, { leading: true }); } - static getDerivedStateFromProps(nextProps: IndicesProps, prevState: IndicesState) { - if (nextProps.dataSourceId != prevState.dataSourceId || nextProps.dataSourceLabel != prevState.dataSourceLabel) { - return { - dataSourceId: nextProps.dataSourceId, - dataSourceLabel: nextProps.dataSourceLabel, - }; - } - return null; - } - async componentDidMount() { this.context.chrome.setBreadcrumbs([BREADCRUMBS.INDEX_MANAGEMENT, BREADCRUMBS.INDICES]); listenEvent(EVENT_MAP.REINDEX_COMPLETE, this.getIndices); @@ -303,11 +272,7 @@ export class Indices extends Component { buttonProps: { fill: true, onClick: () => { - this.props.multiDataSourceEnabled - ? this.props.history.push( - `${ROUTES.CREATE_INDEX}?dataSourceId=${this.state.dataSourceId}&dataSourceLabel=${this.state.dataSourceLabel}` - ) - : this.props.history.push(`${ROUTES.CREATE_INDEX}`); + this.props.history.push(ROUTES.CREATE_INDEX); }, }, }, diff --git a/public/pages/Main/Main.tsx b/public/pages/Main/Main.tsx index f6c1a572d..f4b671cef 100644 --- a/public/pages/Main/Main.tsx +++ b/public/pages/Main/Main.tsx @@ -3,12 +3,11 @@ * SPDX-License-Identifier: Apache-2.0 */ -import React, { Component, createContext } from "react"; +import React, { Component } from "react"; import { Switch, Route, Redirect, RouteComponentProps } from "react-router-dom"; // @ts-ignore -import { EuiSideNav, EuiPage, EuiPageBody, EuiPageSideBar, Query, Direction } from "@elastic/eui"; +import { EuiSideNav, EuiPage, EuiPageBody, EuiPageSideBar } from "@elastic/eui"; import { CoreStart, HttpSetup, MountPoint } from "opensearch-dashboards/public"; -import queryString from "query-string"; import Policies from "../Policies"; import ManagedIndices from "../ManagedIndices"; import Indices from "../Indices"; @@ -19,6 +18,8 @@ import PolicyDetails from "../PolicyDetails/containers/PolicyDetails"; import Rollups from "../Rollups"; import { ModalProvider, ModalRoot } from "../../components/Modal"; import { + CommonService, + IndexService, ManagedIndexService, NotificationService, PolicyService, @@ -58,8 +59,8 @@ import Notifications from "../Notifications"; import ComposableTemplates from "../ComposableTemplates"; import CreateComposableTemplate from "../CreateComposableTemplate"; import { DataSourceMenu } from "../../../../../src/plugins/data_source_management/public"; -import { DataSourceMenuContext } from "../../services/DataSourceMenuContext"; -import { CommonService, IndexService } from "../../services"; +import { DataSourceMenuContext, DataSourceMenuProperties } from "../../services/DataSourceMenuContext"; +import queryString from "query-string"; enum Navigation { IndexManagement = "Index Management", @@ -129,10 +130,7 @@ interface MainProps extends RouteComponentProps { multiDataSourceEnabled: boolean; } -interface MainState { - dataSourceId: string; - dataSourceLabel: string; -} +interface MainState extends Pick {} const dataSourceEnabledPaths: string[] = [ ROUTES.CREATE_DATA_STREAM, @@ -151,6 +149,7 @@ const dataSourceEnabledPaths: string[] = [ ROUTES.CREATE_TEMPLATE, ROUTES.COMPOSABLE_TEMPLATES, ROUTES.CREATE_COMPOSABLE_TEMPLATE, + ROUTES.REINDEX, ]; export default class Main extends Component { @@ -339,6 +338,7 @@ export default class Main extends Component { ROUTES.SPLIT_INDEX, ROUTES.ROLLOVER, ROUTES.INDEX_DETAIL, + ROUTES.REINDEX, ]} render={(props) => ( { +class Reindex extends Component { static contextType = CoreServicesContext; notificationRef: NotificationConfigRef | null = null; constructor(props: ReindexProps) { @@ -710,3 +711,9 @@ export default class Reindex extends Component { ); } } + +export default function (props: ReindexProps) { + // in re-index we don't change the data source picker + useUpdateUrlWithDataSourceProperties(); + return ; +} diff --git a/public/pages/Rollover/containers/Rollover/Rollover.tsx b/public/pages/Rollover/containers/Rollover/Rollover.tsx index 8253c2218..768c2acc5 100644 --- a/public/pages/Rollover/containers/Rollover/Rollover.tsx +++ b/public/pages/Rollover/containers/Rollover/Rollover.tsx @@ -21,9 +21,7 @@ import { getIndexDetail, getOptions, getRolloveredIndex, onSubmit, submitWriteIn import { IRolloverRequestBody } from "../../interface"; import { filterByMinimatch } from "../../../../../utils/helper"; import { SYSTEM_ALIAS } from "../../../../../utils/constants"; -import { DataSourceMenuContext } from "../../../../services/DataSourceMenuContext"; -import { useHistory } from "react-router"; -import { CoreStart } from "opensearch-dashboards/public"; +import { useUpdateUrlWithDataSourceProperties } from "../../../../components/MDSEnabledComponent"; export interface RolloverProps extends RouteComponentProps<{ source?: string }> {} @@ -55,17 +53,8 @@ export default function Rollover(props: RolloverProps) { }, }, }); - const dataSourceMenuProps = useContext(DataSourceMenuContext); - const { dataSourceId, dataSourceLabel, multiDataSourceEnabled } = dataSourceMenuProps; - if (multiDataSourceEnabled) { - // mds flag can't change while the app is loaded - const history = useHistory(); - useEffect(() => { - history.replace({ - search: `?dataSourceId=${dataSourceId}&dataSourceLabel=${dataSourceLabel}`, - }); - }, [dataSourceId, dataSourceLabel]); - } + + useUpdateUrlWithDataSourceProperties(); const onChange = (val?: Record) => { const finalResult = merge({}, tempValue, val); diff --git a/public/pages/SplitIndex/container/SplitIndex/SplitIndex.tsx b/public/pages/SplitIndex/container/SplitIndex/SplitIndex.tsx index 41656608f..494b1951e 100644 --- a/public/pages/SplitIndex/container/SplitIndex/SplitIndex.tsx +++ b/public/pages/SplitIndex/container/SplitIndex/SplitIndex.tsx @@ -28,6 +28,7 @@ import { CoreServicesContext } from "../../../../components/core_services"; import { BREADCRUMBS, ROUTES } from "../../../../utils/constants"; import { EVENT_MAP, destroyListener, listenEvent } from "../../../../JobHandler"; import { ServerResponse } from "../../../../../server/models/types"; +import { useUpdateUrlWithDataSourceProperties } from "../../../../components/MDSEnabledComponent"; interface SplitIndexProps extends RouteComponentProps { commonService: CommonService; @@ -269,5 +270,7 @@ export class SplitIndex extends Component { export default function SplitIndexWrapper(props: Omit) { const services = useContext(ServicesContext) as BrowserServices; const coreService = useContext(CoreServicesContext) as CoreStart; + // in split-index we don't change the data source picker + useUpdateUrlWithDataSourceProperties(); return ; } diff --git a/public/pages/Templates/containers/Templates/Templates.tsx b/public/pages/Templates/containers/Templates/Templates.tsx index e31770c4b..47d3ef8b1 100644 --- a/public/pages/Templates/containers/Templates/Templates.tsx +++ b/public/pages/Templates/containers/Templates/Templates.tsx @@ -4,7 +4,7 @@ */ import React, { Component, useContext } from "react"; -import _, { debounce, isEqual } from "lodash"; +import { debounce, isEqual } from "lodash"; import { Link, RouteComponentProps } from "react-router-dom"; import queryString from "query-string"; import { @@ -39,13 +39,11 @@ import { TemplateConvert } from "../../../CreateIndexTemplate/components/Templat import AssociatedComponentsModal from "../AssociatedComponentsModal"; import DeleteTemplate from "../../components/DeleteTemplate"; import IndexPatternDisplay from "./IndexPatternDisplay"; -import { DataSourceMenuContext } from "../../../../services/DataSourceMenuContext"; +import { DataSourceMenuContext, DataSourceMenuProperties } from "../../../../services/DataSourceMenuContext"; +import MDSEnabledComponent from "../../../../components/MDSEnabledComponent"; -interface TemplatesProps extends RouteComponentProps { +interface TemplatesProps extends RouteComponentProps, DataSourceMenuProperties { commonService: CommonService; - dataSourceId: string; - dataSourceLabel: string; - multiDataSourceEnabled: boolean; } type TemplatesState = { @@ -57,15 +55,14 @@ type TemplatesState = { selectedItems: ITemplate[]; templates: ITemplate[]; loading: boolean; - dataSourceId: string; - dataSourceLabel: string; -} & SearchControlsProps["value"]; +} & SearchControlsProps["value"] & + DataSourceMenuProperties; const defaultFilter = { search: DEFAULT_QUERY_PARAMS.search, }; -class Templates extends Component { +class Templates extends MDSEnabledComponent { static contextType = CoreServicesContext; constructor(props: TemplatesProps) { super(props); @@ -84,6 +81,7 @@ class Templates extends Component { }; this.state = { ...defaultFilter, + ...this.state, totalTemplates: 0, from, size, @@ -93,23 +91,11 @@ class Templates extends Component { selectedItems: [], templates: [], loading: false, - dataSourceId: props.dataSourceId, - dataSourceLabel: props.dataSourceLabel, }; this.getTemplates = debounce(this.getTemplates, 500, { leading: true }); } - static getDerivedStateFromProps(nextProps: TemplatesProps, prevState: TemplatesState) { - if (nextProps.dataSourceId != prevState.dataSourceId || nextProps.dataSourceLabel != prevState.dataSourceLabel) { - return { - dataSourceId: nextProps.dataSourceId, - dataSourceLabel: nextProps.dataSourceLabel, - }; - } - return null; - } - async componentDidUpdate(prevProps: TemplatesProps, prevState: TemplatesState) { const prevQuery = this.getQueryState(prevState); const currQuery = this.getQueryState(this.state); diff --git a/public/services/DataSourceMenuContext.ts b/public/services/DataSourceMenuContext.ts index b24d8d013..3770b1100 100644 --- a/public/services/DataSourceMenuContext.ts +++ b/public/services/DataSourceMenuContext.ts @@ -1,6 +1,6 @@ import { createContext } from "react"; -interface DataSourceMenuProperties { +export interface DataSourceMenuProperties { dataSourceId: string; dataSourceLabel: string; multiDataSourceEnabled: boolean; diff --git a/server/plugin.ts b/server/plugin.ts index 5ce598cb7..8d60434de 100644 --- a/server/plugin.ts +++ b/server/plugin.ts @@ -4,7 +4,7 @@ */ import { IndexManagementPluginSetup, IndexManagementPluginStart } from "."; -import { Plugin, CoreSetup, CoreStart, ILegacyCustomClusterClient, LegacyAPICaller } from "../../../src/core/server"; +import { Plugin, CoreSetup, CoreStart, ILegacyCustomClusterClient } from "../../../src/core/server"; import ismPlugin from "./clusters/ism/ismPlugin"; import { PolicyService, diff --git a/server/routes/aliases.ts b/server/routes/aliases.ts index d022b80cc..aa3eeab58 100644 --- a/server/routes/aliases.ts +++ b/server/routes/aliases.ts @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { schema } from "@osd/config-schema"; +import { schema, Type } from "@osd/config-schema"; import { NodeServices } from "../models/interfaces"; import { NODE_API } from "../../utils/constants"; import { IRouter } from "../../../../src/core/server"; @@ -11,7 +11,7 @@ import { IRouter } from "../../../../src/core/server"; export default function (services: NodeServices, router: IRouter, dataSourceEnabled: boolean = false) { const { aliasService } = services; - let getAliasesQueryParam: any = { + let getAliasesQueryParam: { search: Type; dataSourceId?: Type } = { search: schema.maybe(schema.string()), }; if (dataSourceEnabled) {