-
Notifications
You must be signed in to change notification settings - Fork 885
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
Add default icon for selectable component and make sure the default datasource shows automatically #6327
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6327 +/- ##
=======================================
Coverage 67.50% 67.51%
=======================================
Files 3376 3376
Lines 65830 65837 +7
Branches 10648 10649 +1
=======================================
+ Hits 44441 44447 +6
- Misses 18803 18805 +2
+ Partials 2586 2585 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
config/opensearch_dashboards.yml
Outdated
@@ -247,7 +247,7 @@ | |||
# vis_builder.enabled: false | |||
|
|||
# Set the value of this setting to true to enable multiple data source feature. | |||
#data_source.enabled: false | |||
data_source.enabled: true |
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.
Is this change by intention?
if (selectedDataSource.length === 0) { | ||
this.props.notifications.addWarning('No connected data source available.'); | ||
} else { | ||
this.setState({ |
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.
I think this.setState
here will override dataSourceOptions
set on line 113 because state update is async, this.state
here is still the old one, thus dataSourceOptions
been override.
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.
Thanks for pointing this out! Let me chek on this.
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.
Found this article on it as "React may batch multiple setState() calls into a single update for performance " in https://legacy.reactjs.org/docs/state-and-lifecycle.html. There is possibility that the datasourceOptions can be override. I am looking into this see how to fix this issue
...this.state, | ||
selectedOption: selectedDataSource, | ||
}); | ||
this.props.onSelectedDataSource(selectedDataSource); |
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.
Should it be onSelectedDataSources
?
this.props.onSelectedDataSource(selectedDataSource); | |
this.props.onSelectedDataSources(selectedDataSource); |
@@ -54,6 +55,44 @@ export async function getDataSourcesWithFields( | |||
return response?.savedObjects; | |||
} | |||
|
|||
export function getDefaultDataSource( |
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.
Would be nice to add some test cases for this function :)
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.
Maybe leave a comment to describe the default data source selection logic?
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.
Sure. It is a draft CR. Would add a comment and test case
function renderDataSourceSelectable(config: DataSourceSelectableConfig): ReactElement | null { | ||
function renderDataSourceSelectable( | ||
config: DataSourceSelectableConfig, | ||
ui: IUiSettingsClient |
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.
looks like we already extract the uiSettings props above, and we don't need to add it here
ui: IUiSettingsClient |
@@ -73,6 +77,7 @@ export function DataSourceMenu<T>(props: DataSourceMenuProps<T>): ReactElement | | |||
dataSourceFilter={dataSourceFilter} | |||
hideLocalCluster={hideLocalCluster || false} | |||
fullWidth={fullWidth} | |||
uiSettings={ui} |
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.
uiSettings={ui} | |
uiSettings={uiSettings} |
return renderDataSourceSelectable(componentConfig as DataSourceSelectableConfig); | ||
return renderDataSourceSelectable( | ||
componentConfig as DataSourceSelectableConfig, | ||
uiSettings |
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.
uiSettings |
@zhyuanqi can you add details to the PR Description for the various sections? |
Hi This suppose to be a draft PR, forgot to mark it as draft. Will do it next time. THanks |
6dce230
to
36a24b8
Compare
} | ||
|
||
interface SelectedDataSourceOption extends DataSourceOption { | ||
checked?: boolean; | ||
checked?: string; |
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.
Checked should be a string as "on" or "off"
@@ -16,7 +16,7 @@ import { | |||
noAuthCredentialAuthMethod, | |||
} from '../types'; | |||
import { AuthenticationMethodRegistry } from '../auth_registry'; | |||
import { DataSourceOption } from './data_source_selector/data_source_selector'; | |||
import { DataSourceOption } from './data_source_menu/types'; |
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.
Change to use the DataSourceOption from /data_source_menu/types as this one only contains label and id. Previous one from selector contains an extra check which i don't use it here.
@@ -76,6 +76,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) | |||
- [Multiple Datasource] Add multi data source support to sample vega visualizations ([#6218](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6218)) | |||
- [Multiple Datasource] Fetch data source title for DataSourceView when only id is provided ([#6315](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6315) | |||
- [Workspace] Add permission control logic ([#6052](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6052)) | |||
- [Multiple Datasource] Add default icon for selectable component and make sure the default datasource shows automatically ([#6327](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6327)) |
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.
nit: The description here appears to be more descriptive than the PR title.
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.
Will modify the PR title and commit message
@@ -77,35 +83,58 @@ export class DataSourceSelectable extends React.Component< | |||
|
|||
async componentDidMount() { | |||
this._isMounted = true; | |||
let filteredDataSources: Array<SavedObject<DataSourceAttributes>> = []; | |||
let dataSourceOptions: DataSourceOption[] = []; | |||
getDataSourcesWithFields(this.props.savedObjectsClient, ['id', 'title', 'auth.type']) |
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.
could we covert Promise.then to await syntax for better readability and maintainability
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.
getDataSourcesWithFields(this.props.savedObjectsClient, ['id', 'title', 'auth.type']) | |
const ds = await getDataSourcesWithFields(this.props.savedObjectsClient, ['id', 'title', 'auth.type']); |
There is one snapshot in the test that needs to be updated |
…atasource shows automatically Signed-off-by: Yuanqi(Ella) Zhu <zhyuanqi@amazon.com>
…atasource shows automatically (#6327) (#6346) Signed-off-by: Yuanqi(Ella) Zhu <zhyuanqi@amazon.com> (cherry picked from commit 726fb0e) 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>
Description
Modify seletable picker in datasource management to show the default datasource
Issues Resolved
Screenshot
Screen.Recording.2024-04-03.at.6.36.10.PM.mov
Testing the changes
Check List
yarn test:jest
yarn test:jest_integration