-
Notifications
You must be signed in to change notification settings - Fork 884
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
[MD] Concatenate data source name with index pattern name and change delimiter to double colon #5907
Merged
Merged
[MD] Concatenate data source name with index pattern name and change delimiter to double colon #5907
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
54 changes: 54 additions & 0 deletions
54
src/plugins/data/common/index_patterns/lib/get_title.test.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,54 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { SavedObjectsClientContract } from '../../../../../core/public'; | ||
import { getTitle } from './get_title'; | ||
|
||
describe('test getTitle', () => { | ||
let client: SavedObjectsClientContract; | ||
|
||
it('with dataSourceId match', async () => { | ||
const dataSourceIdToTitle = new Map(); | ||
dataSourceIdToTitle.set('dataSourceId', 'dataSourceTitle'); | ||
client = { | ||
get: jest.fn().mockResolvedValue({ | ||
attributes: { title: 'indexTitle' }, | ||
references: [{ type: 'data-source', id: 'dataSourceId' }], | ||
}), | ||
} as any; | ||
const title = await getTitle(client, 'indexPatternId', dataSourceIdToTitle); | ||
expect(title).toEqual('dataSourceTitle::indexTitle'); | ||
}); | ||
|
||
it('with no dataSourceId match and error to get data source', async () => { | ||
const dataSourceIdToTitle = new Map(); | ||
client = { | ||
get: jest | ||
.fn() | ||
.mockResolvedValueOnce({ | ||
attributes: { title: 'indexTitle' }, | ||
references: [{ type: 'data-source', id: 'dataSourceId' }], | ||
}) | ||
.mockRejectedValue(new Error('error')), | ||
} as any; | ||
const title = await getTitle(client, 'indexPatternId', dataSourceIdToTitle); | ||
expect(title).toEqual('dataSourceId::indexTitle'); | ||
}); | ||
|
||
it('with no dataSourceId match and success to get data source', async () => { | ||
const dataSourceIdToTitle = new Map(); | ||
client = { | ||
get: jest | ||
.fn() | ||
.mockResolvedValueOnce({ | ||
attributes: { title: 'indexTitle' }, | ||
references: [{ type: 'data-source', id: 'dataSourceId' }], | ||
}) | ||
.mockResolvedValue({ attributes: { title: 'acquiredDataSourceTitle' } }), | ||
} as any; | ||
const title = await getTitle(client, 'indexPatternId', dataSourceIdToTitle); | ||
expect(title).toEqual('acquiredDataSourceTitle::indexTitle'); | ||
}); | ||
}); |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we move this code to getTitle? We have index pattern id, saved object client to find reference, right? We don't have to pass third parameter. Otherwise consumer of getTitle always needs to pass map with data source id and title? Instead can getTitle function handle that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part of code would perform bulk get index patterns(existing behavior), the added behavior is if the referred data source doesn't exist in the current state, it will fetch the data sources in bulk. Note there is only 2 requests here. The getTitle function is only used for selected index pattern which is a single index pattern, the existing behavior is it use an index pattern id to make individual call to saved object API to get the index pattern title, and if we use this function to handle all index patterns, this would multiple by number of index patterns, then to add data source title would double the requests.
If we want to refactor this, I can extract the logic here to a function to perform bulk operation and to produce the idToTitle map
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. No need to extract for now. We need to unify the pickers from all screen and that would be another effort. Thanks for the change.