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

[Multiple DataSource]Add datasource query for DataSourceView component to add label when only pass id #6315

Merged
merged 16 commits into from
Apr 3, 2024

Conversation

yujin-emma
Copy link
Contributor

@yujin-emma yujin-emma commented Apr 2, 2024

Description

Today the datasource menu does not populate the label of the datasource based on the datasourceId. This can be confusing to users, who may not know what human-readable datasource they are looking at.

This PR fix the issue in DataSourceView component. Adding the getDataSourceById to get the complete data source saved object when plugin only pass id

Issues Resolved

#6274

Screenshot

Testing the changes

When only pass id in the DataSourceMenu

<DataSourceMenu
        setMenuMountPoint={setActionMenu}
        componentType={'DataSourceView'}
        componentConfig={{fullWidth: true, savedObjects: savedObjects.client,
        notifications: notifications,
        activeOption: [{id: '5aaa7880-f116-11ee-9a73-d3c4f99fbc1f'}],
      }}
onlyid

when pass invalid dataSourceId

<DataSourceMenu
        setMenuMountPoint={setActionMenu}
        componentType={'DataSourceView'}
        componentConfig={{fullWidth: true, savedObjects: savedObjects.client,
        notifications: notifications,
        activeOption: [{id: '5aaa7880-f116-11ee-9a73'}], // format incorrect 
        // onSelectedDataSources: (dataSources) => console.log(dataSources)
      }}
datasourceviewtoast

When activeOption is empty, getDataSourceById throw out exception

exception

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

…nly pass id

Signed-off-by: yujin-emma <yujin.emma.work@gmail.com>
Signed-off-by: yujin-emma <yujin.emma.work@gmail.com>
@huyaboo huyaboo mentioned this pull request Apr 2, 2024
7 tasks
Copy link

codecov bot commented Apr 2, 2024

Codecov Report

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

Project coverage is 67.49%. Comparing base (fb31b2d) to head (ef5066d).

Files Patch % Lines
...c/components/data_source_view/data_source_view.tsx 71.42% 3 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6315      +/-   ##
==========================================
- Coverage   67.51%   67.49%   -0.03%     
==========================================
  Files        3376     3376              
  Lines       65783    65798      +15     
  Branches    10637    10639       +2     
==========================================
- Hits        44415    44408       -7     
- Misses      18785    18804      +19     
- Partials     2583     2586       +3     
Flag Coverage Δ
Linux_1 ?
Linux_2 55.60% <ø> (ø)
Linux_3 ?
Linux_4 ?
Windows_1 32.62% <ø> (-0.03%) ⬇️
Windows_2 55.57% <ø> (ø)
Windows_3 44.85% <72.72%> (+<0.01%) ⬆️
Windows_4 35.02% <0.00%> (-0.02%) ⬇️

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.

@bandinib-amzn bandinib-amzn changed the title Add datasource query for DataSourceView component to add label when o… Add datasource query for DataSourceView component to add label when only pass id Apr 2, 2024
@bandinib-amzn
Copy link
Member

Hi @yujin-emma

  1. Can you add more clear and detailed description in PR overview? It is hard to understand what problem this PR is fixing without any context?

  2. Can you fix codecov/patch CI failure by adding more tests?

  3. As a improvement I would suggest in render method only render component and extract all logic to separate private method. It would be easy to read and test.

