Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions changelogs/fragments/10269.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fix:
- Move dataset select to query panel widgets ([#10269](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/10269))
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const cachingTestSuite = () => {
});

cy.getElementByTestId('datasetSelectButton').should('be.visible').click();
cy.getElementByTestId('datasetSelectAdvancedButton').click();
cy.getElementByTestId('datasetSelectAdvancedButton').should('be.visible').click();
cy.intercept('GET', '**/api/saved_objects/_find?fields*').as('getIndexPatternRequest');
cy.get(`[title="Index Patterns"]`).click();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ const inspectTestSuite = () => {
isEnhancement: true,
});
cy.getElementByTestId('discoverNewButton').click();
setDatePickerDatesAndSearchIfRelevant(config.language);

cy.explore.setDataset(config.dataset, DATASOURCE_NAME, config.datasetType);
setDatePickerDatesAndSearchIfRelevant(config.language);

cy.intercept('POST', '**/search/*').as('docTablePostRequest');
cy.getElementByTestId('queryPanelFooterRunQueryButton').click();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ export const runCreateVisTests = () => {
});

it('should create a metric visualization using a single metric query', () => {
setDatePickerDatesAndSearchIfRelevant('PPL');
cy.wait(2000);
// Setup dataset
const datasetName = `${INDEX_WITH_TIME_1}*`;
cy.explore.setDataset(datasetName, DATASOURCE_NAME, 'INDEX_PATTERN');
setDatePickerDatesAndSearchIfRelevant('PPL');
cy.wait(2000);
cy.explore.clearQueryEditor();

Expand Down
13 changes: 8 additions & 5 deletions cypress/utils/commands.explore.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@
.should('be.visible')
.invoke('attr', 'data-test-subj')
.then((testId) => {
cy.getElementByTestId(testId, opts).should('be.visible').click(opts);
cy.getElementByTestId(testId, opts).as('btn').click({force: true});

Check failure on line 151 in cypress/utils/commands.explore.js

View workflow job for this annotation

GitHub Actions / Lint and validate

Replace `force:·true` with `·force:·true·`
cy.get('@btn').click({force: true});

Check failure on line 152 in cypress/utils/commands.explore.js

View workflow job for this annotation

GitHub Actions / Lint and validate

Replace `force:·true` with `·force:·true·`
});

/* While we surely are in the date selection mode, we don't know if the date selection dialog
Expand Down Expand Up @@ -383,8 +384,8 @@
cy.explore.add(
'setIndexAsDataset',
(index, dataSourceName, language, timeFieldName = 'timestamp', finalAction = 'submit') => {
cy.getElementByTestId('datasetSelectButton').should('be.visible').click();
cy.getElementByTestId(`datasetSelectAdvancedButton`).should('be.visible').click();
cy.getElementByTestId('datasetSelectButton').click({force: true});

Check failure on line 387 in cypress/utils/commands.explore.js

View workflow job for this annotation

GitHub Actions / Lint and validate

Replace `force:·true` with `·force:·true·`
cy.getElementByTestId(`datasetSelectAdvancedButton`).click({force: true});

Check failure on line 388 in cypress/utils/commands.explore.js

View workflow job for this annotation

GitHub Actions / Lint and validate

Replace `force:·true` with `·force:·true·`
cy.get(`[title="Indexes"]`).click();
cy.get(`[title="${dataSourceName}"]`).click();
// this element is sometimes dataSourceName masked by another element
Expand Down Expand Up @@ -412,8 +413,10 @@
);

cy.explore.add('setIndexPatternAsDataset', (indexPattern) => {
cy.getElementByTestId('datasetSelectButton').should('be.visible').click();
cy.get(`[title="${indexPattern}"]`).should('be.visible').click();
cy.getElementByTestId('datasetSelectButton').as('btn').click({force: true});

Check failure on line 416 in cypress/utils/commands.explore.js

View workflow job for this annotation

GitHub Actions / Lint and validate

Replace `force:·true` with `·force:·true·`
cy.get('@btn').click({force:true})

Check failure on line 417 in cypress/utils/commands.explore.js

View workflow job for this annotation

GitHub Actions / Lint and validate

Replace `force:true})` with `·force:·true·});`

cy.get(`[title="${indexPattern}"]`).click({force: true});

Check failure on line 419 in cypress/utils/commands.explore.js

View workflow job for this annotation

GitHub Actions / Lint and validate

Replace `force:·true` with `·force:·true·`

// verify that it has been selected
cy.getElementByTestId('datasetSelectButton').should('contain.text', `${indexPattern}`);
Expand Down
10 changes: 10 additions & 0 deletions src/plugins/data/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ export const DEFAULT_QUERY = {
},
};

export const EMPTY_QUERY = {
QUERY: '',
DATASET: {
TYPE: DEFAULT_DATA.SET_TYPES.INDEX_PATTERN,
DATASOURCE: {
TYPE: DEFAULT_DATA.SOURCE_TYPES.OPENSEARCH,
},
},
};

export const UI_SETTINGS = {
META_FIELDS: 'metaFields',
DOC_HIGHLIGHT: 'doc_table:highlight',
Expand Down
18 changes: 0 additions & 18 deletions src/plugins/data/common/data_views/data_view.stub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ export const stubDataView: IDataView = {
fields: stubFields,
title: 'logstash-*',
timeFieldName: '@timestamp',
getFieldByName: (name: string) => stubFields.find((field) => field.name === name),
getComputedFields: () => ({}),
getScriptedFields: () => stubFields.filter((field) => field.scripted),
getNonScriptedFields: () => stubFields.filter((field) => !field.scripted),
addScriptedField: async () => {},
removeScriptedField: () => {},
};

export const stubDataViewWithFields: IDataView = {
Expand All @@ -32,16 +26,4 @@ export const stubDataViewWithFields: IDataView = {
searchable: true,
},
],
getFieldByName(name: string) {
return this.fields.find((field) => field.name === name);
},
getComputedFields: () => ({}),
getScriptedFields() {
return this.fields.filter((field) => field.scripted);
},
getNonScriptedFields() {
return this.fields.filter((field) => !field.scripted);
},
addScriptedField: async () => {},
removeScriptedField: () => {},
};
61 changes: 55 additions & 6 deletions src/plugins/data/common/data_views/data_views/data_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { SavedObjectsClientCommon } from '../..';
import { SavedObjectsClientCommon, Dataset, DataSource } from '../..';
import { IndexPattern } from '../../index_patterns/index_patterns/index_pattern';
import { IDataView, DataViewSpec } from '../types';
import { FieldFormatsStartCommon } from '../../field_formats';
import { extractDatasetTypeFromUri } from '../';
import { DEFAULT_DATA } from '../../constants';

interface DataViewDeps {
spec?: DataViewSpec;
Expand Down Expand Up @@ -38,10 +40,7 @@ export class DataView extends IndexPattern implements IDataView {
});

this.savedObjectsClient = savedObjectsClient;

if (this.dataSourceRef?.id) {
this.initializeDataSourceRef();
}
this.initializeDataSourceRef();
}

public async initializeDataSourceRef(): Promise<void> {
Expand All @@ -53,8 +52,58 @@ export class DataView extends IndexPattern implements IDataView {
const attributes = dataSourceSavedObject.attributes as any;
this.dataSourceRef = {
id: this.dataSourceRef.id,
type: this.dataSourceRef.type,
type: attributes.dataSourceEngineType || this.dataSourceRef.type,
name: attributes.title || this.dataSourceRef.name || this.dataSourceRef.id,
};
}

/**
* Converts a DataView to a serializable Dataset object
* Maps dataSourceRef and includes only essential properties for backward compatibility
*/
public async toDataset(): Promise<Dataset> {
const defaultType = DEFAULT_DATA.SET_TYPES.INDEX_PATTERN;
const dataSourceReference = this.dataSourceRef || (this as any).dataSource;

let dataSource: DataSource | undefined;
let datasetType = this.type || defaultType;

if (dataSourceReference?.id) {
try {
const dataSourceSavedObject = await this.savedObjectsClient.get(
'data-source',
dataSourceReference.id
);
const attributes = dataSourceSavedObject.attributes as any;

if (dataSourceReference.name) {
const extractedType = extractDatasetTypeFromUri(dataSourceReference.name);
if (extractedType) {
datasetType = extractedType;
}
}

dataSource = {
id: dataSourceReference.id,
title: attributes.title || dataSourceReference.name || dataSourceReference.id,
type: attributes.dataSourceEngineType || 'OpenSearch',
};
} catch (error) {
// If we can't fetch the data source, create a minimal version
dataSource = {
id: dataSourceReference.id,
title: dataSourceReference.name || dataSourceReference.id,
type: dataSourceReference.type || 'OpenSearch',
};
}
}

return {
id: this.id || '',
title: this.title,
type: datasetType,
timeFieldName: this.timeFieldName,
dataSource,
};
}
}
44 changes: 8 additions & 36 deletions src/plugins/data/common/data_views/data_views/data_views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { i18n } from '@osd/i18n';
import { DataSourceAttributes } from 'src/plugins/data_source/common/data_sources';
import { SavedObjectsClientCommon, Dataset, DEFAULT_DATA } from '../..';
import { SavedObjectsClientCommon, Dataset, DEFAULT_DATA, UI_SETTINGS, SavedObject } from '../..';
import { DataView } from './data_view';
import { createEnsureDefaultDataView, EnsureDefaultDataView } from './ensure_default_data_view';
import { IndexPatternsService } from '../../index_patterns';
Expand All @@ -23,7 +23,6 @@ import {
} from '../types';
import { FieldFormatMap } from '../../index_patterns/types';
import { FieldFormatsStartCommon } from '../../field_formats';
import { UI_SETTINGS, SavedObject } from '../..';
import { SavedObjectNotFound } from '../../../../opensearch_dashboards_utils/common';
import { DataViewMissingIndices } from '../lib';
import { findByTitle, getDataViewTitle } from '../utils';
Expand Down Expand Up @@ -135,7 +134,7 @@ export class DataViewsService {
findDataSourceByTitle = async (title: string, size: number = 10) => {
const savedObjectsResponse = await this.savedObjectsClient.find<DataSourceAttributes>({
type: 'data-source',
fields: ['title'],
fields: ['title', 'dataSourceEngineType'],
search: title,
searchFields: ['title'],
perPage: size,
Expand Down Expand Up @@ -432,7 +431,7 @@ export class DataViewsService {
throw new SavedObjectNotFound(
savedObjectType,
id,
'management/opensearch-dashboards/dataViews'
'management/opensearch-dashboards/indexPatterns'
);
}

Expand Down Expand Up @@ -722,7 +721,11 @@ export class DataViewsService {
* @experimental This method is experimental and may change in future versions
* @param dataView DataView object to convert to Dataset
*/
convertToDataset(dataView: DataView): Dataset {
async convertToDataset(dataView: DataView): Promise<Dataset> {
if (dataView.toDataset) {
return await dataView.toDataset();
}

return {
id: dataView.id || '',
title: dataView.title,
Expand All @@ -737,37 +740,6 @@ export class DataViewsService {
}),
};
}

/**
* Create a DataView from a Dataset object
* @experimental This method is experimental and may change in future versions
* @param dataset Dataset object to create DataView from
*/
async createFromDataset(dataset: Dataset): Promise<DataView> {
const cached = await this.patterns.get(dataset.id, true);
if (cached) {
return cached as DataView;
}

const spec: DataViewSpec = {
id: dataset.id,
title: dataset.title,
type: dataset.type,
timeFieldName: dataset.timeFieldName,
dataSourceRef: dataset.dataSource
? {
id: dataset.dataSource.id!,
name: dataset.dataSource.title,
type: dataset.dataSource.type,
}
: undefined,
};

const dataView = await this.create(spec, false);
this.patterns.saveToCache(dataset.id, dataView);

return dataView;
}
}

export type DataViewsContract = PublicMethodsOf<DataViewsService>;
11 changes: 10 additions & 1 deletion src/plugins/data/common/data_views/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,13 @@ export * from './types';
export { DataViewsService } from './data_views';
export type { DataView } from './data_views';
export * from './errors';
export { validateDataViewDataSourceReference, getDataViewTitle } from './utils';
export {
validateDataViewDataSourceReference,
getDataViewTitle,
findByTitle,
getDataSourceReference,
extractDatasetTypeFromUri,
extractDataSourceInfoFromUri,
constructDataSourceUri,
getDatasetTypeFromReference,
} from './utils';
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,5 @@ export function getFromSavedObject(
id: savedObject.id,
fields,
title: savedObject.attributes.title,
getFieldByName: (name: string) => fields.find((field: any) => field.name === name),
getComputedFields: () => ({}),
getScriptedFields: () => fields.filter((field: any) => field.scripted),
getNonScriptedFields: () => fields.filter((field: any) => !field.scripted),
addScriptedField: async () => {},
removeScriptedField: () => {},
};
}
8 changes: 8 additions & 0 deletions src/plugins/data/common/data_views/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
IndexPatternSpec,
SourceFilter,
} from '../index_patterns/types';
import { Dataset } from '../datasets/types';

/**
* @experimental DataView functionality is experimental and may change in future versions
Expand All @@ -40,6 +41,13 @@ export interface IDataView extends IIndexPattern {
* @experimental This method is experimental and may change in future versions
*/
initializeDataSourceRef?(): Promise<void>;

/**
* Converts a DataView to a serializable Dataset object
* Maps dataSourceRef and includes only essential properties for backward compatibility
* @experimental This method is experimental and may change in future versions
*/
toDataset?(): Promise<Dataset>;
}

/**
Expand Down
Loading
Loading