Skip to content

Commit

Permalink
language service
Browse files Browse the repository at this point in the history
Signed-off-by: Kawika Avilla <[email protected]>
  • Loading branch information
kavilla committed Aug 24, 2024
1 parent 42dab80 commit 6766938
Show file tree
Hide file tree
Showing 36 changed files with 643 additions and 781 deletions.
99 changes: 0 additions & 99 deletions src/plugins/data/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,105 +42,6 @@ export const DEFAULT_DATA = {
tooltip: 'Root Data Structure',
},
} as DataStructure,

NULL: {
id: 'NULL',
title: 'Empty',
type: 'NULL',
meta: {
type: DATA_STRUCTURE_META_TYPES.FEATURE,
icon: 'empty',
tooltip: 'Empty Data Structure',
},
} as DataStructure,

CATEGORY: {
id: 'CATEGORY',
title: 'Categories',
type: 'CATEGORY',
meta: {
type: DATA_STRUCTURE_META_TYPES.FEATURE,
icon: 'listAdd',
tooltip: 'Data Categories',
},
} as DataStructure,

DATA_SOURCE: {
id: 'DATA_SOURCE',
title: 'Clusters',
type: 'DATA_SOURCE',
meta: {
type: DATA_STRUCTURE_META_TYPES.FEATURE,
icon: 'cluster',
tooltip: 'Data Clusters',
},
} as DataStructure,

CONNECTION: {
id: 'CONNECTION',
title: 'Connections',
type: 'CONNECTION',
meta: {
type: DATA_STRUCTURE_META_TYPES.FEATURE,
icon: 'link',
tooltip: 'Data Connections',
},
} as DataStructure,

INDEX: {
id: 'INDEX',
title: 'Indexes',
type: 'INDEX',
meta: {
type: DATA_STRUCTURE_META_TYPES.FEATURE,
icon: 'indexOpen',
tooltip: 'Data Indexes',
},
} as DataStructure,

FIELD: {
id: 'FIELD',
title: 'Fields',
type: 'FIELD',
meta: {
type: DATA_STRUCTURE_META_TYPES.FEATURE,
icon: 'field',
tooltip: 'Data Fields',
},
} as DataStructure,

TIME_FIELD: {
id: 'TIME_FIELD',
title: 'Time fields',
type: 'TIME_FIELD',
meta: {
type: DATA_STRUCTURE_META_TYPES.FEATURE,
icon: 'clock',
tooltip: 'Time Fields',
},
} as DataStructure,

DATASET: {
id: 'DATASET',
title: 'Datasets',
type: 'DATASET',
meta: {
type: DATA_STRUCTURE_META_TYPES.FEATURE,
icon: 'document',
tooltip: 'Datasets',
},
} as DataStructure,

DATASET_CATEGORY: {
id: 'DATASET_CATEGORY',
title: 'Datasets',
type: 'DATASET_CATEGORY',
meta: {
type: DATA_STRUCTURE_META_TYPES.FEATURE,
icon: 'documents',
tooltip: 'Dataset Categories',
},
} as DataStructure,
},