Comment on lines +37 to +40
componentWillUnmount() {
this._isMounted = false;
}
async componentDidMount() {
Copy link
Member

Choose a reason for hiding this comment

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

just curious: why do we need componentDidMount and componentWillUnmount for this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need to check the props.selectedOption.label exist, if not, need to call getDataSourceById to get the title back and set this value, since we only have one option, we only need to call at most once before rendering, this is the reason why put a componentDidMount here. As for this._isMounted = false; in componentWillUnmount, this refer to code here: https://github.com/opensearch-project/OpenSearch-Dashboards/blob/main/src/plugins/data_source_management/public/components/data_source_selector/data_source_selector.tsx#L65

Comment on lines +83 to +84
if (this.state.selectedOption) {
items = this.state.selectedOption.map((option) => {
Copy link
Member

Choose a reason for hiding this comment

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

Can you please explain me this - why are we using this.state for selectedOption now instead of this.props?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we pass the selectedOption from props, there can be some empty field, e.g. label is optional, we will use state to reconstruct this and render with the state one

Copy link
Member

Choose a reason for hiding this comment

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

+1, props should be enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We do not only copy the value from props, but also add missing label in the state, therefore, only state.selectedOption contains sufficient information to render, props.selectedOption can miss the label for some plugins

Signed-off-by: yujin-emma <yujin.emma.work@gmail.com>
@BionIT
Copy link
Collaborator

BionIT commented Apr 2, 2024

test coverage check failed, can you add more tests?

CHANGELOG.md Outdated
@@ -83,6 +83,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- [BUG][MD]Fix schema for test connection to separate validation based on auth type ([#5997](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5997))
- [Discover] Enable 'Back to Top' Feature in Discover for scrolling to top ([#6008](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6008))
- [Discover] Fix lazy loading of the legacy table from getting stuck ([#6041](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6041))
- [MDS] Add data source query to fetch missing lable for DataSourceView ([#6315](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6315))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it a bug or a new feature/enhancement?

return (
<DataSourceView
selectedOption={activeOption && activeOption.length > 0 ? activeOption : undefined}
savedObjectsClient={savedObjects!}
Copy link
Collaborator

Choose a reason for hiding this comment

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

saved object client is not required

return (
<DataSourceView
selectedOption={activeOption && activeOption.length > 0 ? activeOption : undefined}
savedObjectsClient={savedObjects!}
notifications={notifications!.toasts}
Copy link
Collaborator

Choose a reason for hiding this comment

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

notification service is not required


interface DataSourceViewProps {
savedObjectsClient: SavedObjectsClientContract;
Copy link
Collaborator

Choose a reason for hiding this comment

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

savedobjects and notifications should be optional config

Signed-off-by: yujin-emma <yujin.emma.work@gmail.com>
yujin-emma and others added 7 commits April 2, 2024 23:14
Signed-off-by: yujin-emma <yujin.emma.work@gmail.com>
Signed-off-by: yujin-emma <yujin.emma.work@gmail.com>
Signed-off-by: yujin-emma <yujin.emma.work@gmail.com>
Signed-off-by: yujin-emma <yujin.emma.work@gmail.com>
Signed-off-by: yujin-emma <yujin.emma.work@gmail.com>
Signed-off-by: yujin-emma <yujin.emma.work@gmail.com>
Signed-off-by: yujin-emma <yujin.emma.work@gmail.com>
BionIT
BionIT previously approved these changes Apr 3, 2024
CHANGELOG.md Outdated Show resolved Hide resolved
yujin-emma and others added 3 commits April 2, 2024 20:58
Co-authored-by: Lu Yu <nluyu@amazon.com>
Signed-off-by: Yu Jin <112784385+yujin-emma@users.noreply.github.com>
…ce_menu/data_source_menu.tsx

Co-authored-by: Lu Yu <nluyu@amazon.com>
Signed-off-by: Yu Jin <112784385+yujin-emma@users.noreply.github.com>
BionIT
BionIT previously approved these changes Apr 3, 2024
@yujin-emma yujin-emma changed the title Add datasource query for DataSourceView component to add label when only pass id [Multiple DataSource]Add datasource query for DataSourceView component to add label when only pass id Apr 3, 2024
Signed-off-by: Yu Jin <112784385+yujin-emma@users.noreply.github.com>
@xinruiba
Copy link
Member

xinruiba commented Apr 3, 2024

LGTM, thanks

@BionIT BionIT added multiple datasource multiple datasource project v2.14.0 backport 2.x labels Apr 3, 2024
@BionIT BionIT merged commit cf43af3 into opensearch-project:main Apr 3, 2024
77 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Apr 3, 2024
…t to add label when only pass id (#6315)

* Add datasource query for DataSourceView component to add label when only pass id

Signed-off-by: yujin-emma <yujin.emma.work@gmail.com>

* update changelog

Signed-off-by: yujin-emma <yujin.emma.work@gmail.com>

* fix the failed test

Signed-off-by: yujin-emma <yujin.emma.work@gmail.com>

* fix comment

Signed-off-by: yujin-emma <yujin.emma.work@gmail.com>

* extract interface

Signed-off-by: yujin-emma <yujin.emma.work@gmail.com>

* revert yml

Signed-off-by: yujin-emma <yujin.emma.work@gmail.com>

* add more test

Signed-off-by: yujin-emma <yujin.emma.work@gmail.com>

* update snapshot

Signed-off-by: yujin-emma <yujin.emma.work@gmail.com>

* update snpshot

Signed-off-by: yujin-emma <yujin.emma.work@gmail.com>

* update change log

Signed-off-by: yujin-emma <yujin.emma.work@gmail.com>

* update change log and address other comments

Signed-off-by: yujin-emma <yujin.emma.work@gmail.com>

* Update CHANGELOG.md

Co-authored-by: Lu Yu <nluyu@amazon.com>
Signed-off-by: Yu Jin <112784385+yujin-emma@users.noreply.github.com>

* Update src/plugins/data_source_management/public/components/data_source_menu/data_source_menu.tsx

Co-authored-by: Lu Yu <nluyu@amazon.com>
Signed-off-by: Yu Jin <112784385+yujin-emma@users.noreply.github.com>

---------

Signed-off-by: yujin-emma <yujin.emma.work@gmail.com>
Signed-off-by: Yu Jin <112784385+yujin-emma@users.noreply.github.com>
Co-authored-by: Lu Yu <nluyu@amazon.com>
(cherry picked from commit cf43af3)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

# Conflicts:
#	CHANGELOG.md
BionIT pushed a commit that referenced this pull request Apr 3, 2024
…t to add label when only pass id (#6315) (#6332)

* Add datasource query for DataSourceView component to add label when only pass id

Signed-off-by: yujin-emma <yujin.emma.work@gmail.com>

* update changelog

Signed-off-by: yujin-emma <yujin.emma.work@gmail.com>

* fix the failed test

Signed-off-by: yujin-emma <yujin.emma.work@gmail.com>

* fix comment

Signed-off-by: yujin-emma <yujin.emma.work@gmail.com>

* extract interface

Signed-off-by: yujin-emma <yujin.emma.work@gmail.com>

* revert yml

Signed-off-by: yujin-emma <yujin.emma.work@gmail.com>

* add more test

Signed-off-by: yujin-emma <yujin.emma.work@gmail.com>

* update snapshot

Signed-off-by: yujin-emma <yujin.emma.work@gmail.com>

* update snpshot

Signed-off-by: yujin-emma <yujin.emma.work@gmail.com>

* update change log

Signed-off-by: yujin-emma <yujin.emma.work@gmail.com>

* update change log and address other comments

Signed-off-by: yujin-emma <yujin.emma.work@gmail.com>

* Update CHANGELOG.md

Co-authored-by: Lu Yu <nluyu@amazon.com>
Signed-off-by: Yu Jin <112784385+yujin-emma@users.noreply.github.com>

* Update src/plugins/data_source_management/public/components/data_source_menu/data_source_menu.tsx

Co-authored-by: Lu Yu <nluyu@amazon.com>
Signed-off-by: Yu Jin <112784385+yujin-emma@users.noreply.github.com>

---------

Signed-off-by: yujin-emma <yujin.emma.work@gmail.com>
Signed-off-by: Yu Jin <112784385+yujin-emma@users.noreply.github.com>
Co-authored-by: Lu Yu <nluyu@amazon.com>
(cherry picked from commit cf43af3)
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
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants