Skip to content

Commit

Permalink
Fix index pattern data source reference not updated in sample data (#…
Browse files Browse the repository at this point in the history
…6851)

* Fix index pattern data source reference not updated in sample data

Signed-off-by: Lin Wang <wonglam@amazon.com>

* Changeset file for PR #6851 created/updated

---------

Signed-off-by: Lin Wang <wonglam@amazon.com>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
  • Loading branch information
wanglam and opensearch-changeset-bot[bot] authored May 29, 2024
1 parent 8d50974 commit eb3efa8
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
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

0 comments on commit eb3efa8

Please sign in to comment.