-
Notifications
You must be signed in to change notification settings - Fork 916
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Enable data client with sample data server side * Add dataSourceId into savedObject Signed-off-by: Kristen Tian <[email protected]> * Functional list, install uninstall Signed-off-by: Kristen Tian <[email protected]> * add change log Signed-off-by: Kristen Tian <[email protected]> * address comments Signed-off-by: Kristen Tian <[email protected]> * add ut Signed-off-by: Kristen Tian <[email protected]> --------- Signed-off-by: Kristen Tian <[email protected]> (cherry picked from commit b337bea) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> # Conflicts: # CHANGELOG.md Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
b00edec
commit 4fbf897
Showing
17 changed files
with
647 additions
and
106 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
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
84 changes: 84 additions & 0 deletions
84
src/plugins/home/server/services/sample_data/data_sets/util.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,84 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { SavedObject } from 'opensearch-dashboards/server'; | ||
|
||
export const appendDataSourceId = (id: string) => { | ||
return (dataSourceId?: string) => (dataSourceId ? `${dataSourceId}_` + id : id); | ||
}; | ||
|
||
export const getSavedObjectsWithDataSource = ( | ||
saveObjectList: SavedObject[], | ||
dataSourceId?: string, | ||
dataSourceTitle?: string | ||
): SavedObject[] => { | ||
if (dataSourceId) { | ||
return saveObjectList.map((saveObject) => { | ||
saveObject.id = `${dataSourceId}_` + saveObject.id; | ||
// update reference | ||
if (saveObject.type === 'dashboard') { | ||
saveObject.references.map((reference) => { | ||
if (reference.id) { | ||
reference.id = `${dataSourceId}_` + reference.id; | ||
} | ||
}); | ||
} | ||
|
||
// update reference | ||
if (saveObject.type === 'visualization' || saveObject.type === 'search') { | ||
const searchSourceString = saveObject.attributes?.kibanaSavedObjectMeta?.searchSourceJSON; | ||
const visStateString = saveObject.attributes?.visState; | ||
|
||
if (searchSourceString) { | ||
const searchSource = JSON.parse(searchSourceString); | ||
if (searchSource.index) { | ||
searchSource.index = `${dataSourceId}_` + searchSource.index; | ||
saveObject.attributes.kibanaSavedObjectMeta.searchSourceJSON = JSON.stringify( | ||
searchSource | ||
); | ||
} | ||
} | ||
|
||
if (visStateString) { | ||
const visState = JSON.parse(visStateString); | ||
const controlList = visState.params?.controls; | ||
if (controlList) { | ||
controlList.map((control) => { | ||
if (control.indexPattern) { | ||
control.indexPattern = `${dataSourceId}_` + control.indexPattern; | ||
} | ||
}); | ||
} | ||
saveObject.attributes.visState = JSON.stringify(visState); | ||
} | ||
} | ||
|
||
// update reference | ||
if (saveObject.type === 'index-pattern') { | ||
saveObject.references = [ | ||
{ | ||
id: `${dataSourceId}`, | ||
type: 'data-source', | ||
name: 'dataSource', | ||
}, | ||
]; | ||
} | ||
|
||
if (dataSourceTitle) { | ||
if ( | ||
saveObject.type === 'dashboard' || | ||
saveObject.type === 'visualization' || | ||
saveObject.type === 'search' | ||
) { | ||
saveObject.attributes.title = saveObject.attributes.title + `_${dataSourceTitle}`; | ||
} | ||
} | ||
|
||
return saveObject; | ||
}); | ||
} | ||
|
||
return saveObjectList; | ||
}; |
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.