diff --git a/public/components/common/search/searchindex.tsx b/public/components/common/search/searchindex.tsx new file mode 100644 index 000000000..7e062d598 --- /dev/null +++ b/public/components/common/search/searchindex.tsx @@ -0,0 +1,66 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + * Modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ + +import { EuiComboBox } from '@elastic/eui'; +import React, { useState, useEffect, memo } from 'react'; + + +export const IndexPicker = memo(function indexDropdown(props: any) { + return ; +}); + +interface Fetch { + dslService: any; + query: any; + handleQueryChange: (query: string, index: string) => void; +} + +export function SearchIndex(options: Fetch) { + + const [indicesFromBackend, setindicesFromBackend] = useState([]); + + // fetch indices from backend + const getIndices = async (dslService: any) => { + if (indicesFromBackend.length === 0) { + const indices = (await dslService.fetchIndices()).filter( + ({ index }) => !index.startsWith('.') + ); + for (let i = 0; i < indices.length; i++) { + indicesFromBackend.push({ + label: indices[i].index, + }); + } + } + }; + + useEffect(() => { + getIndices(options.dslService); + }, []); + + const [selectedOptions, setSelected] = useState( + [] + ); + + // handle Index Change + const onChange = (selectedOptions) => { + options.handleQueryChange(options.query, selectedOptions); + setSelected(selectedOptions); + }; + + return ( + onChange(e)} + /> + ); +} diff --git a/public/components/explorer/explorer.tsx b/public/components/explorer/explorer.tsx index 45ed230fb..075ad1a31 100644 --- a/public/components/explorer/explorer.tsx +++ b/public/components/explorer/explorer.tsx @@ -36,6 +36,7 @@ import { NoResults } from './no_results'; import { HitsCounter } from './hits_counter/hits_counter'; import { TimechartHeader } from './timechart_header'; import { ExplorerVisualizations } from './visualizations'; +import { IndexPicker } from '../common/search/searchindex'; import { IField, IQueryTab @@ -463,6 +464,11 @@ export const Explorer = ({ onLiveStreamChange={ handleLiveStreamChecked } actionItems={ actionItems } /> + { handleQueryChange(query, index) } } + /> ); -}; \ No newline at end of file +};