From 078bd72cc2bcb3eb2abf7f9b0f1b0a85308d0d50 Mon Sep 17 00:00:00 2001 From: Ramakrishna Chilaka Date: Mon, 25 Mar 2024 10:21:06 +0530 Subject: [PATCH] refactoring types Signed-off-by: Ramakrishna Chilaka --- .../Aliases/containers/Aliases/Aliases.tsx | 3 ++- .../ComposableTemplates.tsx | 2 +- .../CreateComposableTemplate.tsx | 2 +- .../CreateDataStream/CreateDataStream.tsx | 2 +- .../containers/CreateIndex/CreateIndex.tsx | 8 ++++---- .../CreateIndex/containers/IndexForm/index.tsx | 4 +++- .../CreateIndexTemplate.tsx | 9 +++++++-- .../containers/DataStreams/DataStreams.tsx | 2 +- .../Indices/containers/Indices/Indices.tsx | 18 ++++++++++++------ public/pages/Indices/models/interfaces.ts | 2 +- public/pages/Main/Main.tsx | 10 +++++----- .../containers/Templates/Templates.tsx | 2 +- public/services/MDSEnabledClientService.ts | 12 ++++++++---- 13 files changed, 47 insertions(+), 29 deletions(-) diff --git a/public/pages/Aliases/containers/Aliases/Aliases.tsx b/public/pages/Aliases/containers/Aliases/Aliases.tsx index b63f51a62..7e447fa49 100644 --- a/public/pages/Aliases/containers/Aliases/Aliases.tsx +++ b/public/pages/Aliases/containers/Aliases/Aliases.tsx @@ -115,6 +115,7 @@ const defaultFilter = { class Aliases extends MDSEnabledComponent { static contextType = CoreServicesContext; + constructor(props: AliasesProps) { super(props); const { @@ -482,7 +483,7 @@ class Aliases extends MDSEnabledComponent { } } -export default function AliasContainer(props: Omit) { +export default function AliasContainer(props: Omit) { const context = useContext(ServicesContext); const dataSourceMenuProps = useContext(DataSourceMenuContext); return ; diff --git a/public/pages/ComposableTemplates/containers/ComposableTemplates/ComposableTemplates.tsx b/public/pages/ComposableTemplates/containers/ComposableTemplates/ComposableTemplates.tsx index 066f63ac5..826207d70 100644 --- a/public/pages/ComposableTemplates/containers/ComposableTemplates/ComposableTemplates.tsx +++ b/public/pages/ComposableTemplates/containers/ComposableTemplates/ComposableTemplates.tsx @@ -461,7 +461,7 @@ class ComposableTemplates extends MDSEnabledComponent + props: Omit ) { const context = useContext(ServicesContext); const dataSourceMenuProps = useContext(DataSourceMenuContext); diff --git a/public/pages/CreateComposableTemplate/containers/CreateComposableTemplate/CreateComposableTemplate.tsx b/public/pages/CreateComposableTemplate/containers/CreateComposableTemplate/CreateComposableTemplate.tsx index 2d31b6c0d..462dfec12 100644 --- a/public/pages/CreateComposableTemplate/containers/CreateComposableTemplate/CreateComposableTemplate.tsx +++ b/public/pages/CreateComposableTemplate/containers/CreateComposableTemplate/CreateComposableTemplate.tsx @@ -75,7 +75,7 @@ class CreateComposableTemplate extends Component } } -export default function (props: CreateComposableTemplateProps) { +export default function (props: Omit) { const dataSourceMenuProps = useContext(DataSourceMenuContext); useUpdateUrlWithDataSourceProperties(); return ; diff --git a/public/pages/CreateDataStream/containers/CreateDataStream/CreateDataStream.tsx b/public/pages/CreateDataStream/containers/CreateDataStream/CreateDataStream.tsx index fda04b2ce..9a075d855 100644 --- a/public/pages/CreateDataStream/containers/CreateDataStream/CreateDataStream.tsx +++ b/public/pages/CreateDataStream/containers/CreateDataStream/CreateDataStream.tsx @@ -64,7 +64,7 @@ class CreateDataStream extends Component { } } -export default function (props: CreateDataStreamProps) { +export default function (props: Omit) { 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 f39eca7a3..4f64e7f39 100644 --- a/public/pages/CreateIndex/containers/CreateIndex/CreateIndex.tsx +++ b/public/pages/CreateIndex/containers/CreateIndex/CreateIndex.tsx @@ -9,15 +9,15 @@ import { RouteComponentProps } from "react-router-dom"; import IndexForm from "../IndexForm"; import { BREADCRUMBS, IndicesUpdateMode, ROUTES } from "../../../../utils/constants"; import { CoreServicesContext } from "../../../../components/core_services"; -import { CommonService } from "../../../../services/index"; import { DataSourceMenuContext, DataSourceMenuProperties } from "../../../../services/DataSourceMenuContext"; import { useUpdateUrlWithDataSourceProperties } from "../../../../components/MDSEnabledComponent"; -interface CreateIndexProps extends RouteComponentProps<{ index?: string; mode?: IndicesUpdateMode }>, DataSourceMenuProperties { +interface CreateIndexPropsBase extends RouteComponentProps<{ index?: string; mode?: IndicesUpdateMode }> { isEdit?: boolean; - commonService: CommonService; } +interface CreateIndexProps extends CreateIndexPropsBase, DataSourceMenuProperties {} + export class CreateIndex extends Component { static contextType = CoreServicesContext; @@ -63,7 +63,7 @@ export class CreateIndex extends Component { } } -export default function (props: CreateIndexProps) { +export default function (props: CreateIndexPropsBase) { 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 46300c96b..e4bdd0ede 100644 --- a/public/pages/CreateIndex/containers/IndexForm/index.tsx +++ b/public/pages/CreateIndex/containers/IndexForm/index.tsx @@ -46,7 +46,9 @@ export const getAliasActionsByDiffArray = ( }, [] as IAliasAction[]); }; -export interface IndexFormProps extends Pick, DataSourceMenuProperties { +export interface IndexFormProps + extends Pick, + Pick { index?: string; value?: Partial; mode?: IndicesUpdateMode; diff --git a/public/pages/CreateIndexTemplate/containers/CreateIndexTemplate/CreateIndexTemplate.tsx b/public/pages/CreateIndexTemplate/containers/CreateIndexTemplate/CreateIndexTemplate.tsx index 44c693074..6ad7638a5 100644 --- a/public/pages/CreateIndexTemplate/containers/CreateIndexTemplate/CreateIndexTemplate.tsx +++ b/public/pages/CreateIndexTemplate/containers/CreateIndexTemplate/CreateIndexTemplate.tsx @@ -12,7 +12,12 @@ import { CoreServicesContext } from "../../../../components/core_services"; import { DataSourceMenuContext, DataSourceMenuProperties } from "../../../../services/DataSourceMenuContext"; import { useUpdateUrlWithDataSourceProperties } from "../../../../components/MDSEnabledComponent"; -interface CreateIndexTemplateProps extends RouteComponentProps<{ template?: string; mode?: string }>, DataSourceMenuProperties {} +interface CreateIndexTemplateProps + extends RouteComponentProps<{ + template?: string; + mode?: string; + }>, + DataSourceMenuProperties {} class CreateIndexTemplate extends Component { static contextType = CoreServicesContext; @@ -74,7 +79,7 @@ class CreateIndexTemplate extends Component { } } -export default function (props: CreateIndexTemplateProps) { +export default function (props: Omit) { const dataSourceMenuProps = useContext(DataSourceMenuContext); useUpdateUrlWithDataSourceProperties(); return ; diff --git a/public/pages/DataStreams/containers/DataStreams/DataStreams.tsx b/public/pages/DataStreams/containers/DataStreams/DataStreams.tsx index eb33cc573..fe73a6f1e 100644 --- a/public/pages/DataStreams/containers/DataStreams/DataStreams.tsx +++ b/public/pages/DataStreams/containers/DataStreams/DataStreams.tsx @@ -428,7 +428,7 @@ class DataStreams extends MDSEnabledComponent) { +export default function DataStreamsContainer(props: Omit) { const context = useContext(ServicesContext); const dataSourceMenuProperties = useContext(DataSourceMenuContext); return ; diff --git a/public/pages/Indices/containers/Indices/Indices.tsx b/public/pages/Indices/containers/Indices/Indices.tsx index 3955fc507..21c04f967 100644 --- a/public/pages/Indices/containers/Indices/Indices.tsx +++ b/public/pages/Indices/containers/Indices/Indices.tsx @@ -62,6 +62,7 @@ interface IndicesState extends DataSourceMenuProperties { export class Indices extends MDSEnabledComponent { static contextType = CoreServicesContext; + constructor(props: IndicesProps) { super(props); const { from, size, search, sortField, sortDirection, showDataStreams } = getURLQueryParams(this.props.location); @@ -101,14 +102,14 @@ export class Indices extends MDSEnabledComponent { } async componentDidUpdate(prevProps: IndicesProps, prevState: IndicesState) { - const prevQuery = Indices.getQueryObjectFromState(prevState); - const currQuery = Indices.getQueryObjectFromState(this.state); + const prevQuery = this.getQueryObjectFromState(prevState); + const currQuery = this.getQueryObjectFromState(this.state); if (!_.isEqual(prevQuery, currQuery)) { await this.getIndices(); } } - static getQueryObjectFromState({ + getQueryObjectFromState({ from, size, search, @@ -117,14 +118,19 @@ export class Indices extends MDSEnabledComponent { showDataStreams, dataSourceId, }: IndicesState): IndicesQueryParams { - return { from, size, search, sortField, sortDirection, showDataStreams, dataSourceId }; + const queryObj = { from, size, search, sortField, sortDirection, showDataStreams }; + if (!this.props.multiDataSourceEnabled) { + // don't send dataSourceId, if MDS is not enabled + return queryObj; + } + return { ...queryObj, dataSourceId }; } getIndices = async (): Promise => { this.setState({ loadingIndices: true }); try { const { indexService, history } = this.props; - const queryObject = Indices.getQueryObjectFromState(this.state); + const queryObject = this.getQueryObjectFromState(this.state); const queryParamsString = queryString.stringify({ ...queryObject, dataSourceLabel: this.state.dataSourceLabel }); history.replace({ ...this.props.location, search: queryParamsString }); @@ -313,7 +319,7 @@ export class Indices extends MDSEnabledComponent { } } -export default function (props: IndicesProps) { +export default function (props: Omit) { const dataSourceMenuProps = useContext(DataSourceMenuContext); return ; } diff --git a/public/pages/Indices/models/interfaces.ts b/public/pages/Indices/models/interfaces.ts index 7bd32d299..59cafc716 100644 --- a/public/pages/Indices/models/interfaces.ts +++ b/public/pages/Indices/models/interfaces.ts @@ -19,5 +19,5 @@ export interface IndicesQueryParams { sortField: keyof ManagedCatIndex; sortDirection: Direction; showDataStreams: boolean; - dataSourceId: string; + dataSourceId?: string; } diff --git a/public/pages/Main/Main.tsx b/public/pages/Main/Main.tsx index 9f89c5c68..319567772 100644 --- a/public/pages/Main/Main.tsx +++ b/public/pages/Main/Main.tsx @@ -201,8 +201,8 @@ export default class Main extends Component { }; if (this.props.multiDataSourceEnabled && this.isDataSourceEnabledForPath(pathname)) { - services.indexService = new IndexService(http, this.state.dataSourceId); - services.commonService = new CommonService(http, this.state.dataSourceId); + services.indexService = new IndexService(http, this.state.dataSourceId, this.props.multiDataSourceEnabled); + services.commonService = new CommonService(http, this.state.dataSourceId, this.props.multiDataSourceEnabled); } return services; } @@ -311,7 +311,7 @@ export default class Main extends Component { const { landingPage } = this.props; const ROUTE_STYLE = { padding: "25px 25px" }; - const DataSourceMenu = this.props.dataSourceManagement.ui.DataSourceMenu; + const DataSourceMenu = this.props.dataSourceManagement?.ui?.DataSourceMenu; return ( @@ -626,7 +626,7 @@ export default class Main extends Component { path={`${ROUTES.CREATE_INDEX}/:index/:mode`} render={(props: RouteComponentProps) => (
- +
)} /> @@ -642,7 +642,7 @@ export default class Main extends Component { path={ROUTES.CREATE_INDEX} render={(props: RouteComponentProps) => (
- +
)} /> diff --git a/public/pages/Templates/containers/Templates/Templates.tsx b/public/pages/Templates/containers/Templates/Templates.tsx index 47d3ef8b1..bb625c5ee 100644 --- a/public/pages/Templates/containers/Templates/Templates.tsx +++ b/public/pages/Templates/containers/Templates/Templates.tsx @@ -417,7 +417,7 @@ class Templates extends MDSEnabledComponent { } } -export default function TemplatesContainer(props: Omit) { +export default function TemplatesContainer(props: Omit) { const context = useContext(ServicesContext); const dataSourceMenuProps = useContext(DataSourceMenuContext); return ; diff --git a/public/services/MDSEnabledClientService.ts b/public/services/MDSEnabledClientService.ts index 2b7c012d9..34ddaece0 100644 --- a/public/services/MDSEnabledClientService.ts +++ b/public/services/MDSEnabledClientService.ts @@ -3,15 +3,19 @@ import { HttpFetchQuery, HttpSetup } from "opensearch-dashboards/public"; export abstract class MDSEnabledClientService { httpClient: HttpSetup; dataSourceId: string; + mdsEnabled: boolean; - constructor(httpClient: HttpSetup, dataSourceId: string = "") { + constructor(httpClient: HttpSetup, dataSourceId: string = "", mdsEnabled: boolean = false) { this.httpClient = httpClient; this.dataSourceId = dataSourceId; + this.mdsEnabled = mdsEnabled; } - patchQueryObjectWithDataSourceId(queryObject: HttpFetchQuery) { - queryObject = queryObject || {}; - queryObject.dataSourceId = this.dataSourceId; + patchQueryObjectWithDataSourceId(queryObject: HttpFetchQuery): HttpFetchQuery { + if (this.mdsEnabled) { + queryObject = queryObject || {}; + queryObject.dataSourceId = this.dataSourceId; + } return queryObject; } }