Skip to content

Commit

Permalink
linter fixes
Browse files Browse the repository at this point in the history
Signed-off-by: sumukhswamy <[email protected]>
  • Loading branch information
sumukhswamy committed Jul 17, 2024
1 parent efd62fd commit e95d3a9
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ describe('<Notebook /> spec', () => {
expect(utils.getByText('sample-notebook-1')).toBeInTheDocument();
});
expect(utils.container.firstChild).toMatchSnapshot();

});

it('Adds a code block', async () => {
Expand Down
11 changes: 7 additions & 4 deletions public/components/notebooks/components/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ import React, { ReactChild } from 'react';
// eslint-disable-next-line @osd/eslint/module_migration
import { Route, Switch } from 'react-router';
import { HashRouter, RouteComponentProps } from 'react-router-dom';
import { ChromeBreadcrumb, CoreStart, MountPoint, SavedObjectsStart } from '../../../../../../src/core/public';
import { DashboardStart } from '../../../../../../src/plugins/dashboard/public';
import {
DataSourceManagementPluginSetup
} from '../../../../../../src/plugins/data_source_management/public';
ChromeBreadcrumb,
CoreStart,
MountPoint,
SavedObjectsStart,
} from '../../../../../../src/core/public';
import { DashboardStart } from '../../../../../../src/plugins/dashboard/public';
import { DataSourceManagementPluginSetup } from '../../../../../../src/plugins/data_source_management/public';
import {
NOTEBOOKS_API_PREFIX,
NOTEBOOKS_DOCUMENTATION_URL,
Expand Down
19 changes: 12 additions & 7 deletions public/components/notebooks/components/notebook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ import moment from 'moment';
import queryString from 'query-string';
import React, { Component } from 'react';
import { RouteComponentProps } from 'react-router-dom';
import { ChromeBreadcrumb, CoreStart, MountPoint, SavedObjectsStart } from '../../../../../../src/core/public';
import {
ChromeBreadcrumb,
CoreStart,
MountPoint,
SavedObjectsStart,
} from '../../../../../../src/core/public';
import { DashboardStart } from '../../../../../../src/plugins/dashboard/public';
import { DataSourceManagementPluginSetup } from '../../../../../../src/plugins/data_source_management/public';
import { CREATE_NOTE_MESSAGE, NOTEBOOKS_API_PREFIX } from '../../../../common/constants/notebooks';
Expand Down Expand Up @@ -125,7 +130,7 @@ export class Notebook extends Component<NotebookProps, NotebookState> {
showQueryParagraphError: false,
queryParagraphErrorMessage: '',
savedObjectNotebook: true,
dataSourceMDSId: ''
dataSourceMDSId: '',
};
}

Expand Down Expand Up @@ -640,20 +645,20 @@ export class Notebook extends Component<NotebookProps, NotebookState> {
});
};

