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

[discover-next][bug] add back data set navigator to control state #7492

Merged
merged 33 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
8a5faff
Revert "Revert "[Discover-next] data set picker (#7426)" (#7479)"
kavilla Jul 25, 2024
a526102
fix(query assist): update reading data source id from dataset manager…
joshuali925 Jul 25, 2024
74b03e9
[Auto Suggest] DQL autosuggest with ANTLR (#7467)
paulstn Jul 25, 2024
44b2fc1
[tests][discover-next] update the tests and async nature of the datas…
kavilla Jul 25, 2024
f55c295
update snapshot
kavilla Jul 25, 2024
af2017b
[DataSet Navigator] Rewire S3 components (#7470)
sejli Jul 25, 2024
2b5881b
Fix UI and detection of external data source in query assist (#7494)
joshuali925 Jul 25, 2024
9f49ce3
pass in index patterns
kavilla Jul 25, 2024
9f68352
[Auto Suggest] Add MDS Support Along with A Few Cleanup and tests (#7…
mengweieric Jul 25, 2024
3fff70e
More styling on query enhancement UI styling (#7496)
abbyhu2000 Jul 25, 2024
27a74ab
[Auto Suggest] DQL Updates (#7498)
paulstn Jul 25, 2024
bf057f2
fix some typing issues
kavilla Jul 25, 2024
254a7f2
delete manual changelogs
kavilla Jul 25, 2024
b33c5b4
fixing sessionId support
sejli Jul 26, 2024
b575ca6
remove height
abbyhu2000 Jul 26, 2024
f66ef3b
Revert "[Auto Suggest] DQL Updates (#7498)"
kavilla Jul 26, 2024
65b9171
Revert "[Auto Suggest] Add MDS Support Along with A Few Cleanup and t…
kavilla Jul 26, 2024
4d1ea50
Revert "[Auto Suggest] DQL autosuggest with ANTLR (#7467)"
kavilla Jul 26, 2024
a77b0db
fixing typing issue
sejli Jul 26, 2024
b887914
remove unused export
sejli Jul 26, 2024
666bae4
fix texts and some state mgmt
kavilla Jul 26, 2024
4a58eda
Merge remote-tracking branch 'lnse/s3-sessionid' into feature/discove…
kavilla Jul 26, 2024
d5f5686
fix file
kavilla Jul 26, 2024
593541d
update snapshot
kavilla Jul 26, 2024
f37f782
Merge remote-tracking branch 'abby/fix_style_top_nav' into feature/di…
kavilla Jul 26, 2024
729f0e3
more clean up
kavilla Jul 26, 2024
b09c906
default to false
kavilla Jul 26, 2024
ca2b837
only push the set with enhancements
kavilla Jul 26, 2024
0964ec9
fix two tests
kavilla Jul 26, 2024
fef6156
render hell
kavilla Jul 26, 2024
861af9b
test update
kavilla Jul 26, 2024
2f5ed13
passing in settings
kavilla Jul 26, 2024
6ff7e26
add changelog
kavilla Jul 26, 2024
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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/plugins/data/common/data_frames/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,18 +183,18 @@
};

if (data && data.fields && data.fields.length > 0) {
for (let index = 0; index < data.size; index++) {
const hit: { [key: string]: any } = {};
data.fields.forEach((field) => {
hit[field.name] = field.values[index];

Check warning on line 189 in src/plugins/data/common/data_frames/utils.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/common/data_frames/utils.ts#L186-L189

Added lines #L186 - L189 were not covered by tests
});
hits.push({

Check warning on line 191 in src/plugins/data/common/data_frames/utils.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/common/data_frames/utils.ts#L191

Added line #L191 was not covered by tests
_index: data.name,
_source: hit,
});
}
}
searchResponse.hits.hits = hits;

Check warning on line 197 in src/plugins/data/common/data_frames/utils.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/common/data_frames/utils.ts#L197

Added line #L197 was not covered by tests

if (data.hasOwnProperty('aggs')) {
const dataWithAggs = data as IDataFrameWithAggs;
Expand Down Expand Up @@ -291,14 +291,14 @@
aggConfig?: DataFrameAggConfig
): Partial<IFieldType> | undefined => {
if (queryConfig?.timeFieldName) {
return {

Check warning on line 294 in src/plugins/data/common/data_frames/utils.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/common/data_frames/utils.ts#L294

Added line #L294 was not covered by tests
name: queryConfig.timeFieldName,
type: 'date',
};
}
const fields = data.schema || data.fields;
if (!fields) {
throw Error('Invalid time field');

Check warning on line 301 in src/plugins/data/common/data_frames/utils.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/common/data_frames/utils.ts#L301

Added line #L301 was not covered by tests
}
return aggConfig && aggConfig.date_histogram && aggConfig.date_histogram.field
? fields.find((field) => field.name === aggConfig?.date_histogram?.field)
Expand Down Expand Up @@ -484,6 +484,11 @@
id: id ?? DATA_FRAME_TYPES.DEFAULT,
title: dataFrame.name,
timeFieldName: getTimeField(dataFrame, dataFrame.meta?.queryConfig)?.name,
dataSourceRef: {
id: dataFrame.meta?.queryConfig?.dataSourceId,
name: dataFrame.meta?.queryConfig?.dataSourceName,
type: dataFrame.meta?.queryConfig?.dataSourceType,
},
type: !id ? DATA_FRAME_TYPES.DEFAULT : undefined,
fields: fields.reduce(flattenFields, {} as IndexPatternFieldMap),
};
Expand Down
4 changes: 0 additions & 4 deletions src/plugins/data/common/search/opensearch_search/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ export interface ISearchOptions {
* Use this option to enable support for long numerals.
*/
withLongNumeralsSupport?: boolean;
/**
* Use this option to enable support for async.
*/
isAsync?: boolean;
Copy link
Member

Choose a reason for hiding this comment

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

Did we put this somewhere else?

}

export type ISearchRequestParams<T = Record<string, any>> = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import { SqlErrorListener } from './sql_error_listerner';
import { findCursorTokenIndex } from '../shared/cursor';
import { openSearchSqlAutocompleteData } from './opensearch_sql_autocomplete';
import { getUiSettings } from '../../services';
import { SQL_SYMBOLS } from './constants';
import { QuerySuggestion, QuerySuggestionGetFnArgs } from '../../autocomplete';
import { fetchColumnValues, fetchTableSchemas } from '../shared/utils';
Expand All @@ -46,8 +45,8 @@
query,
services,
}: QuerySuggestionGetFnArgs): Promise<QuerySuggestion[]> => {
const { api } = services.uiSettings;
const dataSetManager = services.data.query.dataSet;

Check warning on line 49 in src/plugins/data/public/antlr/opensearch_sql/code_completion.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/antlr/opensearch_sql/code_completion.ts#L48-L49

Added lines #L48 - L49 were not covered by tests
const suggestions = getOpenSearchSqlAutoCompleteSuggestions(query, {
line: position?.lineNumber || selectionStart,
column: position?.column || selectionEnd,
Expand All @@ -59,12 +58,12 @@
// Fetch columns and values
if ('suggestColumns' in suggestions && (suggestions.suggestColumns?.tables?.length ?? 0) > 0) {
const tableNames = suggestions.suggestColumns?.tables?.map((table) => table.name) ?? [];
const schemas = await fetchTableSchemas(tableNames, api, services);

Check warning on line 61 in src/plugins/data/public/antlr/opensearch_sql/code_completion.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/antlr/opensearch_sql/code_completion.ts#L61

Added line #L61 was not covered by tests

schemas.forEach((schema) => {
if (schema.body?.fields?.length > 0) {
const columns = schema.body.fields.find((col: any) => col.name === 'COLUMN_NAME');
const fieldTypes = schema.body.fields.find((col: any) => col.name === 'DATA_TYPE');

Check warning on line 66 in src/plugins/data/public/antlr/opensearch_sql/code_completion.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/antlr/opensearch_sql/code_completion.ts#L65-L66

Added lines #L65 - L66 were not covered by tests
if (columns && fieldTypes) {
finalSuggestions.push(
...columns.values.map((col: string, index: number) => ({
Expand All @@ -86,7 +85,7 @@
tableNames,
suggestions.suggestValuesForColumn as string,
api,
connectionService
services
Copy link
Contributor

Choose a reason for hiding this comment

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

might need to remove these lines from here, since the other autocomplete prs were removed from this branch. this change was added in this commit, would only need to revert the changes done on this file: bf057f2#diff-f67c8b1b68c9ae8eeb8ea7d7dea38e59d32b7738dec7c9db5763cf74b96aa92fR46

);
values.forEach((value) => {
if (value.body?.fields?.length > 0) {
Expand Down
3 changes: 3 additions & 0 deletions src/plugins/data/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,9 @@ export {
// for BWC, keeping the old name
IUiStart as DataPublicPluginStartUi,
DataSetNavigator,
setAsyncSessionId,
getAsyncSessionId,
setAsyncSessionIdByObj,
} from './ui';

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
import { DataSetManager } from './dataset_manager';
import { coreMock } from '../../../../../core/public/mocks';
import { SimpleDataSet } from '../../../common';

describe('DataSetManager', () => {
let service: DataSetManager;

beforeEach(() => {
service = new DataSetManager(coreMock.createSetup().uiSettings);
const uiSettingsMock = coreMock.createSetup().uiSettings;
uiSettingsMock.get.mockReturnValue(true);
service = new DataSetManager(uiSettingsMock);
});

test('getUpdates$ emits initially and after data set changes', () => {
Expand All @@ -20,15 +21,15 @@ describe('DataSetManager', () => {
obs$.subscribe((v) => {
emittedValues.push(v);
});
expect(emittedValues).toHaveLength(1);
expect(emittedValues[1]).toEqual(undefined);
expect(emittedValues).toHaveLength(0);
expect(emittedValues[0]).toEqual(undefined);

const newDataSet: SimpleDataSet = { id: 'test_dataset', title: 'Test Dataset' };
service.setDataSet(newDataSet);
expect(emittedValues).toHaveLength(2);
expect(emittedValues[1]).toEqual(newDataSet);
expect(emittedValues).toHaveLength(1);
expect(emittedValues[0]).toEqual(newDataSet);

service.setDataSet({ ...newDataSet });
expect(emittedValues).toHaveLength(3);
expect(emittedValues).toHaveLength(2);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@

import { BehaviorSubject } from 'rxjs';
import { CoreStart } from 'opensearch-dashboards/public';
import { SIMPLE_DATA_SET_TYPES, SimpleDataSet, SimpleDataSource } from '../../../common';
import { skip } from 'rxjs/operators';
import {
SIMPLE_DATA_SET_TYPES,
SimpleDataSet,
SimpleDataSource,
UI_SETTINGS,
} from '../../../common';
import { IndexPatternsContract } from '../../index_patterns';

export class DataSetManager {
Expand All @@ -24,7 +30,7 @@
};

public getUpdates$ = () => {
return this.dataSet$.asObservable();
return this.dataSet$.asObservable().pipe(skip(1));
};

public getDataSet = () => {
Expand All @@ -36,6 +42,7 @@
* @param {Query} query
*/
public setDataSet = (dataSet: SimpleDataSet | undefined) => {
if (!this.uiSettings.get(UI_SETTINGS.QUERY_ENHANCEMENTS_ENABLED)) return;
this.dataSet$.next(dataSet);
};

Expand All @@ -46,7 +53,7 @@
public fetchDefaultDataSet = async (): Promise<SimpleDataSet | undefined> => {
const defaultIndexPatternId = this.uiSettings.get('defaultIndex');
if (!defaultIndexPatternId) {
return undefined;

Check warning on line 56 in src/plugins/data/public/query/dataset_manager/dataset_manager.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/query/dataset_manager/dataset_manager.ts#L56

Added line #L56 was not covered by tests
}

const indexPattern = await this.indexPatterns?.get(defaultIndexPatternId);
Expand All @@ -55,10 +62,10 @@
}

if (!indexPattern.id) {
return undefined;

Check warning on line 65 in src/plugins/data/public/query/dataset_manager/dataset_manager.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/query/dataset_manager/dataset_manager.ts#L65

Added line #L65 was not covered by tests
}

return {

Check warning on line 68 in src/plugins/data/public/query/dataset_manager/dataset_manager.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/query/dataset_manager/dataset_manager.ts#L68

Added line #L68 was not covered by tests
id: indexPattern.id,
title: indexPattern.title,
type: SIMPLE_DATA_SET_TYPES.INDEX_PATTERN,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,19 @@
import { Subscription } from 'rxjs';
import { filter, map } from 'rxjs/operators';
import _ from 'lodash';
import { CoreStart } from 'opensearch-dashboards/public';
import {
BaseStateContainer,
IOsdUrlStateStorage,
} from '../../../../opensearch_dashboards_utils/public';
import { QuerySetup, QueryStart } from '../query_service';
import { QueryState, QueryStateChange } from './types';
import { FilterStateStore, COMPARE_ALL_OPTIONS, compareFilters } from '../../../common';
import {
FilterStateStore,
COMPARE_ALL_OPTIONS,
compareFilters,
UI_SETTINGS,
} from '../../../common';
import { validateTimeRange } from '../timefilter';

/**
Expand All @@ -63,7 +69,8 @@
filters: FilterStateStore;
query: boolean;
dataSet?: boolean;
}
},
uiSettings?: CoreStart['uiSettings']
) => {
try {
const syncKeys: Array<keyof QueryStateChange> = [];
Expand All @@ -74,13 +81,16 @@
syncKeys.push('appFilters');
}
if (syncConfig.dataSet) {
syncKeys.push('dataSet');

Check warning on line 84 in src/plugins/data/public/query/state_sync/connect_to_query_state.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/query/state_sync/connect_to_query_state.ts#L84

Added line #L84 was not covered by tests
}

const initialStateFromURL: QueryState = OsdUrlStateStorage.get('_q') ?? {
query: queryString.getDefaultQuery(),
filters: filterManager.getAppFilters(),
dataSet: dataSet.getDefaultDataSet(),
...(uiSettings &&
uiSettings.get(UI_SETTINGS.QUERY_ENHANCEMENTS_ENABLED) && {
dataSet: dataSet.getDataSet(),
}),
};

// set up initial '_q' flag in the URL to sync query and filter changes
Expand All @@ -98,11 +108,11 @@

if (syncConfig.dataSet && !_.isEqual(initialStateFromURL.dataSet, dataSet.getDataSet())) {
if (initialStateFromURL.dataSet) {
dataSet.setDataSet(_.cloneDeep(initialStateFromURL.dataSet));

Check warning on line 111 in src/plugins/data/public/query/state_sync/connect_to_query_state.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/query/state_sync/connect_to_query_state.ts#L111

Added line #L111 was not covered by tests
} else {
const defaultDataSet = await dataSet.getDefaultDataSet();

Check warning on line 113 in src/plugins/data/public/query/state_sync/connect_to_query_state.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/query/state_sync/connect_to_query_state.ts#L113

Added line #L113 was not covered by tests
if (defaultDataSet) {
dataSet.setDataSet(defaultDataSet);

Check warning on line 115 in src/plugins/data/public/query/state_sync/connect_to_query_state.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/query/state_sync/connect_to_query_state.ts#L115

Added line #L115 was not covered by tests
}
}
}
Expand Down Expand Up @@ -140,7 +150,7 @@
}

if (syncConfig.dataSet && changes.dataSet) {
newState.dataSet = dataSet.getDataSet();

Check warning on line 153 in src/plugins/data/public/query/state_sync/connect_to_query_state.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/query/state_sync/connect_to_query_state.ts#L153

Added line #L153 was not covered by tests
}

return newState;
Expand Down Expand Up @@ -310,7 +320,7 @@
}
}
if (syncConfig.dataSet && changes.dataSet) {
newState.dataSet = dataSet.getDataSet();

Check warning on line 323 in src/plugins/data/public/query/state_sync/connect_to_query_state.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/query/state_sync/connect_to_query_state.ts#L323

Added line #L323 was not covered by tests
}
return newState;
})
Expand Down Expand Up @@ -375,12 +385,12 @@
const currentDataSet = dataSet.getDataSet();
if (!_.isEqual(state.dataSet, currentDataSet)) {
if (state.dataSet) {
dataSet.setDataSet(state.dataSet);

Check warning on line 388 in src/plugins/data/public/query/state_sync/connect_to_query_state.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/query/state_sync/connect_to_query_state.ts#L388

Added line #L388 was not covered by tests
} else {
const defaultDataSet = await dataSet.getDefaultDataSet();

Check warning on line 390 in src/plugins/data/public/query/state_sync/connect_to_query_state.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/query/state_sync/connect_to_query_state.ts#L390

Added line #L390 was not covered by tests
if (defaultDataSet) {
dataSet.setDataSet(defaultDataSet);
stateContainer.set({ ...stateContainer.get(), dataSet: defaultDataSet });

Check warning on line 393 in src/plugins/data/public/query/state_sync/connect_to_query_state.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/query/state_sync/connect_to_query_state.ts#L392-L393

Added lines #L392 - L393 were not covered by tests
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* under the License.
*/

import { CoreStart } from 'opensearch-dashboards/public';
import {
createStateContainer,
IOsdUrlStateStorage,
Expand All @@ -37,6 +38,7 @@ import { QuerySetup, QueryStart } from '../query_service';
import { connectToQueryState } from './connect_to_query_state';
import { QueryState } from './types';
import { FilterStateStore } from '../../../common/opensearch_query/filters';
import { UI_SETTINGS } from '../../../common';

const GLOBAL_STATE_STORAGE_KEY = '_g';

Expand All @@ -50,7 +52,8 @@ export const syncQueryStateWithUrl = (
QueryStart | QuerySetup,
'filterManager' | 'timefilter' | 'queryString' | 'dataSet' | 'state$'
>,
osdUrlStateStorage: IOsdUrlStateStorage
osdUrlStateStorage: IOsdUrlStateStorage,
uiSettings?: CoreStart['uiSettings']
) => {
const {
timefilter: { timefilter },
Expand All @@ -61,7 +64,10 @@ export const syncQueryStateWithUrl = (
time: timefilter.getTime(),
refreshInterval: timefilter.getRefreshInterval(),
filters: filterManager.getGlobalFilters(),
dataSet: dataSet.getDataSet(),
...(uiSettings &&
uiSettings.get(UI_SETTINGS.QUERY_ENHANCEMENTS_ENABLED) && {
dataSet: dataSet.getDataSet(),
}),
};

// retrieve current state from `_g` url
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/public/search/search_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,21 +135,21 @@
{ fieldFormats, indexPatterns }: SearchServiceStartDependencies
): ISearchStart {
const search = ((request, options) => {
const selectedLanguage = getQueryService().queryString.getQuery().language;
const uiService = getUiService();
const enhancement = uiService.Settings.getQueryEnhancements(selectedLanguage);
uiService.Settings.setUiOverridesByUserQueryLanguage(selectedLanguage);
const isEnhancedEnabled = uiSettings.get(UI_SETTINGS.QUERY_ENHANCEMENTS_ENABLED);

Check warning on line 142 in src/plugins/data/public/search/search_service.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/search/search_service.ts#L138-L142

Added lines #L138 - L142 were not covered by tests

if (enhancement) {
if (!isEnhancedEnabled) {
notifications.toasts.addWarning(

Check warning on line 146 in src/plugins/data/public/search/search_service.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/search/search_service.ts#L146

Added line #L146 was not covered by tests
`Query enhancements are disabled. Please enable to use: ${selectedLanguage}.`
);
}
return enhancement.search.search(request, options);

Check warning on line 150 in src/plugins/data/public/search/search_service.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/search/search_service.ts#L150

Added line #L150 was not covered by tests
}
return this.defaultSearchInterceptor.search(request, options);

Check warning on line 152 in src/plugins/data/public/search/search_service.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/search/search_service.ts#L152

Added line #L152 was not covered by tests
}) as ISearchGeneric;

const loadingCount$ = new BehaviorSubject(0);
Expand All @@ -161,6 +161,7 @@
if (this.dfCache.get() && this.dfCache.get()?.name !== dataFrame.name) {
indexPatterns.clearCache(this.dfCache.get()!.name, false);
}

if (
dataFrame.meta &&
dataFrame.meta.queryConfig &&
Expand All @@ -173,13 +174,12 @@
}
this.dfCache.set(dataFrame);
const dataSetName = `${dataFrame.meta?.queryConfig?.dataSourceId ?? ''}.${dataFrame.name}`;
const existingIndexPattern = await indexPatterns.get(dataSetName, true);

Check warning on line 177 in src/plugins/data/public/search/search_service.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/search/search_service.ts#L177

Added line #L177 was not covered by tests
const dataSet = await indexPatterns.create(
dataFrameToSpec(dataFrame, existingIndexPattern?.id ?? dataSetName),
!existingIndexPattern?.id
);
await indexPatterns.refreshFields(dataSet, true);
indexPatterns.saveToCache(dataSetName, dataSet);

Check warning on line 182 in src/plugins/data/public/search/search_service.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/search/search_service.ts#L182

Added line #L182 was not covered by tests
},
clear: () => {
if (this.dfCache.get() === undefined) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,16 @@
}

export const DataSetNavigator = (props: DataSetNavigatorProps) => {
const { savedObjectsClient, http, dataSet: dataSetManager } = props;
const searchService = getSearchService();
const queryService = getQueryService();
const uiService = getUiService();
const indexPatternsService = getIndexPatterns();
const notifications = getNotifications();

Check warning on line 82 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L77-L82

Added lines #L77 - L82 were not covered by tests

const { dataSet } = useDataSetManager({ dataSetManager: dataSetManager! });

Check warning on line 84 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L84

Added line #L84 was not covered by tests

const [navigatorState, setNavigatorState] = useState<DataSetNavigatorState>({

Check warning on line 86 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L86

Added line #L86 was not covered by tests
isOpen: false,
isLoading: false,
isMounted: false,
Expand All @@ -97,37 +97,37 @@
cachedTables: [],
});

const [selectedDataSetState, setSelectedDataSetState] = useState<SelectedDataSetState>();

Check warning on line 100 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L100

Added line #L100 was not covered by tests

const {
loadStatus: dataSourcesLoadStatus,
loadExternalDataSources: startLoadingDataSources,
} = useLoadExternalDataSourcesToCache(http!, notifications);

Check warning on line 105 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L105

Added line #L105 was not covered by tests
const {
loadStatus: databasesLoadStatus,
startLoading: startLoadingDatabases,
} = useLoadDatabasesToCache(http!, notifications);
const { loadStatus: tablesLoadStatus, startLoading: startLoadingTables } = useLoadTablesToCache(

Check warning on line 110 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L109-L110

Added lines #L109 - L110 were not covered by tests
http!,
notifications
);

const onClick = () => {
setNavigatorState((prevState) => ({

Check warning on line 116 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L115-L116

Added lines #L115 - L116 were not covered by tests
...prevState,
isOpen: !prevState.isOpen,
}));
};

const isLoading = (loading: boolean) => {
setNavigatorState((prevState) => ({

Check warning on line 123 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L122-L123

Added lines #L122 - L123 were not covered by tests
...prevState,
isLoading: loading,
}));
};

const closePopover = () => {
setNavigatorState((prevState) => ({

Check warning on line 130 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L129-L130

Added lines #L129 - L130 were not covered by tests
...prevState,
isOpen: false,
externalDataSources: [],
Expand All @@ -138,33 +138,33 @@
}));
};

const onRefresh = () => {

Check warning on line 141 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L141

Added line #L141 was not covered by tests
if (!isCatalogCacheFetching(dataSourcesLoadStatus) && navigatorState.dataSources.length > 0) {
startLoadingDataSources(navigatorState.dataSources.map((dataSource) => dataSource.id));

Check warning on line 143 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L143

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

const handleSelectedDataSet = useCallback(

Check warning on line 147 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L147

Added line #L147 was not covered by tests
async (ds?: SimpleDataSet) => {
const selectedDataSet = ds ?? navigatorState.currentDataSet;
if (!selectedDataSet || !selectedDataSet.id) return;

const language = uiService.Settings.getUserQueryLanguage();
const queryEnhancements = uiService.Settings.getQueryEnhancements(language);
const initialInput = queryEnhancements?.searchBar?.queryStringInput?.initialValue;

Check warning on line 154 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L152-L154

Added lines #L152 - L154 were not covered by tests

// Update query
const query = initialInput
? initialInput.replace('<data_source>', selectedDataSet.title!)
: '';
uiService.Settings.setUserQueryString(query);
queryService.queryString.setQuery({ query, language });

Check warning on line 161 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L160-L161

Added lines #L160 - L161 were not covered by tests

// Update dataset
queryService.dataSet.setDataSet(selectedDataSet);

Check warning on line 164 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L164

Added line #L164 was not covered by tests

// Add to recent datasets
CatalogCacheManager.addRecentDataSet({

Check warning on line 167 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L167

Added line #L167 was not covered by tests
id: selectedDataSet.id,
title: selectedDataSet.title ?? selectedDataSet.id!,
dataSourceRef: selectedDataSet.dataSourceRef,
Expand All @@ -173,7 +173,7 @@
});

// Update data set manager
dataSetManager!.setDataSet({

Check warning on line 176 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L176

Added line #L176 was not covered by tests
id: selectedDataSet.id,
title: selectedDataSet.title,
...(selectedDataSet.dataSourceRef && {
Expand All @@ -187,9 +187,7 @@
type: selectedDataSet.type,
});

setSelectedDataSetState(selectedDataSet);

closePopover();

Check warning on line 190 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L190

Added line #L190 was not covered by tests
},
[
dataSetManager,
Expand All @@ -200,9 +198,9 @@
]
);

useEffect(() => {
setNavigatorState((prevState) => ({ ...prevState, isMounted: true, isLoading: true }));
Promise.all([

Check warning on line 203 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L201-L203

Added lines #L201 - L203 were not covered by tests
dataSetManager?.init(indexPatternsService),
fetchIndexPatterns(savedObjectsClient!, ''),
fetchDataSources(savedObjectsClient!),
Expand All @@ -210,7 +208,7 @@
])
.then(([defaultDataSet, indexPatterns, dataSources, isExternalDataSourcesEnabled]) => {
if (!navigatorState.isMounted) return;
setNavigatorState((prevState) => ({

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

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L211

Added line #L211 was not covered by tests
...prevState,
isExternalDataSourcesEnabled,
indexPatterns,
Expand All @@ -220,7 +218,7 @@
const selectedPattern = dataSet ?? defaultDataSet;

if (selectedPattern) {
setSelectedDataSetState({

Check warning on line 221 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L221

Added line #L221 was not covered by tests
id: selectedPattern.id,
title: selectedPattern.title,
type: selectedPattern.type,
Expand All @@ -240,28 +238,27 @@
}
})
.finally(() => {
isLoading(false);

Check warning on line 241 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L241

Added line #L241 was not covered by tests
});
return () => {
setNavigatorState((prevState) => ({ ...prevState, isMounted: false }));

Check warning on line 244 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L243-L244

Added lines #L243 - L244 were not covered by tests
};
}, [
savedObjectsClient,
http,
navigatorState.isMounted,
dataSet,
dataSetManager,
http,
indexPatternsService,
handleSelectedDataSet,
navigatorState.isMounted,
savedObjectsClient,
]);

useEffect(() => {
const status = dataSourcesLoadStatus.toLowerCase();
const externalDataSourcesCache = CatalogCacheManager.getExternalDataSourcesCache();

Check warning on line 257 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L255-L257

Added lines #L255 - L257 were not covered by tests
if (status === DirectQueryLoadingStatus.SUCCESS) {
setNavigatorState((prevState) => ({

Check warning on line 259 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L259

Added line #L259 was not covered by tests
...prevState,
externalDataSources: externalDataSourcesCache.externalDataSources.map((ds) => ({

Check warning on line 261 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L261

Added line #L261 was not covered by tests
id: ds.dataSourceRef,
name: ds.name,
type: SIMPLE_DATA_SOURCE_TYPES.EXTERNAL,
Expand All @@ -271,22 +268,22 @@
status === DirectQueryLoadingStatus.CANCELED ||
status === DirectQueryLoadingStatus.FAILED
) {
setNavigatorState((prevState) => ({ ...prevState, failed: true }));

Check warning on line 271 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L271

Added line #L271 was not covered by tests
}
}, [dataSourcesLoadStatus]);

useEffect(() => {
const status = databasesLoadStatus.toLowerCase();

Check warning on line 276 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L275-L276

Added lines #L275 - L276 were not covered by tests
if (
selectedDataSetState?.dataSourceRef &&
selectedDataSetState.dataSourceRef.type === SIMPLE_DATA_SOURCE_TYPES.EXTERNAL
) {
const dataSourceCache = CatalogCacheManager.getOrCreateDataSource(

Check warning on line 281 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L281

Added line #L281 was not covered by tests
selectedDataSetState.dataSourceRef.name,
selectedDataSetState.dataSourceRef.id
);
if (status === DirectQueryLoadingStatus.SUCCESS) {
setNavigatorState((prevState) => ({

Check warning on line 286 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L286

Added line #L286 was not covered by tests
...prevState,
cachedDatabases: dataSourceCache.databases,
}));
Expand All @@ -294,15 +291,15 @@
status === DirectQueryLoadingStatus.CANCELED ||
status === DirectQueryLoadingStatus.FAILED
) {
setNavigatorState((prevState) => ({ ...prevState, failed: true }));

Check warning on line 294 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L294

Added line #L294 was not covered by tests
}
}
}, [databasesLoadStatus, selectedDataSetState?.dataSourceRef]);

const handleSelectExternalDataSource = useCallback(

Check warning on line 299 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L299

Added line #L299 was not covered by tests
async (dataSource) => {
if (dataSource && dataSource.type === SIMPLE_DATA_SOURCE_TYPES.EXTERNAL) {
const dataSourceCache = CatalogCacheManager.getOrCreateDataSource(

Check warning on line 302 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L302

Added line #L302 was not covered by tests
dataSource.name,
dataSource.id
);
Expand All @@ -311,17 +308,17 @@
dataSourceCache.status === CachedDataSourceStatus.Failed) &&
!isCatalogCacheFetching(databasesLoadStatus)
) {
await startLoadingDatabases({

Check warning on line 311 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L311

Added line #L311 was not covered by tests
dataSourceName: dataSource.name,
dataSourceMDSId: dataSource.id,
});
} else if (dataSourceCache.status === CachedDataSourceStatus.Updated) {
setNavigatorState((prevState) => ({

Check warning on line 316 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L316

Added line #L316 was not covered by tests
...prevState,
cachedDatabases: dataSourceCache.databases,
}));
}
setSelectedDataSetState((prevState) => ({

Check warning on line 321 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L321

Added line #L321 was not covered by tests
...prevState,
dataSourceRef: dataSource,
isExternal: true,
Expand All @@ -332,33 +329,36 @@
);

// Start loading tables for selected database
const handleSelectExternalDatabase = useCallback(

Check warning on line 332 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L332

Added line #L332 was not covered by tests
(externalDatabase: SimpleDataSource) => {
if (selectedDataSetState?.dataSourceRef && externalDatabase) {
let databaseCache: CachedDatabase;
try {
databaseCache = CatalogCacheManager.getDatabase(

Check warning on line 337 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L336-L337

Added lines #L336 - L337 were not covered by tests
selectedDataSetState.dataSourceRef.name,
externalDatabase.name,
selectedDataSetState.dataSourceRef.id
);
} catch (error) {
return;

Check warning on line 343 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L343

Added line #L343 was not covered by tests
}
if (
databaseCache.status === CachedDataSourceStatus.Empty ||
(databaseCache.status === CachedDataSourceStatus.Failed &&
!isCatalogCacheFetching(tablesLoadStatus))
) {
startLoadingTables({

Check warning on line 350 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L350

Added line #L350 was not covered by tests
dataSourceName: selectedDataSetState.dataSourceRef.name,
databaseName: externalDatabase.name,
dataSourceMDSId: selectedDataSetState.dataSourceRef.id,
});
} else if (databaseCache.status === CachedDataSourceStatus.Updated) {
setNavigatorState((prevState) => ({

Check warning on line 356 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L356

Added line #L356 was not covered by tests
...prevState,
cachedTables: databaseCache.tables,
cachedTables: databaseCache.tables.map((table) => ({

Check warning on line 358 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L358

Added line #L358 was not covered by tests
id: table.name,
title: table.name,
})),
}));
}
}
Expand All @@ -367,33 +367,36 @@
);

// Retrieve tables from cache upon success
useEffect(() => {

Check warning on line 370 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L370

Added line #L370 was not covered by tests
if (
selectedDataSetState?.dataSourceRef &&
selectedDataSetState.dataSourceRef?.type === SIMPLE_DATA_SOURCE_TYPES.EXTERNAL &&
selectedDataSetState.database
) {
const tablesStatus = tablesLoadStatus.toLowerCase();

Check warning on line 376 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L376

Added line #L376 was not covered by tests
let databaseCache: CachedDatabase;
try {
databaseCache = CatalogCacheManager.getDatabase(

Check warning on line 379 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L378-L379

Added lines #L378 - L379 were not covered by tests
selectedDataSetState.dataSourceRef.name,
selectedDataSetState.database,
selectedDataSetState.dataSourceRef.id
);
} catch (error) {
return;

Check warning on line 385 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L385

Added line #L385 was not covered by tests
}
if (tablesStatus === DirectQueryLoadingStatus.SUCCESS) {
setNavigatorState((prevState) => ({

Check warning on line 388 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L388

Added line #L388 was not covered by tests
...prevState,
cachedTables: databaseCache.tables,
cachedTables: databaseCache.tables.map((table) => ({

Check warning on line 390 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L390

Added line #L390 was not covered by tests
id: table.name,
title: table.name,
})),
}));
} else if (
tablesStatus === DirectQueryLoadingStatus.CANCELED ||
tablesStatus === DirectQueryLoadingStatus.FAILED
) {
notifications.toasts.addWarning('Error loading tables');

Check warning on line 399 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L399

Added line #L399 was not covered by tests
}
}
}, [
Expand All @@ -403,16 +406,16 @@
notifications.toasts,
]);

const handleSelectedDataSource = useCallback(

Check warning on line 409 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L409

Added line #L409 was not covered by tests
async (source: SimpleDataSource) => {
if (source) {
isLoading(true);
const indices = await fetchIndices(searchService, source.id);
setNavigatorState((prevState) => ({

Check warning on line 414 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L412-L414

Added lines #L412 - L414 were not covered by tests
...prevState,
currentDataSourceRef: {
...source,
indices: indices.map((indexName: string) => ({

Check warning on line 418 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L418

Added line #L418 was not covered by tests
id: indexName,
title: indexName,
dataSourceRef: {
Expand All @@ -423,24 +426,24 @@
})),
},
}));
isLoading(false);

Check warning on line 429 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L429

Added line #L429 was not covered by tests
}
},
[searchService]
);

const handleSelectedObject = useCallback(

Check warning on line 435 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L435

Added line #L435 was not covered by tests
async (object) => {
if (object) {
isLoading(true);
const fields = await indexPatternsService.getFieldsForWildcard({

Check warning on line 439 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L438-L439

Added lines #L438 - L439 were not covered by tests
pattern: object.title,
dataSourceId: object.dataSourceRef?.id,
});

const timeFields = fields.filter((field: any) => field.type === 'date');

Check warning on line 444 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L444

Added line #L444 was not covered by tests
const timeFieldName = timeFields?.length > 0 ? timeFields[0].name : undefined;
setNavigatorState((prevState) => ({

Check warning on line 446 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L446

Added line #L446 was not covered by tests
...prevState,
currentDataSet: {
id: `${object.dataSourceRef ? object.dataSourceRef.id : ''}.${object.id}`,
Expand All @@ -448,69 +451,70 @@
fields,
timeFields,
timeFieldName,
dataSourceRef: object.dataSourceRef,
type: SIMPLE_DATA_SET_TYPES.TEMPORARY,
},
}));
isLoading(false);

Check warning on line 458 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L458

Added line #L458 was not covered by tests
}
},
[indexPatternsService]
);

const indexPatternsLabel = i18n.translate('data.query.dataSetNavigator.indexPatternsName', {

Check warning on line 464 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L464

Added line #L464 was not covered by tests
defaultMessage: 'Index patterns',
});
const indicesLabel = i18n.translate('data.query.dataSetNavigator.indicesName', {

Check warning on line 467 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L467

Added line #L467 was not covered by tests
defaultMessage: 'Indexes',
});
const S3DataSourcesLabel = i18n.translate('data.query.dataSetNavigator.S3DataSourcesLabel', {

Check warning on line 470 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L470

Added line #L470 was not covered by tests
defaultMessage: 'S3',
});

const createRefreshButton = () => (
<EuiButtonEmpty

Check warning on line 475 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L474-L475

Added lines #L474 - L475 were not covered by tests
iconType="refresh"
onClick={onRefresh}
isLoading={isCatalogCacheFetching(databasesLoadStatus, tablesLoadStatus)}
/>
);

const createLoadingSpinner = () => (
<EuiPanel hasShadow={false} hasBorder={false}>

Check warning on line 483 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L482-L483

Added lines #L482 - L483 were not covered by tests
<EuiLoadingSpinner className="dataSetNavigator__loading" size="m" />
</EuiPanel>
);

const createIndexPatternsPanel = () => ({

Check warning on line 488 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L488

Added line #L488 was not covered by tests
id: 1,
title: indexPatternsLabel,
items: navigatorState.indexPatterns.map((indexPattern) => ({

Check warning on line 491 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L491

Added line #L491 was not covered by tests
name: indexPattern.title,
onClick: async () => await handleSelectedDataSet(indexPattern),

Check warning on line 493 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L493

Added line #L493 was not covered by tests
})),
content: <div>{navigatorState.indexPatterns.length === 0 && createLoadingSpinner()}</div>,
});

const createIndexesPanel = () => ({

Check warning on line 498 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L498

Added line #L498 was not covered by tests
id: 2,
title: indicesLabel,
items: [
...navigatorState.dataSources.map((dataSource) => ({

Check warning on line 502 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L502

Added line #L502 was not covered by tests
name: dataSource.name,
panel: 3,
onClick: async () => await handleSelectedDataSource(dataSource),

Check warning on line 505 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L505

Added line #L505 was not covered by tests
})),
],
content: <div>{navigatorState.isLoading && createLoadingSpinner()}</div>,
});

const createDataSourcesPanel = () => ({

Check warning on line 511 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L511

Added line #L511 was not covered by tests
id: 3,
title: navigatorState.currentDataSourceRef?.name ?? indicesLabel,
items: navigatorState.currentDataSourceRef?.indices?.map((object) => ({

Check warning on line 514 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L514

Added line #L514 was not covered by tests
name: object.title,
panel: 7,
onClick: async () => await handleSelectedObject(object),

Check warning on line 517 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L517

Added line #L517 was not covered by tests
})),
content: (
<div>
Expand All @@ -519,7 +523,7 @@
),
});

const createS3DataSourcesPanel = () => ({

Check warning on line 526 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L526

Added line #L526 was not covered by tests
id: 4,
title: (
<div>
Expand All @@ -529,29 +533,29 @@
</div>
),
items: [
...navigatorState.externalDataSources.map((dataSource) => ({

Check warning on line 536 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L536

Added line #L536 was not covered by tests
name: dataSource.name,
onClick: async () => await handleSelectExternalDataSource(dataSource),

Check warning on line 538 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L538

Added line #L538 was not covered by tests
panel: 5,
})),
],
content: <div>{dataSourcesLoadStatus && createLoadingSpinner()}</div>,
});

const createDatabasesPanel = () => ({

Check warning on line 545 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L545

Added line #L545 was not covered by tests
id: 5,
title: selectedDataSetState?.dataSourceRef?.name
? selectedDataSetState.dataSourceRef?.name
: 'Databases',
items: [
...navigatorState.cachedDatabases.map((db) => ({

Check warning on line 551 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L551

Added line #L551 was not covered by tests
name: db.name,
onClick: async () => {
setSelectedDataSetState((prevState) => ({

Check warning on line 554 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L554

Added line #L554 was not covered by tests
...prevState,
database: db,
}));
await handleSelectExternalDatabase(db);

Check warning on line 558 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L558

Added line #L558 was not covered by tests
},
panel: 6,
})),
Expand All @@ -559,7 +563,7 @@
content: <div>{isCatalogCacheFetching(databasesLoadStatus) && createLoadingSpinner()}</div>,
});

return (

Check warning on line 566 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L566

Added line #L566 was not covered by tests
<EuiPopover
button={
<EuiButtonEmpty
Expand Down Expand Up @@ -613,23 +617,23 @@
name: S3DataSourcesLabel,
panel: 4,
onClick: async () => {
const externalDataSourcesCache = CatalogCacheManager.getExternalDataSourcesCache();

Check warning on line 620 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L620

Added line #L620 was not covered by tests
if (
(externalDataSourcesCache.status === CachedDataSourceStatus.Empty ||
externalDataSourcesCache.status === CachedDataSourceStatus.Failed) &&
!isCatalogCacheFetching(dataSourcesLoadStatus) &&
navigatorState.dataSources.length > 0
) {
startLoadingDataSources(
navigatorState.dataSources.map((dataSource) => dataSource.id)

Check warning on line 628 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L627-L628

Added lines #L627 - L628 were not covered by tests
);
} else if (
externalDataSourcesCache.status === CachedDataSourceStatus.Updated
) {
setNavigatorState((prevState) => ({

Check warning on line 633 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L633

Added line #L633 was not covered by tests
...prevState,
externalDataSources: externalDataSourcesCache.externalDataSources.map(
(ds) => ({

Check warning on line 636 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L636

Added line #L636 was not covered by tests
id: ds.dataSourceRef,
name: ds.name,
type: SIMPLE_DATA_SOURCE_TYPES.EXTERNAL,
Expand All @@ -652,10 +656,10 @@
id: 6,
title: selectedDataSetState?.database ? selectedDataSetState.database.name : 'Tables',
items: [
...navigatorState.cachedTables.map((table) => ({

Check warning on line 659 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L659

Added line #L659 was not covered by tests
name: table.name,
onClick: async () => {
const tableObject = {

Check warning on line 662 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L662

Added line #L662 was not covered by tests
...selectedDataSetState,
id: `${selectedDataSetState?.dataSourceRef!.name}.${
selectedDataSetState?.database.name
Expand All @@ -670,8 +674,7 @@
},
type: SIMPLE_DATA_SET_TYPES.TEMPORARY_ASYNC,
};
setSelectedDataSetState(tableObject);
handleSelectedDataSet(tableObject);
await handleSelectedDataSet(tableObject);

Check warning on line 677 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L677

Added line #L677 was not covered by tests
},
})),
],
Expand All @@ -683,9 +686,7 @@
id: 7,
title: navigatorState.currentDataSet?.title,
content:
navigatorState.isLoading ||
!navigatorState.currentDataSet ||
!navigatorState.currentDataSet?.title ? (
!navigatorState.currentDataSet || !navigatorState.currentDataSet?.title ? (
<div>{createLoadingSpinner()}</div>
) : (
<EuiForm className="dataSetNavigatorFormWrapper">
Expand All @@ -700,7 +701,7 @@
...(navigatorState.currentDataSet!.timeFields &&
navigatorState.currentDataSet!.timeFields.length > 0
? [
...navigatorState.currentDataSet!.timeFields!.map((field: any) => ({

Check warning on line 704 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L704

Added line #L704 was not covered by tests
value: field.name,
text: field.name,
})),
Expand All @@ -709,7 +710,7 @@
{ value: 'no-time-filter', text: "I don't want to use a time filter" },
]}
onChange={(event) => {
setNavigatorState((prevState) => ({

Check warning on line 713 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L713

Added line #L713 was not covered by tests
...prevState,
currentDataSet: {
...prevState.currentDataSet!,
Expand All @@ -727,7 +728,7 @@
size="s"
fullWidth
onClick={async () => {
await handleSelectedDataSet();

Check warning on line 731 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L731

Added line #L731 was not covered by tests
}}
>
Select
Expand All @@ -738,17 +739,17 @@
{
id: 8,
title: 'Recently Used',
items: CatalogCacheManager.getRecentDataSets().map((ds) => ({

Check warning on line 742 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L742

Added line #L742 was not covered by tests
name: ds.title,
onClick: async () => {
setSelectedDataSetState({

Check warning on line 745 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L745

Added line #L745 was not covered by tests
id: ds.id ?? ds.title,
title: ds.title,
dataSourceRef: ds.dataSourceRef,
database: undefined,
timeFieldName: ds.timeFieldName,
});
await handleSelectedDataSet();

Check warning on line 752 in src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx#L752

Added line #L752 was not covered by tests
},
})),
},
Expand Down
1 change: 1 addition & 0 deletions src/plugins/data/public/ui/dataset_navigator/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@

export { DataSetNavigator, DataSetNavigatorProps } from './dataset_navigator';
export { createDataSetNavigator } from './create_dataset_navigator';
export { setAsyncSessionId, getAsyncSessionId, setAsyncSessionIdByObj } from './lib';
Loading
Loading