From e95d3a94928152e0c219857deb9b6dd5d673430c Mon Sep 17 00:00:00 2001 From: sumukhswamy Date: Wed, 17 Jul 2024 14:01:33 -0700 Subject: [PATCH] linter fixes Signed-off-by: sumukhswamy --- .../components/__tests__/notebook.test.tsx | 1 - .../components/notebooks/components/main.tsx | 11 +++-- .../notebooks/components/notebook.tsx | 19 +++++--- .../paragraph_components/paragraphs.tsx | 45 ++++++++++++------- server/routes/notebooks/sqlRouter.ts | 14 +++--- server/routes/notebooks/vizRouter.ts | 12 +++-- server/services/queryService.ts | 15 ++++--- 7 files changed, 72 insertions(+), 45 deletions(-) diff --git a/public/components/notebooks/components/__tests__/notebook.test.tsx b/public/components/notebooks/components/__tests__/notebook.test.tsx index 3528bcce3f..ba181c763d 100644 --- a/public/components/notebooks/components/__tests__/notebook.test.tsx +++ b/public/components/notebooks/components/__tests__/notebook.test.tsx @@ -82,7 +82,6 @@ describe(' spec', () => { expect(utils.getByText('sample-notebook-1')).toBeInTheDocument(); }); expect(utils.container.firstChild).toMatchSnapshot(); - }); it('Adds a code block', async () => { diff --git a/public/components/notebooks/components/main.tsx b/public/components/notebooks/components/main.tsx index 133713cc72..94573cfc9c 100644 --- a/public/components/notebooks/components/main.tsx +++ b/public/components/notebooks/components/main.tsx @@ -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, diff --git a/public/components/notebooks/components/notebook.tsx b/public/components/notebooks/components/notebook.tsx index a36cff8167..b412672850 100644 --- a/public/components/notebooks/components/notebook.tsx +++ b/public/components/notebooks/components/notebook.tsx @@ -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'; @@ -125,7 +130,7 @@ export class Notebook extends Component { showQueryParagraphError: false, queryParagraphErrorMessage: '', savedObjectNotebook: true, - dataSourceMDSId: '' + dataSourceMDSId: '', }; } @@ -640,20 +645,20 @@ export class Notebook extends Component { }); }; - 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; diff --git a/public/components/notebooks/components/paragraph_components/paragraphs.tsx b/public/components/notebooks/components/paragraph_components/paragraphs.tsx index 888e255aa0..040353e11f 100644 --- a/public/components/notebooks/components/paragraph_components/paragraphs.tsx +++ b/public/components/notebooks/components/paragraph_components/paragraphs.tsx @@ -78,7 +78,12 @@ interface ParagraphProps { paraCount: number; paragraphSelector: (index: number) => void; textValueEditor: (evt: React.ChangeEvent, index: number) => void; - handleKeyPress: (evt: React.KeyboardEvent, para: ParaType, index: number, dataSourceMDSID: string) => void; + handleKeyPress: ( + evt: React.KeyboardEvent, + para: ParaType, + index: number, + dataSourceMDSID: string + ) => void; addPara: (index: number, newParaContent: string, inputType: string) => void; DashboardContainerByValueRenderer: DashboardStart['DashboardContainerByValueRenderer']; deleteVizualization: (uniqueId: string) => void; @@ -86,7 +91,13 @@ interface ParagraphProps { 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; @@ -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) => { @@ -116,7 +127,7 @@ export const Paragraphs = forwardRef((props: ParagraphProps, ref) => { setActionMenu, notifications, savedObjectsMDSClient, - handleSelectedDataSourceChange + handleSelectedDataSourceChange, } = props; const [visOptions, setVisOptions] = useState([ @@ -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 ( <> {renderParaHeader(!para.isVizualisation ? 'Code block' : 'Visualization', index)} - {dataSourceEnabled && ()} + {dataSourceEnabled && ( + + )} {/* eslint-disable-next-line jsx-a11y/click-events-have-key-events */}
paragraphSelector(index)}> diff --git a/server/routes/notebooks/sqlRouter.ts b/server/routes/notebooks/sqlRouter.ts index 514d1a2d36..892076da35 100644 --- a/server/routes/notebooks/sqlRouter.ts +++ b/server/routes/notebooks/sqlRouter.ts @@ -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 ( @@ -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 ( diff --git a/server/routes/notebooks/vizRouter.ts b/server/routes/notebooks/vizRouter.ts index 83f39be95a..481caa063a 100644 --- a/server/routes/notebooks/vizRouter.ts +++ b/server/routes/notebooks/vizRouter.ts @@ -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 }, }); diff --git a/server/services/queryService.ts b/server/services/queryService.ts index 71e25ebfb4..d11e66621d 100644 --- a/server/services/queryService.ts +++ b/server/services/queryService.ts @@ -13,7 +13,12 @@ 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, @@ -21,10 +26,10 @@ export class QueryService { 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); @@ -41,7 +46,7 @@ export class QueryService { } catch (err) { this.logger.info('error describeQueryInternal'); this.logger.info(err); - + return { data: { ok: false, @@ -51,7 +56,7 @@ export class QueryService { }; } }; - + describeSQLQuery = async (context: any, request: any) => { return this.describeQueryInternal(request, 'ppl.sqlQuery', 'json', context); };