handleSelectedDataSourceChange = (id : string| undefined) => {
this.setState({dataSourceMDSId: id})
handleSelectedDataSourceChange = (id: string | undefined) => {
this.setState({ dataSourceMDSId: id });
};

loadQueryResultsFromInput = async (paragraph: any) => {
const queryType =
paragraph.input.inputText.substring(0, 4) === '%sql' ? 'sqlquery' : 'pplquery';
const query = {
dataSourceMDSId: this.state.dataSourceMDSId
}
dataSourceMDSId: this.state.dataSourceMDSId,
};
await this.props.http
.post(`/api/sql/${queryType}`, {
body: JSON.stringify(paragraph.output[0].result),
query
query,
})
.then((response) => {
paragraph.output[0].result = response.data.resp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,26 @@ interface ParagraphProps {
paraCount: number;
paragraphSelector: (index: number) => void;
textValueEditor: (evt: React.ChangeEvent<HTMLTextAreaElement>, index: number) => void;
handleKeyPress: (evt: React.KeyboardEvent<Element>, para: ParaType, index: number, dataSourceMDSID: string) => void;
handleKeyPress: (
evt: React.KeyboardEvent<Element>,
para: ParaType,
index: number,
dataSourceMDSID: string
) => void;
addPara: (index: number, newParaContent: string, inputType: string) => void;
DashboardContainerByValueRenderer: DashboardStart['DashboardContainerByValueRenderer'];
deleteVizualization: (uniqueId: string) => void;
http: CoreStart['http'];
selectedViewId: string;
setSelectedViewId: (viewId: string, scrollToIndex?: number) => void;
deletePara: (para: ParaType, index: number) => void;
runPara: (para: ParaType, index: number, vizObjectInput?: string, paraType?: string, dataSourceMDSId?: string) => void;
runPara: (
para: ParaType,
index: number,
vizObjectInput?: string,
paraType?: string,
dataSourceMDSId?: string
) => void;
clonePara: (para: ParaType, index: number) => void;
movePara: (index: number, targetIndex: number) => void;
showQueryParagraphError: boolean;
Expand All @@ -96,7 +107,7 @@ interface ParagraphProps {
notifications: CoreStart['notifications'];
dataSourceEnabled: boolean;
savedObjectsMDSClient: SavedObjectsStart;
handleSelectedDataSourceChange: (dataSourceMDSId: string | undefined) => void
handleSelectedDataSourceChange: (dataSourceMDSId: string | undefined) => void;
}

export const Paragraphs = forwardRef((props: ParagraphProps, ref) => {
Expand All @@ -116,7 +127,7 @@ export const Paragraphs = forwardRef((props: ParagraphProps, ref) => {
setActionMenu,
notifications,
savedObjectsMDSClient,
handleSelectedDataSourceChange
handleSelectedDataSourceChange,
} = props;

const [visOptions, setVisOptions] = useState<EuiComboBoxOptionOption[]>([
Expand Down Expand Up @@ -528,24 +539,26 @@ export const Paragraphs = forwardRef((props: ParagraphProps, ref) => {
let DataSourceSelector;
const onSelectedDataSource = (e) => {
const dataConnectionId = e[0] ? e[0].id : undefined;
setDataSourceMDSId(dataConnectionId)
handleSelectedDataSourceChange(dataConnectionId)
}
setDataSourceMDSId(dataConnectionId);
handleSelectedDataSourceChange(dataConnectionId);
};
if (dataSourceEnabled) {
DataSourceSelector = dataSourceManagement.ui.DataSourceSelector;
}
}
return (
<>
<EuiPanel>
{renderParaHeader(!para.isVizualisation ? 'Code block' : 'Visualization', index)}
{dataSourceEnabled && (<DataSourceSelector
savedObjectsClient={savedObjectsMDSClient.client}
notifications={notifications}
onSelectedDataSource={onSelectedDataSource}
disabled={false}
fullWidth={false}
removePrepend={true}
/>)}
{dataSourceEnabled && (
<DataSourceSelector
savedObjectsClient={savedObjectsMDSClient.client}
notifications={notifications}
onSelectedDataSource={onSelectedDataSource}
disabled={false}
fullWidth={false}
removePrepend={true}
/>
)}
<EuiSpacer size="s" />
{/* eslint-disable-next-line jsx-a11y/click-events-have-key-events */}
<div key={index} className={paraClass} onClick={() => paragraphSelector(index)}>
Expand Down
14 changes: 9 additions & 5 deletions server/routes/notebooks/sqlRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,19 @@ import {
} from '../../../../../src/core/server';
import { QueryService } from '../../services/queryService';

export function registerSqlRoute(server: IRouter, service: QueryService, _dataSourceEnabled: boolean) {
export function registerSqlRoute(
server: IRouter,
service: QueryService,
_dataSourceEnabled: boolean
) {
server.post(
{
path: '/api/sql/sqlquery',
validate: {
body: schema.any(),
query: schema.object({
dataSourceMDSId: schema.maybe(schema.string({ defaultValue: '' }))
})
dataSourceMDSId: schema.maybe(schema.string({ defaultValue: '' })),
}),
},
},
async (
Expand All @@ -40,8 +44,8 @@ export function registerSqlRoute(server: IRouter, service: QueryService, _dataSo
validate: {
body: schema.any(),
query: schema.object({
dataSourceMDSId: schema.maybe(schema.string({ defaultValue: '' }))
})
dataSourceMDSId: schema.maybe(schema.string({ defaultValue: '' })),
}),
},
},
async (
Expand Down
12 changes: 5 additions & 7 deletions server/routes/notebooks/vizRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,22 @@ export function registerVizRoute(router: IRouter, dataSourceEnabled: boolean) {
};
try {
let opensearchClientResponse;
let vizResponse;
if (dataSourceEnabled && request.params.dataSourceMDSId) {
const client = await context.dataSource.opensearch.legacy.getClient(
request.params.dataSourceMDSId
);
opensearchClientResponse = await client.callAPI('search', params);
}
else{
} else {
opensearchClientResponse = await context.core.opensearch.legacy.client.callAsCurrentUser(
'search',
params
);
}
const savedVisualizations = opensearchClientResponse.hits.hits;
vizResponse = savedVisualizations.map((vizDocument) => ({
label: vizDocument._source.visualization.title,
key: vizDocument._id.split(':').pop(),
}));
const vizResponse = savedVisualizations.map((vizDocument) => ({
label: vizDocument._source.visualization.title,
key: vizDocument._id.split(':').pop(),
}));
return response.ok({
body: { savedVisualizations: vizResponse },
});
Expand Down
15 changes: 10 additions & 5 deletions server/services/queryService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,23 @@ export class QueryService {
this.client = client;
}

describeQueryInternal = async (request: any, format: string, responseFormat: string, context: any) => {
describeQueryInternal = async (
request: any,
format: string,
responseFormat: string,
context: any
) => {
try {
const queryRequest = {
query: request.body,
};
const params = {
body: JSON.stringify(queryRequest),
};

let client = this.client;
let queryResponse;

const { dataSourceMDSId } = request.query;
if (dataSourceMDSId) {
client = context.dataSource.opensearch.legacy.getClient(dataSourceMDSId);
Expand All @@ -41,7 +46,7 @@ export class QueryService {
} catch (err) {
this.logger.info('error describeQueryInternal');
this.logger.info(err);

return {
data: {
ok: false,
Expand All @@ -51,7 +56,7 @@ export class QueryService {
};
}
};

describeSQLQuery = async (context: any, request: any) => {
return this.describeQueryInternal(request, 'ppl.sqlQuery', 'json', context);
};
Expand Down

0 comments on commit e95d3a9

Please sign in to comment.