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

Multi datasource support #311

Merged
merged 19 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
3 changes: 2 additions & 1 deletion common/utils/async_query_helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@
export const executeAsyncQuery = (
currentDataSource: string,
query: {},
dataSourceId: string,
pollingCallback: PollingCallback,
onErrorCallback?: (errorMessage: string) => void
onErrorCallback?: (errorMessage: string) => void,

Check failure on line 31 in common/utils/async_query_helpers.ts

View workflow job for this annotation

GitHub Actions / Lint

Delete `,`
) => {
let jobId: string | undefined;
let isQueryFulfilled = false;
Expand Down Expand Up @@ -74,7 +75,7 @@
};

const pollQueryStatus = (id: string, callback: PollingCallback) => {
!isQueryCancelled &&

Check failure on line 78 in common/utils/async_query_helpers.ts

View workflow job for this annotation

GitHub Actions / Lint

Expected an assignment or function call and instead saw an expression
http
.get(ASYNC_QUERY_JOB_ENDPOINT + id)
.then((res: AsyncApiResponse) => {
Expand Down
54 changes: 54 additions & 0 deletions common/utils/fetch_datasources.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/


import { CoreStart } from "../../../../src/core/public";

export const fetchDataSources = (http: CoreStart['http'], dataSourceId: string, urlDataSource: string, onSuccess, onError) => {
sumukhswamy marked this conversation as resolved.
Show resolved Hide resolved
let dataOptions: { label: string; options?: any; }[] = [];
joshuali925 marked this conversation as resolved.
Show resolved Hide resolved
let urlSourceFound = false;
if(!dataSourceId){
dataSourceId = ''
}

http.get(`/api/get_datasources/${dataSourceId}`)
.then((res) => {
const data = res.data.resp;
const connectorGroups = {};

data.forEach((item) => {
const connector = item.connector;
const name = item.name;
sumukhswamy marked this conversation as resolved.
Show resolved Hide resolved

if (connector === 'S3GLUE') {
if (!connectorGroups[connector]) {
connectorGroups[connector] = [];
}

connectorGroups[connector].push(name);
if (name === urlDataSource) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is urlDataSource? Can we give a better name?

urlSourceFound = true;
}
}
});
sumukhswamy marked this conversation as resolved.
Show resolved Hide resolved

for (const connector in connectorGroups) {
if (connectorGroups.hasOwnProperty(connector)) {
const connectorNames = connectorGroups[connector];

dataOptions.push({
label: connector,
options: connectorNames.map((name) => ({ label: name })),
});
}
}

onSuccess(dataOptions, urlSourceFound);
})
.catch((err) => {
console.error(err);
onError(err);
});
};
14 changes: 10 additions & 4 deletions public/application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { AppMountParameters, CoreStart } from '../../../src/core/public';
import { AppPluginStartDependencies } from './types';
import { DataSourceManagementPluginSetup } from '../../../src/plugins/data_source_management/public';
import { WorkbenchApp } from './components/app';
import { AppPluginStartDependencies } from './types';

export const renderApp = (
{ notifications, http, chrome }: CoreStart,
{ navigation }: AppPluginStartDependencies,
{ appBasePath, element }: AppMountParameters
{ notifications, http, chrome, savedObjects }: CoreStart,
{ navigation, dataSource }: AppPluginStartDependencies,
{ appBasePath, element, setHeaderActionMenu }: AppMountParameters,
dataSourceManagement: DataSourceManagementPluginSetup
) => {
ReactDOM.render(
<WorkbenchApp
Expand All @@ -22,6 +24,10 @@ export const renderApp = (
http={http}
navigation={navigation}
chrome={chrome}
savedObjects={savedObjects}
dataSourceEnabled={!!dataSource}
dataSourceManagement={dataSourceManagement}
setActionMenu={setHeaderActionMenu}
/>,
element
);
Expand Down
Loading
Loading