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) (#6853)

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



* Changeset file for PR #6851 created/updated

---------



(cherry picked from commit eb3efa8)

Signed-off-by: Lin Wang <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored May 29, 2024
1 parent 022ed35 commit 2930bde
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 2930bde

Please sign in to comment.