forked from opensearch-project/OpenSearch-Dashboards
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Discover-next] data set picker (opensearch-project#7426)
* update using query manager Signed-off-by: Kawika Avilla <[email protected]> * aggs not working Signed-off-by: Kawika Avilla <[email protected]> * almost there Signed-off-by: Kawika Avilla <[email protected]> * stablish Signed-off-by: Kawika Avilla <[email protected]> * thanks ashwin Signed-off-by: Kawika Avilla <[email protected]> * update ref name Signed-off-by: Kawika Avilla <[email protected]> * fix timefields Signed-off-by: Kawika Avilla <[email protected]> * clean up some console logs Signed-off-by: Kawika Avilla <[email protected]> * go safer route of setting language Signed-off-by: Kawika Avilla <[email protected]> * its working again Signed-off-by: Kawika Avilla <[email protected]> * fix names Signed-off-by: Kawika Avilla <[email protected]> * restore code editor and indices Signed-off-by: Kawika Avilla <[email protected]> * sql df Signed-off-by: Kawika Avilla <[email protected]> * fix external datasources again Signed-off-by: Kawika Avilla <[email protected]> --------- Signed-off-by: Kawika Avilla <[email protected]>
- Loading branch information
Showing
88 changed files
with
3,583 additions
and
712 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
feat: | ||
- [Discover] Adds a dataset selector for Discover ([#7368](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7368)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,4 @@ | |
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export * from './create_extension'; | ||
export * from './types'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/** @public **/ | ||
export enum SIMPLE_DATA_SOURCE_TYPES { | ||
DEFAULT = 'data-source', | ||
EXTERNAL = 'external-source', | ||
} | ||
|
||
/** @public **/ | ||
export enum SIMPLE_DATA_SET_TYPES { | ||
INDEX_PATTERN = 'index-pattern', | ||
TEMPORARY = 'temporary', | ||
TEMPORARY_ASYNC = 'temporary-async', | ||
} | ||
|
||
export interface SimpleObject { | ||
id: string; | ||
title?: string; | ||
dataSourceRef?: SimpleDataSource; | ||
} | ||
|
||
export interface SimpleDataSource { | ||
id: string; | ||
name: string; | ||
indices?: SimpleObject[]; | ||
tables?: SimpleObject[]; | ||
type: SIMPLE_DATA_SOURCE_TYPES; | ||
} | ||
|
||
export interface SimpleDataSet extends SimpleObject { | ||
fields?: any[]; | ||
timeFieldName?: string; | ||
timeFields?: any[]; | ||
type?: SIMPLE_DATA_SET_TYPES; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/plugins/data/public/query/dataset_manager/dataset_manager.mock.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { DataSetContract } from '.'; | ||
|
||
const createSetupContractMock = () => { | ||
const dataSetManagerMock: jest.Mocked<DataSetContract> = { | ||
init: jest.fn(), | ||
getDataSet: jest.fn(), | ||
setDataSet: jest.fn(), | ||
getUpdates$: jest.fn(), | ||
getDefaultDataSet: jest.fn(), | ||
}; | ||
return dataSetManagerMock; | ||
}; | ||
|
||
export const dataSetManagerMock = { | ||
createSetupContract: createSetupContractMock, | ||
createStartContract: createSetupContractMock, | ||
}; |
33 changes: 33 additions & 0 deletions
33
src/plugins/data/public/query/dataset_manager/dataset_manager.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { DataSetManager } from './dataset_manager'; | ||
import { coreMock } from '../../../../../core/public/mocks'; | ||
import { SimpleDataSet } from '../../../common/data_sets'; | ||
|
||
describe('DataSetManager', () => { | ||
let service: DataSetManager; | ||
|
||
beforeEach(() => { | ||
service = new DataSetManager(coreMock.createSetup().uiSettings); | ||
}); | ||
|
||
test('getUpdates$ is a cold emits only after query changes', () => { | ||
const obs$ = service.getUpdates$(); | ||
const emittedValues: SimpleDataSet[] = []; | ||
obs$.subscribe((v) => { | ||
emittedValues.push(v!); | ||
}); | ||
expect(emittedValues).toHaveLength(0); | ||
|
||
const newDataSet: SimpleDataSet = { id: 'test_dataset', title: 'Test Dataset' }; | ||
service.setDataSet(newDataSet); | ||
expect(emittedValues).toHaveLength(1); | ||
expect(emittedValues[0]).toEqual(newDataSet); | ||
|
||
service.setDataSet({ ...newDataSet }); | ||
expect(emittedValues).toHaveLength(2); | ||
}); | ||
}); |
77 changes: 77 additions & 0 deletions
77
src/plugins/data/public/query/dataset_manager/dataset_manager.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { BehaviorSubject } from 'rxjs'; | ||
import { skip } from 'rxjs/operators'; | ||
import { CoreStart } from 'opensearch-dashboards/public'; | ||
import { | ||
IndexPatternsService, | ||
SIMPLE_DATA_SET_TYPES, | ||
SimpleDataSet, | ||
SimpleDataSource, | ||
} from '../../../common'; | ||
|
||
export class DataSetManager { | ||
private dataSet$: BehaviorSubject<SimpleDataSet | undefined>; | ||
private indexPatterns?: IndexPatternsService; | ||
|
||
constructor(private readonly uiSettings: CoreStart['uiSettings']) { | ||
this.dataSet$ = new BehaviorSubject<SimpleDataSet | undefined>(undefined); | ||
} | ||
|
||
public init = (indexPatterns: IndexPatternsService) => { | ||
this.indexPatterns = indexPatterns; | ||
}; | ||
|
||
public getUpdates$ = () => { | ||
return this.dataSet$.asObservable().pipe(skip(1)); | ||
}; | ||
|
||
public getDataSet = () => { | ||
return this.dataSet$.getValue(); | ||
}; | ||
|
||
/** | ||
* Updates the query. | ||
* @param {Query} query | ||
*/ | ||
public setDataSet = (dataSet: SimpleDataSet | undefined) => { | ||
this.dataSet$.next(dataSet); | ||
}; | ||
|
||
public getDefaultDataSet = async (): Promise<SimpleDataSet | undefined> => { | ||
const defaultIndexPatternId = await this.uiSettings.get('defaultIndex'); | ||
if (!defaultIndexPatternId) { | ||
return undefined; | ||
} | ||
|
||
const indexPattern = await this.indexPatterns?.get(defaultIndexPatternId); | ||
if (!indexPattern) { | ||
return undefined; | ||
} | ||
|
||
if (!indexPattern.id) { | ||
return undefined; | ||
} | ||
|
||
return { | ||
id: indexPattern.id, | ||
title: indexPattern.title, | ||
type: SIMPLE_DATA_SET_TYPES.INDEX_PATTERN, | ||
timeFieldName: indexPattern.timeFieldName, | ||
...(indexPattern.dataSourceRef | ||
? { | ||
dataSourceRef: { | ||
id: indexPattern.dataSourceRef?.id, | ||
name: indexPattern.dataSourceRef?.name, | ||
type: indexPattern.dataSourceRef?.type, | ||
} as SimpleDataSource, | ||
} | ||
: {}), | ||
}; | ||
}; | ||
} | ||
|
||
export type DataSetContract = PublicMethodsOf<DataSetManager>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export { DataSetContract, DataSetManager } from './dataset_manager'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.