diff --git a/public/components/MDSEnabledComponent/MDSEnabledComponent.tsx b/public/components/MDSEnabledComponent/MDSEnabledComponent.tsx index 340fe1120..701753729 100644 --- a/public/components/MDSEnabledComponent/MDSEnabledComponent.tsx +++ b/public/components/MDSEnabledComponent/MDSEnabledComponent.tsx @@ -11,7 +11,6 @@ export default class MDSEnabledComponent< super(props); this.state = { dataSourceId: props.dataSourceId, - dataSourceLabel: props.dataSourceLabel, multiDataSourceEnabled: props.multiDataSourceEnabled, } as State; } @@ -21,13 +20,9 @@ export default class MDSEnabledComponent< prevState: State ) { // static members cannot reference class type parameters - if ( - nextProps.multiDataSourceEnabled && - (nextProps.dataSourceId !== prevState.dataSourceId || nextProps.dataSourceLabel !== prevState.dataSourceLabel) - ) { + if (nextProps.multiDataSourceEnabled && nextProps.dataSourceId !== prevState.dataSourceId) { return { dataSourceId: nextProps.dataSourceId, - dataSourceLabel: nextProps.dataSourceLabel, }; } return null; @@ -36,7 +31,7 @@ export default class MDSEnabledComponent< export function useUpdateUrlWithDataSourceProperties() { const dataSourceMenuProps = useContext(DataSourceMenuContext); - const { dataSourceId, dataSourceLabel, multiDataSourceEnabled } = dataSourceMenuProps; + const { dataSourceId, multiDataSourceEnabled } = dataSourceMenuProps; const history = useHistory(); const currentSearch = history.location.search; const currentQuery = queryString.parse(currentSearch); @@ -46,9 +41,8 @@ export function useUpdateUrlWithDataSourceProperties() { search: queryString.stringify({ ...currentQuery, dataSourceId, - dataSourceLabel, }), }); } - }, [dataSourceId, dataSourceLabel, multiDataSourceEnabled]); + }, [dataSourceId, multiDataSourceEnabled]); } diff --git a/public/pages/Aliases/utils/constants.tsx b/public/pages/Aliases/utils/constants.tsx index 643e1074e..ebed1fb94 100644 --- a/public/pages/Aliases/utils/constants.tsx +++ b/public/pages/Aliases/utils/constants.tsx @@ -15,5 +15,4 @@ export const DEFAULT_QUERY_PARAMS = { sortDirection: SortDirection.DESC, status: "", dataSourceId: "", - dataSourceLabel: "", }; diff --git a/public/pages/ComposableTemplates/utils/constants.tsx b/public/pages/ComposableTemplates/utils/constants.tsx index 00adea8a5..6203656e5 100644 --- a/public/pages/ComposableTemplates/utils/constants.tsx +++ b/public/pages/ComposableTemplates/utils/constants.tsx @@ -14,5 +14,4 @@ export const DEFAULT_QUERY_PARAMS = { sortField: "name" as keyof ICatComposableTemplate, sortDirection: SortDirection.DESC, dataSourceId: "", - dataSourceLabel: "", }; diff --git a/public/pages/DataStreams/utils/constants.tsx b/public/pages/DataStreams/utils/constants.tsx index bd4c3cfb5..79e195db5 100644 --- a/public/pages/DataStreams/utils/constants.tsx +++ b/public/pages/DataStreams/utils/constants.tsx @@ -14,7 +14,6 @@ export const DEFAULT_QUERY_PARAMS = { sortField: "name" as keyof DataStream, sortDirection: SortDirection.DESC, dataSourceId: "", - dataSourceLabel: "", }; export const HEALTH_TO_COLOR: { diff --git a/public/pages/Indices/containers/Indices/Indices.test.tsx b/public/pages/Indices/containers/Indices/Indices.test.tsx index 4224efc51..6610525c9 100644 --- a/public/pages/Indices/containers/Indices/Indices.test.tsx +++ b/public/pages/Indices/containers/Indices/Indices.test.tsx @@ -23,7 +23,6 @@ function renderWithRouter( Component: React.ComponentType, data: DataSourceMenuProperties = { dataSourceId: "", - dataSourceLabel: "", multiDataSourceEnabled: false, }, renderFn = render @@ -264,7 +263,6 @@ describe("re-render on data-source-id prop change", () => { const { getByText, queryByText, rerender } = renderWithRouter(Indices, { dataSourceId: "test_data_source_id", - dataSourceLabel: "test_data_source_label", multiDataSourceEnabled: true, }); @@ -276,7 +274,6 @@ describe("re-render on data-source-id prop change", () => { Indices, { dataSourceId: "test_data_source_id_2", - dataSourceLabel: "test_data_source_label_2", multiDataSourceEnabled: true, }, rerender diff --git a/public/pages/Indices/containers/Indices/Indices.tsx b/public/pages/Indices/containers/Indices/Indices.tsx index 21c04f967..235bbddb2 100644 --- a/public/pages/Indices/containers/Indices/Indices.tsx +++ b/public/pages/Indices/containers/Indices/Indices.tsx @@ -131,7 +131,9 @@ export class Indices extends MDSEnabledComponent { try { const { indexService, history } = this.props; const queryObject = this.getQueryObjectFromState(this.state); - const queryParamsString = queryString.stringify({ ...queryObject, dataSourceLabel: this.state.dataSourceLabel }); + const queryParamsString = queryString.stringify({ + ...queryObject, + }); history.replace({ ...this.props.location, search: queryParamsString }); const getIndicesResponse = await indexService.getIndices({ diff --git a/public/pages/Main/Main.tsx b/public/pages/Main/Main.tsx index 319567772..cf14383ce 100644 --- a/public/pages/Main/Main.tsx +++ b/public/pages/Main/Main.tsx @@ -60,7 +60,13 @@ import ComposableTemplates from "../ComposableTemplates"; import CreateComposableTemplate from "../CreateComposableTemplate"; import { DataSourceMenuContext, DataSourceMenuProperties } from "../../services/DataSourceMenuContext"; import queryString from "query-string"; -import { DataSourceManagementPluginSetup } from "../../../../../src/plugins/data_source_management/public"; +import { + DataSourceManagementPluginSetup, + DataSourceSelectableConfig, + DataSourceViewConfig, +} from "../../../../../src/plugins/data_source_management/public"; +import { DataSourceOption } from "../../../../../src/plugins/data_source_management/public/components/data_source_menu/types"; +import { ImageType } from "../../../../../src/core/common"; enum Navigation { IndexManagement = "Index Management", @@ -131,7 +137,11 @@ interface MainProps extends RouteComponentProps { dataSourceManagement: DataSourceManagementPluginSetup; } -interface MainState extends Pick {} +interface MainState extends Pick { + dataSourceLabel: string; + dataSourceReadOnly: boolean; + dataSourceLoading: boolean; +} const dataSourceEnabledPaths: string[] = [ ROUTES.CREATE_DATA_STREAM, @@ -171,6 +181,12 @@ export default class Main extends Component { dataSourceLabel: "", }; } + this.state = { + dataSourceId: dataSourceId, + dataSourceLabel: dataSourceLabel, + dataSourceReadOnly: false, + dataSourceLoading: props.multiDataSourceEnabled, + }; } isDataSourceEnabledForPath(path: string): boolean { @@ -207,6 +223,21 @@ export default class Main extends Component { return services; } + onSelectedDataSources = (dataSources: DataSourceOption[]) => { + const { id = "", label = "" } = dataSources[0] || {}; + if (this.state.dataSourceId != id || this.state.dataSourceLabel != label) { + this.setState({ + dataSourceId: id, + dataSourceLabel: label, + }); + } + if (this.state.dataSourceLoading) { + this.setState({ + dataSourceLoading: false, + }); + } + }; + render() { const { location: { pathname }, @@ -311,7 +342,9 @@ 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?.getDataSourceMenu(); + const DataSourceViewer = this.props.dataSourceManagement?.ui?.getDataSourceMenu(); return ( @@ -325,11 +358,10 @@ export default class Main extends Component { - {this.props.multiDataSourceEnabled && ( + {this.props.multiDataSourceEnabled && DataSourceMenu && DataSourceViewer && ( { ROUTES.INDEX_DETAIL, ROUTES.REINDEX, ]} - render={(props) => ( - ( + { - if (this.state.dataSourceId && this.state.dataSourceId !== "") { - return [ - { - id: this.state.dataSourceId, - label: this.state.dataSourceLabel, - }, - ]; - } - return undefined; - })()} - fullWidth={false} - hideLocalCluster={false} + componentType={"DataSourceView"} + componentConfig={{ + activeOption: [{ label: this.state.dataSourceLabel, id: this.state.dataSourceId }], + fullWidth: false, + }} /> )} /> @@ -377,447 +399,469 @@ export default class Main extends Component { ]} render={() => ( { - this.setState({ dataSourceId, dataSourceLabel }); + componentType={"DataSourceSelectable"} + componentConfig={{ + savedObjects: core?.savedObjects.client, + notifications: core?.notifications, + fullWidth: false, + activeOption: [{ label: this.state.dataSourceLabel, id: this.state.dataSourceId }], + onSelectedDataSources: this.onSelectedDataSources, }} - disableDataSourceSelectable={false} - notifications={services.notificationService} - savedObjects={core.savedObjects.client} - selectedOption={(() => { - if (this.state.dataSourceId && this.state.dataSourceId !== "") { - return [ - { - id: this.state.dataSourceId, - label: this.state.dataSourceLabel, - }, - ]; - } - return undefined; - })()} - fullWidth={false} - hideLocalCluster={false} /> )} /> + + this.state.dataSourceReadOnly ? ( + + ) : ( + + ) + } + /> )} - - - {/* Hide side navigation bar when creating or editing rollup job*/} - {!HIDDEN_NAV_ROUTES.includes(pathname) && - !HIDDEN_NAV_STARTS_WITH_ROUTE.some((item) => pathname.startsWith(item)) ? ( - - - - ) : null} - - - ( -
- -
- )} - /> - ( -
- -
- )} - /> - ( -
- -
- )} - /> - ( - - )} - /> - ( - - )} - /> - ( - - )} - /> - ( - - )} - /> - - queryString.parse(this.props.location.search).type == "visual" ? ( - - ) : ( - - ) - } - /> - - queryString.parse(this.props.location.search).type == "visual" ? ( - - ) : ( - - ) - } - /> - ( -
- -
- )} - /> - ( -
- -
- )} - /> - ( -
- -
- )} - /> - ( -
- -
- )} - /> - ( -
- -
- )} - /> - ( -
- -
- )} - /> - ( -
- -
- )} - /> - ( -
- -
- )} - /> - ( -
- -
- )} - /> - ( -
- -
- )} - /> - ( -
- -
- )} - /> - ( -
- -
- )} - /> - ( -
- -
- )} - /> - ( -
- -
- )} - /> - ( -
- -
- )} - /> - ( -
- -
- )} - /> - ( -
- -
- )} - /> - ( -
- -
- )} - /> - ( -
- -
- )} - /> - ( -
- -
- )} - /> - ( -
- -
- )} - /> - ( -
- -
- )} - /> - ( -
- -
- )} - /> - ( -
- -
- )} - /> - ( -
- -
- )} - /> - ( -
- -
- )} - /> - ( -
- -
- )} - /> - ( -
- -
- )} - /> - ( -
- -
- )} - /> - ( -
- -
- )} - /> - ( -
- -
- )} - /> - ( -
- -
- )} - /> - ( -
- -
- )} - /> - ( -
- -
- )} - /> - ( -
- -
- )} - /> - ( -
- -
- )} - /> - -
-
-
+ {!this.state.dataSourceLoading && ( + <> + + + {/* Hide side navigation bar when creating or editing rollup job*/} + {!HIDDEN_NAV_ROUTES.includes(pathname) && + !HIDDEN_NAV_STARTS_WITH_ROUTE.some((item) => pathname.startsWith(item)) ? ( + + + + ) : null} + + + ( +
+ +
+ )} + /> + ( +
+ +
+ )} + /> + ( +
+ +
+ )} + /> + ( + + )} + /> + ( + + )} + /> + ( + + )} + /> + ( + + )} + /> + + queryString.parse(this.props.location.search).type == "visual" ? ( + + ) : ( + + ) + } + /> + + queryString.parse(this.props.location.search).type == "visual" ? ( + + ) : ( + + ) + } + /> + ( +
+ +
+ )} + /> + ( +
+ +
+ )} + /> + ( +
+ +
+ )} + /> + ( +
+ +
+ )} + /> + ( +
+ +
+ )} + /> + ( +
+ +
+ )} + /> + ( +
+ +
+ )} + /> + ( +
+ +
+ )} + /> + ( +
+ +
+ )} + /> + ( +
+ +
+ )} + /> + ( +
+ +
+ )} + /> + ( +
+ +
+ )} + /> + ( +
+ +
+ )} + /> + ( +
+ +
+ )} + /> + ( +
+ +
+ )} + /> + ( +
+ +
+ )} + /> + ( +
+ +
+ )} + /> + ( +
+ +
+ )} + /> + ( +
+ +
+ )} + /> + ( +
+ +
+ )} + /> + ( +
+ +
+ )} + /> + ( +
+ +
+ )} + /> + ( +
+ +
+ )} + /> + ( +
+ +
+ )} + /> + ( +
+ +
+ )} + /> + ( +
+ +
+ )} + /> + ( +
+ +
+ )} + /> + ( +
+ +
+ )} + /> + ( +
+ +
+ )} + /> + ( +
+ +
+ )} + /> + ( +
+ +
+ )} + /> + ( +
+ +
+ )} + /> + ( +
+ +
+ )} + /> + ( +
+ +
+ )} + /> + ( +
+ +
+ )} + /> + ( +
+ +
+ )} + /> + +
+
+
+ + )}
) diff --git a/public/pages/Rollups/containers/Rollups/Rollups.tsx b/public/pages/Rollups/containers/Rollups/Rollups.tsx index 6780cb813..05f36a6be 100644 --- a/public/pages/Rollups/containers/Rollups/Rollups.tsx +++ b/public/pages/Rollups/containers/Rollups/Rollups.tsx @@ -110,7 +110,7 @@ export default class Rollups extends Component { try { const { rollupService, history } = this.props; const queryObject = Rollups.getQueryObjectFromState(this.state); - const queryParamsString = queryString.stringify(Rollups.getQueryObjectFromState(this.state)); + const queryParamsString = queryString.stringify(queryObject); history.replace({ ...this.props.location, search: queryParamsString }); const rollupJobsResponse = await rollupService.getRollups(queryObject); if (rollupJobsResponse.ok) { diff --git a/public/pages/Templates/utils/constants.tsx b/public/pages/Templates/utils/constants.tsx index 21230015d..3ff2466eb 100644 --- a/public/pages/Templates/utils/constants.tsx +++ b/public/pages/Templates/utils/constants.tsx @@ -14,5 +14,4 @@ export const DEFAULT_QUERY_PARAMS = { sortField: "name" as keyof ITemplate, sortDirection: SortDirection.DESC, dataSourceId: "", - dataSourceLabel: "", }; diff --git a/public/services/DataSourceMenuContext.ts b/public/services/DataSourceMenuContext.ts index 3770b1100..36fd6ba3a 100644 --- a/public/services/DataSourceMenuContext.ts +++ b/public/services/DataSourceMenuContext.ts @@ -2,13 +2,11 @@ import { createContext } from "react"; export interface DataSourceMenuProperties { dataSourceId: string; - dataSourceLabel: string; multiDataSourceEnabled: boolean; } const DataSourceMenuContext = createContext({ dataSourceId: "", - dataSourceLabel: "", multiDataSourceEnabled: false, });