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

[Backport 2.x] Fix index pattern data source reference not updated in sample data #6853

Merged
merged 1 commit into from
May 29, 2024
Merged
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/6851.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fix:
- Update index pattern references with data source when import sample data ([#6851](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6851))
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { getSavedObjectsWithDataSource, getFinalSavedObjects, appendDataSourceId } from './util';
import { getSavedObjectsWithDataSource, getFinalSavedObjects } from './util';
import { SavedObject, updateDataSourceNameInVegaSpec } from '../../../../../../core/server';
import visualizationObjects from './test_utils/visualization_objects.json';

Expand Down Expand Up @@ -62,6 +62,39 @@ describe('getSavedObjectsWithDataSource()', () => {

expect(updatedVegaVisualizationsFields).toEqual(expect.arrayContaining(expectedUpdatedFields));
});

it('should update index-pattern id and references with given data source', () => {
const dataSourceId = 'some-datasource-id';
const dataSourceName = 'Data Source Name';

expect(
getSavedObjectsWithDataSource(
[
{
id: 'saved-object-1',
type: 'index-pattern',
attributes: {},
references: [],
},
],
dataSourceId,
dataSourceName
)
).toEqual([
{
id: 'some-datasource-id_saved-object-1',
type: 'index-pattern',
attributes: {},
references: [
{
id: `${dataSourceId}`,
type: 'data-source',
name: 'dataSource',
},
],
},
]);
});
});

describe('getFinalSavedObjects()', () => {
Expand Down
11 changes: 11 additions & 0 deletions src/plugins/home/server/services/sample_data/data_sets/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ export const getSavedObjectsWithDataSource = (
return saveObjectList.map((saveObject) => {
overrideSavedObjectId(saveObject, idGenerator);

// update reference
if (saveObject.type === 'index-pattern') {
saveObject.references = [
{
id: `${dataSourceId}`,
type: 'data-source',
name: 'dataSource',
},
];
}

if (dataSourceTitle) {
if (
saveObject.type === 'dashboard' ||
Expand Down
Loading