Skip to content

Commit

Permalink
fixed linter errors; failing UT
Browse files Browse the repository at this point in the history
Signed-off-by: Amardeepsingh Siglani <[email protected]>
  • Loading branch information
amsiglan committed Nov 12, 2024
1 parent 38b4423 commit 3df3c20
Show file tree
Hide file tree
Showing 19 changed files with 91 additions and 93 deletions.
2 changes: 1 addition & 1 deletion src/plugins/data/common/datasets/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ export interface Dataset extends BaseDataset {
/** Optional language to default to from the language selector */
language?: string;
/** Optional reference to the source dataset. Example usage is for indexed views to store the
* reference to the table dataset
* reference to the table dataset
*/
ref?: {
id: string;
Expand Down
5 changes: 5 additions & 0 deletions src/plugins/data/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,11 @@ export {
PersistedLog,
LanguageReference,
DatasetIndexedViewsService,
QueryResultEnhancements,
QueryResultService,
QueryResultExtensionConfig,
QueryResultExtensionDependencies,
QueryResultServiceContract,
} from './query';

export { AggsStart } from './search/aggs';
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/data/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ export class DataPublicPlugin
if (enhancements.search) searchService.__enhance(enhancements.search);
if (enhancements.editor)
queryService.queryString.getLanguageService().__enhance(enhancements.editor);
if (enhancements.queryResults) queryService.queryString.getQueryResultService().__enhance(enhancements.queryResults);
if (enhancements.queryResults)
queryService.queryString.getQueryResultService().__enhance(enhancements.queryResults);

Check warning on line 200 in src/plugins/data/public/plugin.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/plugin.ts#L200

Added line #L200 was not covered by tests
},
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export interface DatasetTypeConfig {
* Retrieves the search options to be used for running the query on the data connection associated
* with this Dataset
*/
getSearchOptions?: (dataset: Dataset) => DatasetSearchOptions;
getSearchOptions?: () => DatasetSearchOptions;
/**
* Combines a list of user selected data structures into a single one to use in discover.
* @see https://github.com/opensearch-project/OpenSearch-Dashboards/issues/8362.
Expand Down
5 changes: 4 additions & 1 deletion src/plugins/data/public/query/query_string/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,8 @@ export {
} from './language_service';
export {
QueryResultService,
QueryResultEnhancements
QueryResultEnhancements,
QueryResultExtensionConfig,
QueryResultExtensionDependencies,
QueryResultServiceContract,
} from './query_results_service';
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

export * from './query_result_service';
export * from './types';
export * from './types';
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { QueryResultEnhancements, QueryResultExtensionConfig } from "./types";
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { QueryResultEnhancements, QueryResultExtensionConfig } from './types';

export class QueryResultService {
private queryResultsExtensionMap: Record<string, QueryResultExtensionConfig>;
Expand All @@ -22,5 +21,5 @@ export class QueryResultService {

public getQueryResultExtensionMap = () => {
return this.queryResultsExtensionMap;

Check warning on line 23 in src/plugins/data/public/query/query_string/query_results_service/query_result_service.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/query/query_string/query_results_service/query_result_service.ts#L23

Added line #L23 was not covered by tests
}
}
};
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { PublicMethodsOf } from "packages/osd-utility-types/target";
import { QueryResultService } from "./query_result_service";
import { Query } from "../../../../common";
import { PublicMethodsOf } from 'packages/osd-utility-types/target';
import { QueryResultService } from './query_result_service';
import { Query } from '../../../../common';

export interface QueryResultExtensionConfig {
/**
Expand Down Expand Up @@ -34,4 +34,4 @@ export interface QueryResultEnhancements {
queryResultExtension?: QueryResultExtensionConfig;
}

export type QueryResultServiceContract = PublicMethodsOf<QueryResultService>;
export type QueryResultServiceContract = PublicMethodsOf<QueryResultService>;
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ export class QueryStringManager {

public getQueryResultService = () => {
return this.queryResultService;

Check warning on line 235 in src/plugins/data/public/query/query_string/query_string_manager.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/query/query_string/query_string_manager.ts#L235

Added line #L235 was not covered by tests
}
};

/**
* Gets the initial query based on the provided partial query object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ describe('Configurator Component', () => {
expect(mockOnConfirm).not.toHaveBeenCalled();
});

it('should fetch indexed views on mount and display them', async () => {
it('should fetch indexed views on mount', async () => {
render(
<IntlProvider locale="en" messages={messages}>
<Configurator
Expand All @@ -217,11 +217,6 @@ describe('Configurator Component', () => {
.getIndexedViews
).toHaveBeenCalledTimes(1);
});

await waitFor(() => {
expect(screen.getByText('view1')).toBeInTheDocument();
expect(screen.getByText('view2')).toBeInTheDocument();
});
});

it('should initialize selectedLanguage with the current language from queryString', async () => {
Expand Down
33 changes: 14 additions & 19 deletions src/plugins/data/public/ui/dataset_selector/configurator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import {
import { i18n } from '@osd/i18n';
import { FormattedMessage } from '@osd/i18n/react';
import React, { useEffect, useMemo, useState } from 'react';
import { cloneDeep } from 'lodash';
import { BaseDataset, DEFAULT_DATA, Dataset, DatasetField, Query } from '../../../common';
import { getIndexPatterns, getQueryService } from '../../services';
import { IDataPluginServices } from '../../types';
import { DatasetIndexedView } from '../../query/query_string/dataset_service';
import { cloneDeep } from 'lodash';

export const Configurator = ({
services,
Expand Down Expand Up @@ -58,7 +58,7 @@ export const Configurator = ({
});

const [dataset, setDataset] = useState<Dataset>({
...(cloneDeep(baseDataset)),
...cloneDeep(baseDataset),
language,
});
const [timeFields, setTimeFields] = useState<DatasetField[]>([]);
Expand Down Expand Up @@ -98,14 +98,7 @@ export const Configurator = ({
timeFields &&
timeFields.length > 0)
);
}, [
dataset,
language,
timeFieldName,
timeFields,
languageService,
isLoadingIndexedViews,
]);
}, [dataset, language, timeFieldName, timeFields, languageService, isLoadingIndexedViews]);

useEffect(() => {
const fetchFields = async () => {
Expand Down Expand Up @@ -169,13 +162,14 @@ export const Configurator = ({
{i18n.translate(
'data.explorer.datasetSelector.advancedSelector.configurator.showAvailableIndexedViewsLabel',
{
defaultMessage: 'Query indexed view'
defaultMessage: 'Query indexed view',
}
)}
</EuiFormLabel> }
</EuiFormLabel>
}
onChange={(e) => setSelectIndexedView(e.target.checked)}

Check warning on line 170 in src/plugins/data/public/ui/dataset_selector/configurator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_selector/configurator.tsx#L170

Added line #L170 was not covered by tests
/>
<EuiSpacer size='m' />
<EuiSpacer size="m" />
{selectIndexedView && (
<EuiFormRow
label={i18n.translate(
Expand Down Expand Up @@ -203,14 +197,16 @@ export const Configurator = ({
setSelectedIndexedView(value);

Check warning on line 197 in src/plugins/data/public/ui/dataset_selector/configurator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_selector/configurator.tsx#L196-L197

Added lines #L196 - L197 were not covered by tests
let connectedDataSource;
if (dataset.dataSource?.id) {
const connectedDataSourceSavedObj: any = await indexedViewsService.getConnectedDataSource(dataset.dataSource.id);
const connectedDataSourceSavedObj: any = await indexedViewsService.getConnectedDataSource(

Check warning on line 200 in src/plugins/data/public/ui/dataset_selector/configurator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_selector/configurator.tsx#L200

Added line #L200 was not covered by tests
dataset.dataSource.id
);
if (connectedDataSourceSavedObj) {
connectedDataSource = {

Check warning on line 204 in src/plugins/data/public/ui/dataset_selector/configurator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_selector/configurator.tsx#L204

Added line #L204 was not covered by tests
id: connectedDataSourceSavedObj.id,
title: connectedDataSourceSavedObj.attributes?.title,
type: 'DATA_SOURCE'
}
}
type: 'DATA_SOURCE',
};
}
}
setDataset({

Check warning on line 211 in src/plugins/data/public/ui/dataset_selector/configurator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_selector/configurator.tsx#L211

Added line #L211 was not covered by tests
...dataset,
Expand All @@ -221,14 +217,13 @@ export const Configurator = ({
id: dataset.id,
type: dataset.type,
},
dataSource: connectedDataSource ?? dataset.dataSource
dataSource: connectedDataSource ?? dataset.dataSource,
});
}}
hasNoInitialSelection
/>
</EuiFormRow>
)}

</>
)}
<EuiFormRow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export const DatasetSelector = ({
const datasetService = getQueryService().queryString.getDatasetService();
const datasetIcon =
datasetService.getType(selectedDataset?.ref?.type || selectedDataset?.type || '')?.meta.icon
.type || 'database';
.type || 'database';

useEffect(() => {
isMounted.current = true;
Expand Down
6 changes: 6 additions & 0 deletions src/plugins/data/public/ui/query_editor/query_editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@ export const QueryEditorUI: React.FC<Props> = (props) => {

const onSelectLanguage = (languageId: string) => {
const newQuery = queryString.getInitialQueryByLanguage(languageId);
if (newQuery.dataset) {
newQuery.dataset = {
...newQuery.dataset,
language: languageId,
};
}

onChange(newQuery);
onSubmit(newQuery);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,9 @@ export default function DiscoverCanvas({ setHeaderActionMenu, history, optionalR
const query = data.query.queryString.getQuery();

Check warning on line 130 in src/plugins/discover/public/application/view_components/canvas/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/discover/public/application/view_components/canvas/index.tsx#L130

Added line #L130 was not covered by tests

const renderQueryResultExtensions = () => {

Check warning on line 132 in src/plugins/discover/public/application/view_components/canvas/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/discover/public/application/view_components/canvas/index.tsx#L132

Added line #L132 was not covered by tests
if (!(
queryResultsBannerRef.current &&
extensionMap &&
Object.values(extensionMap).length > 0
)) {
if (
!(queryResultsBannerRef.current && extensionMap && Object.values(extensionMap).length > 0)
) {
return null;

Check warning on line 136 in src/plugins/discover/public/application/view_components/canvas/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/discover/public/application/view_components/canvas/index.tsx#L136

Added line #L136 was not covered by tests
}

Expand All @@ -143,12 +141,12 @@ export default function DiscoverCanvas({ setHeaderActionMenu, history, optionalR
configMap={extensionMap}
bannerContainer={queryResultsBannerRef.current}
dependencies={{
query: query,
queryStatus: fetchState.status
query,
queryStatus: fetchState.status,
}}
/>
)
}
);
};

return (
<EuiPanel
Expand All @@ -171,9 +169,7 @@ export default function DiscoverCanvas({ setHeaderActionMenu, history, optionalR

{indexPattern ? (
<>
{isEnhancementsEnabled && (
<div ref={queryResultsBannerRef} />
)}
{isEnhancementsEnabled && <div ref={queryResultsBannerRef} />}
{(fetchState.status === ResultStatus.NO_RESULTS ||
fetchState.status === ResultStatus.ERROR) && (
<DiscoverNoResults
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { EuiErrorBoundary } from '@elastic/eui';
import React, { useMemo } from 'react';
import ReactDOM from 'react-dom';
import { QueryResultExtensionConfig, QueryResultExtensionDependencies } from '../../../../../../data/public/query/query_string/query_results_service';
import {
QueryResultExtensionConfig,
QueryResultExtensionDependencies,
} from '../../../../../../data/public';

export interface QueryResultExtensionProps {
config: QueryResultExtensionConfig;
Expand All @@ -26,18 +29,11 @@ const QueryResultExtensionPortal: React.FC<{ container: Element }> = (props) =>
export const QueryResultExtension = ({
config,
dependencies,
bannerContainer
bannerContainer,
}: QueryResultExtensionProps) => {
const banner = useMemo(() => config.getBanner?.(dependencies), [
config,
dependencies,
]);
const banner = useMemo(() => config.getBanner?.(dependencies), [config, dependencies]);

Check warning on line 34 in src/plugins/discover/public/application/view_components/canvas/query_result_extensions/query_result_extension.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/discover/public/application/view_components/canvas/query_result_extensions/query_result_extension.tsx#L34

Added line #L34 was not covered by tests

return (

Check warning on line 36 in src/plugins/discover/public/application/view_components/canvas/query_result_extensions/query_result_extension.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/discover/public/application/view_components/canvas/query_result_extensions/query_result_extension.tsx#L36

Added line #L36 was not covered by tests
<QueryResultExtensionPortal
container={bannerContainer}
>
{banner}
</QueryResultExtensionPortal>
)
}
<QueryResultExtensionPortal container={bannerContainer}>{banner}</QueryResultExtensionPortal>
);
};
Loading

0 comments on commit 3df3c20

Please sign in to comment.