SET_TYPES: {
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/data/common/datasets/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ export interface DataStructure {
children?: DataStructure[];
/** Optional array of data structures of ancestors */
path?: DataStructure[];
isLeaf?: boolean;
columnHeader?: string;
hasNext?: boolean;
groupName?: string;
/** Optional metadata for the data structure */
meta?: DataStructureMeta;
}
Expand Down
10 changes: 6 additions & 4 deletions src/plugins/data/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,6 @@ export {
QueryEditorTopRow,
// for BWC, keeping the old name
IUiStart as DataPublicPluginStartUi,
DataSetNavigator,
} from './ui';

/**
Expand All @@ -462,9 +461,12 @@ export {
QueryState,
getDefaultQuery,
FilterManager,
DatasetContract,
DatasetManager,
DatasetHandlerConfig,
DatasetTypeConfig,
DatasetService,
DatasetServiceContract,
LanguageConfig,
LanguageService,
LanguageServiceContract,
SavedQuery,
SavedQueryService,
SavedQueryTimeFilter,
Expand Down
3 changes: 1 addition & 2 deletions src/plugins/data/public/query/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@
*/

export * from './lib';

export * from './types';
export * from './query_service';
export * from './filter_manager';
export * from './query_string';
export * from './query_string/dataset_manager';
export * from './timefilter';
export * from './saved_query';
export * from './persisted_log';
Expand Down
30 changes: 9 additions & 21 deletions src/plugins/data/public/query/query_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,47 +29,35 @@
*/

import { share } from 'rxjs/operators';
import { IUiSettingsClient, SavedObjectsClientContract } from 'src/core/public';
import { FilterManager } from './filter_manager';
import { createAddToQueryLog } from './lib';
import { TimefilterService, TimefilterSetup } from './timefilter';
import { createSavedQueryService } from './saved_query/saved_query_service';
import { createQueryStateObservable } from './state_sync/create_global_query_observable';
import { QueryStringManager, QueryStringContract } from './query_string';
import {
buildOpenSearchQuery,
DataStorage,
getOpenSearchQueryConfig,
IndexPatternsService,
} from '../../common';
import { buildOpenSearchQuery, getOpenSearchQueryConfig } from '../../common';
import { getUiSettings } from '../services';
import { IndexPattern } from '..';
import {
IQuerySetup,
IQueryStart,
QueryServiceSetupDependencies,
QueryServiceStartDependencies,
} from './types';

/**
* Query Service
* @internal
*/

interface QueryServiceSetupDependencies {
storage: DataStorage;
uiSettings: IUiSettingsClient;
}

interface QueryServiceStartDependencies {
savedObjectsClient: SavedObjectsClientContract;
storage: DataStorage;
uiSettings: IUiSettingsClient;
indexPatterns: IndexPatternsService;
}

export class QueryService {
filterManager!: FilterManager;
timefilter!: TimefilterSetup;
queryStringManager!: QueryStringContract;

state$!: ReturnType<typeof createQueryStateObservable>;

public setup({ storage, uiSettings }: QueryServiceSetupDependencies) {
public setup({ storage, uiSettings }: QueryServiceSetupDependencies): IQuerySetup {
this.filterManager = new FilterManager(uiSettings);

const timefilterService = new TimefilterService();
Expand Down Expand Up @@ -99,7 +87,7 @@ export class QueryService {
storage,
uiSettings,
indexPatterns,
}: QueryServiceStartDependencies) {
}: QueryServiceStartDependencies): IQueryStart {
this.queryStringManager.getDatasetManager().init(indexPatterns);
return {
addToQueryLog: createAddToQueryLog({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ import {
DataStructure,
CachedDataStructure,
DataStructureCache,
toCachedDataStructure,
createDataStructureCache,
DatasetField,
IndexPatternSpec,
} from '../../../../common';
import { IndexPatternsContract } from '../../../index_patterns';
Expand Down Expand Up @@ -128,48 +126,6 @@ export class DatasetManager {
return handler;
}

/**
* Gets cached children for a given parent ID.
* @param parentId - The ID of the parent data structure.
* @returns An array of child data structures.
*/
private getCachedChildren(parentId: string): DataStructure[] {
const cachedStructure = this.dataStructureCache.get(parentId);
if (!cachedStructure) return [];

return cachedStructure.children
.map((childId) => this.dataStructuresMap.get(childId))
.filter((child): child is DataStructure => !!child);
}

/**
* Caches an array of data structures.
* @param dataStructures - The data structures to cache.
*/
private cacheDataStructures(dataStructures: DataStructure[]) {
dataStructures.forEach((ds) => {
const fullId = this.getFullId(ds);
this.dataStructuresMap.set(fullId, ds);
const cachedDs = toCachedDataStructure(ds);
this.dataStructureCache.set(fullId, cachedDs);
});
}

/**
* Gets the full ID for a data structure, including its parent's ID.
* @param dataStructure - The data structure to get the full ID for.
* @returns The full ID of the data structure.
*/
private getFullId(dataStructure: DataStructure): string {
if (!dataStructure.parent) {
return dataStructure.id;
}
const parentId = this.getFullId(dataStructure.parent);
const separator =
dataStructure.parent.type === DEFAULT_DATA.STRUCTURES.DATA_SOURCE.type ? '::' : '.';
return `${parentId}${separator}${dataStructure.id}`;
}

/**
* Sets the current dataset.
* @param dataset - The dataset to set.
Expand Down
Loading

0 comments on commit 6766938

Please sign in to comment.