Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event Analytics - Add index picker to explorer page #125

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions public/components/common/search/searchindex.tsx
Original file line number Diff line number Diff line change
@@ -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 <SearchIndex {...props} />;
});

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 (
<EuiComboBox
placeholder="Select one or more index"
options={indicesFromBackend}
selectedOptions={selectedOptions}
onChange={(e) => onChange(e)}
/>
);
}
8 changes: 7 additions & 1 deletion public/components/explorer/explorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -463,6 +464,11 @@ export const Explorer = ({
onLiveStreamChange={ handleLiveStreamChecked }
actionItems={ actionItems }
/>
<IndexPicker
dslService={ dslService }
query = { query }
handleQueryChange={(query: string, index: string) => { handleQueryChange(query, index) } }
/>
<EuiTabbedContent
className="mainContentTabs"
initialSelectedTab={ memorizedMainContentTabs[0] }
Expand All @@ -472,4 +478,4 @@ export const Explorer = ({
/>
</div>
);
};
};