forked from opensearch-project/OpenSearch-Dashboards
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Kawika Avilla <[email protected]>
- Loading branch information
Showing
14 changed files
with
276 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/plugins/data/public/ui/dataset_navigator/create_dataset_navigator.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import _ from 'lodash'; | ||
import React from 'react'; | ||
|
||
import { SavedObjectsClientContract } from 'src/core/public'; | ||
import { DataSetNavigator, DataSetNavigatorProps } from './'; | ||
|
||
// Takes in stateful runtime dependencies and pre-wires them to the component | ||
export function createDataSetNavigator(savedObjectsClient: SavedObjectsClientContract) { | ||
return (props: Omit<DataSetNavigatorProps, 'savedObjectsClient'>) => ( | ||
<DataSetNavigator {...props} savedObjectsClient={savedObjectsClient} /> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/plugins/data/public/ui/dataset_navigator/fetch_clusters.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { SavedObjectsClientContract } from 'opensearch-dashboards/public'; | ||
|
||
export const fetchClusters = async (savedObjectsClient: SavedObjectsClientContract) => { | ||
return await savedObjectsClient.find({ | ||
type: 'data-source', | ||
perPage: 10000, | ||
}); | ||
}; |
21 changes: 21 additions & 0 deletions
21
src/plugins/data/public/ui/dataset_navigator/fetch_index_patterns.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { SavedObjectsClientContract } from 'opensearch-dashboards/public'; | ||
|
||
export const fetchIndexPatterns = async ( | ||
client: SavedObjectsClientContract, | ||
search: string, | ||
fields: string[] | ||
) => { | ||
const resp = await client.find({ | ||
type: 'index-pattern', | ||
fields, | ||
search: `${search}*`, | ||
searchFields: ['title'], | ||
perPage: 100, | ||
}); | ||
return resp.savedObjects; | ||
}; |
67 changes: 67 additions & 0 deletions
67
src/plugins/data/public/ui/dataset_navigator/fetch_indices.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { map, scan } from 'rxjs/operators'; | ||
import { ISearchStart } from '../../search'; | ||
|
||
export const fetchIndices = async (search: ISearchStart, dataSourceId: string) => { | ||
const request = buildSearchRequest(true, '*', dataSourceId); | ||
return search | ||
.getDefaultSearchInterceptor() | ||
.search(request) | ||
.pipe(map(searchResponseToArray(true))) | ||
.pipe(scan((accumulator = [], value) => accumulator.join(value))) | ||
.toPromise() | ||
.catch(() => []); | ||
}; | ||
|
||
const searchResponseToArray = (showAllIndices: boolean) => (response) => { | ||
const { rawResponse } = response; | ||
if (!rawResponse.aggregations) { | ||
return []; | ||
} else { | ||
return rawResponse.aggregations.indices.buckets | ||
.map((bucket: { key: string }) => { | ||
return bucket.key; | ||
}) | ||
.filter((indexName: string) => { | ||
if (showAllIndices) { | ||
return true; | ||
} else { | ||
return !indexName.startsWith('.'); | ||
} | ||
}) | ||
.map((indexName: string) => { | ||
return { | ||
name: indexName, | ||
// item: {}, | ||
}; | ||
}); | ||
} | ||
}; | ||
|
||
const buildSearchRequest = (showAllIndices: boolean, pattern: string, dataSourceId?: string) => { | ||
const request = { | ||
params: { | ||
ignoreUnavailable: true, | ||
expand_wildcards: showAllIndices ? 'all' : 'open', | ||
index: pattern, | ||
body: { | ||
size: 0, // no hits | ||
aggs: { | ||
indices: { | ||
terms: { | ||
field: '_index', | ||
size: 100, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
dataSourceId, | ||
}; | ||
|
||
return request; | ||
}; |
Oops, something went wrong.