Skip to content

Commit

Permalink
added changes for selecting and filtering multiple data sources
Browse files Browse the repository at this point in the history
Signed-off-by: sumukhswamy <[email protected]>
  • Loading branch information
sumukhswamy committed Mar 14, 2024
1 parent d850cbe commit 3f1543c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
19 changes: 15 additions & 4 deletions public/components/query_compare/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ export const Home = ({
datasource1,
datasource2,
setFetchedPipelines1,
setFetchedPipelines2
setFetchedPipelines2,
dataSourceOptions,
setDataSourceOptions
} = useSearchRelevanceContext();

useEffect(() => {
Expand Down Expand Up @@ -104,6 +106,16 @@ export const Home = ({
}
}

const selectedDatasources = (e) => {
console.log(e)
e.forEach(item => {
if (item.checked === "on" && !dataSourceOptions.find(option => option.id === item.id)) {
dataSourceOptions.push({ id: item.id, label: item.name });;
}
});
setDataSourceOptions(dataSourceOptions)
}

// Get Indexes and Pipelines
useEffect(() => {

Expand All @@ -117,14 +129,13 @@ export const Home = ({
<>
<DataSourceMenu
setMenuMountPoint={setActionMenu}
showDataSourceSelectable={true}
dataSourceCallBackFunc={(id, label) => console.log(id, label)}
showDataSourceMultiSelectable={true}
disableDataSourceSelectable={true}
savedObjects={savedObjects.client}
notifications={notifications}
appName={'searchRelevance'}
hideLocalCluster={false}
selectedOption={[{label: 'Local Cluster', id: 'a'}]}
selectedDataSourcesCallBackFunc={selectedDatasources}
fullWidth={true}
/>
<div className="osdOverviewWrapper">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const SearchConfig: FunctionComponent<SearchConfigProps> = ({
navigation,
setActionMenu,
}) => {
const { documentsIndexes1, setDataSource1, setDataSource2, documentsIndexes2, fetchedPipelines1, fetchedPipelines2, setShowFlyout} = useSearchRelevanceContext();
const { documentsIndexes1, setDataSource1, setDataSource2, documentsIndexes2, fetchedPipelines1, fetchedPipelines2, setShowFlyout, dataSourceOptions} = useSearchRelevanceContext();
// On select index
const onChangeSelectedIndex: React.ChangeEventHandler<HTMLSelectElement> = (e) => {
setSelectedIndex(e.target.value);
Expand Down Expand Up @@ -164,6 +164,7 @@ export const SearchConfig: FunctionComponent<SearchConfigProps> = ({
hideLocalCluster={false}
fullWidth={false}
removePrepend={true}
dataSourceOptions={dataSourceOptions}
/>
</EuiFormRow>
</EuiFlexItem> )}
Expand Down
8 changes: 7 additions & 1 deletion public/contexts/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import React, { createContext, useContext, useState } from 'react';

import { DataSourceOption } from '../../../../src/plugins/data_source_management/public/components/data_source_selector/data_source_selector';
import { DocumentsIndex, SearchResults } from '../types/index';
import { DocumentRank, getDocumentRank } from './utils';

Expand Down Expand Up @@ -41,6 +42,8 @@ export interface SearchRelevanceContextProps {
setFetchedPipelines1: React.Dispatch<React.SetStateAction<{}>>;
fetchedPipelines2: {};
setFetchedPipelines2: React.Dispatch<React.SetStateAction<{}>>;
dataSourceOptions: DataSourceOption[]
setDataSourceOptions: React.Dispatch<React.SetStateAction<DataSourceOption[]>>;
}

export const SearchRelevanceContext = createContext<SearchRelevanceContextProps | null>(null);
Expand Down Expand Up @@ -72,6 +75,7 @@ export const SearchRelevanceContextProvider = ({ children }: { children: React.R
const [datasource2, setDataSource2] = useState('');
const [fetchedPipelines1, setFetchedPipelines1] = useState<{}>({});
const [fetchedPipelines2, setFetchedPipelines2] = useState<{}>({});
const [dataSourceOptions, setDataSourceOptions] = useState<DataSourceOption[]>([])

const updateComparedResult1 = (result: SearchResults) => {
setComparedResult1(getDocumentRank(result?.hits?.hits));
Expand Down Expand Up @@ -113,7 +117,9 @@ export const SearchRelevanceContextProvider = ({ children }: { children: React.R
fetchedPipelines1,
setFetchedPipelines1,
fetchedPipelines2,
setFetchedPipelines2
setFetchedPipelines2,
dataSourceOptions,
setDataSourceOptions
}}
>
{children}
Expand Down

0 comments on commit 3f1543c

Please sign in to comment.