Skip to content
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

Merged
merged 2 commits into from
Apr 4, 2024

Conversation

zhyuanqi
Copy link
Collaborator

@zhyuanqi zhyuanqi commented Apr 3, 2024

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

  • All tests pass
    • yarn test:jest
    • yarn test:jest_integration
  • New functionality includes testing.
  • New functionality has been documented.
  • Update CHANGELOG.md
  • Commits are signed per the DCO using --signoff

Copy link

codecov bot commented Apr 3, 2024

Codecov Report

Attention: Patch coverage is 78.57143% with 6 lines in your changes are missing coverage. Please review.

Project coverage is 67.51%. Comparing base (b92387a) to head (36307a2).

Files Patch % Lines
.../data_source_selectable/data_source_selectable.tsx 80.76% 3 Missing and 2 partials ⚠️
...rc/plugins/data_source_management/public/plugin.ts 0.00% 1 Missing ⚠️
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     
Flag Coverage Δ
Linux_1 32.60% <ø> (ø)
Linux_2 55.60% <ø> (ø)
Linux_3 44.89% <78.57%> (+0.02%) ⬆️
Linux_4 34.99% <0.00%> (-0.01%) ⬇️
Windows_1 32.62% <ø> (ø)
Windows_2 55.57% <ø> (ø)
Windows_3 44.90% <78.57%> (+<0.01%) ⬆️
Windows_4 34.99% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -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
Copy link
Member

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({
Copy link
Member

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

@zhyuanqi zhyuanqi Apr 3, 2024

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be onSelectedDataSources?

Suggested change
this.props.onSelectedDataSource(selectedDataSource);
this.props.onSelectedDataSources(selectedDataSource);

@@ -54,6 +55,44 @@ export async function getDataSourcesWithFields(
return response?.savedObjects;
}

export function getDefaultDataSource(
Copy link
Member

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 :)

Copy link
Member

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?

Copy link
Collaborator Author

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
Copy link
Collaborator

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

Suggested change
ui: IUiSettingsClient

@@ -73,6 +77,7 @@ export function DataSourceMenu<T>(props: DataSourceMenuProps<T>): ReactElement |
dataSourceFilter={dataSourceFilter}
hideLocalCluster={hideLocalCluster || false}
fullWidth={fullWidth}
uiSettings={ui}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
uiSettings={ui}
uiSettings={uiSettings}

return renderDataSourceSelectable(componentConfig as DataSourceSelectableConfig);
return renderDataSourceSelectable(
componentConfig as DataSourceSelectableConfig,
uiSettings
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
uiSettings

@ashwin-pc
Copy link
Member

@zhyuanqi can you add details to the PR Description for the various sections?

@zhyuanqi
Copy link
Collaborator Author

zhyuanqi commented Apr 3, 2024

@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

@zhyuanqi zhyuanqi marked this pull request as ready for review April 4, 2024 01:28
@zhyuanqi zhyuanqi changed the title Add selectable Modify seletable picker in datasource management to show the default datasource Apr 4, 2024
@zhyuanqi zhyuanqi force-pushed the selectable branch 3 times, most recently from 6dce230 to 36a24b8 Compare April 4, 2024 01:41
}

interface SelectedDataSourceOption extends DataSourceOption {
checked?: boolean;
checked?: string;
Copy link
Collaborator Author

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';
Copy link
Collaborator Author

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.

BionIT
BionIT previously approved these changes Apr 4, 2024
@@ -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))
Copy link
Member

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.

Copy link
Collaborator Author

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'])
Copy link
Member

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
getDataSourcesWithFields(this.props.savedObjectsClient, ['id', 'title', 'auth.type'])
const ds = await getDataSourcesWithFields(this.props.savedObjectsClient, ['id', 'title', 'auth.type']);

@zhyuanqi zhyuanqi changed the title Modify seletable picker in datasource management to show the default datasource Add default icon for selectable component and make sure the default datasource shows automatically Apr 4, 2024
@BionIT
Copy link
Collaborator

BionIT commented Apr 4, 2024

There is one snapshot in the test that needs to be updated

@BionIT BionIT added multiple datasource multiple datasource project backport 2.x v2.14.0 labels Apr 4, 2024
…atasource shows automatically

Signed-off-by: Yuanqi(Ella) Zhu <[email protected]>
@zhongnansu zhongnansu merged commit 726fb0e into opensearch-project:main Apr 4, 2024
69 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Apr 4, 2024
…atasource shows automatically (#6327)

Signed-off-by: Yuanqi(Ella) Zhu <[email protected]>
(cherry picked from commit 726fb0e)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

# Conflicts:
#	CHANGELOG.md
bandinib-amzn pushed a commit that referenced this pull request Apr 4, 2024
…atasource shows automatically (#6327) (#6346)

Signed-off-by: Yuanqi(Ella) Zhu <[email protected]>
(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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

6 participants