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] Expose filterfn in datasource menu component to allow filter data sources before rendering in navigation bar #6113

Merged
merged 4 commits into from
Mar 12, 2024

Conversation

BionIT
Copy link
Collaborator

@BionIT BionIT commented Mar 11, 2024

Description

In #6057, we exposed a few properties in data source selector component for plugins to consume, and in #6082, we created a new data source menu component to be mounted into navigation bar. Based on requirements, we should also expose this filter function to allow plugins to exclude data sources that don't make sense to render in options

Issues Resolved

Screenshot

exportfilterinselectable.mp4

Testing the changes

The following steps were performed in the recording:

  1. create a data source with no authentication
  2. go to add sample data page, and see that the data source picker shows all available data sources including the one configured with no authentication
  3. go to query workbench plugin, and see that the data source menu doesn't show the data source with no auth
  4. go to the query workbench implementation, and see the filterfn passed in will exclude the data sources with no auth

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

Signed-off-by: Lu Yu <nluyu@amazon.com>
@BionIT BionIT changed the title [Multiple Datasource] Expose filterfn in datasource menu component [Multiple Datasource] Expose filterfn in datasource menu component to allow filter data sources before rendering in navigation bar Mar 11, 2024
Signed-off-by: Lu Yu <nluyu@amazon.com>
Copy link

codecov bot commented Mar 11, 2024

Codecov Report

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

Project coverage is 67.15%. Comparing base (4b89ad0) to head (1ce11a3).

Files Patch % Lines
...onents/data_source_menu/data_source_selectable.tsx 90.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6113      +/-   ##
==========================================
+ Coverage   67.14%   67.15%   +0.01%     
==========================================
  Files        3326     3326              
  Lines       64394    64400       +6     
  Branches    10358    10361       +3     
==========================================
+ Hits        43237    43249      +12     
+ Misses      18627    18620       -7     
- Partials     2530     2531       +1     
Flag Coverage Δ
Linux_1 31.73% <ø> (ø)
Linux_2 55.23% <ø> (ø)
Linux_3 ?
Linux_4 35.08% <0.00%> (-0.01%) ⬇️
Windows_1 31.75% <ø> (ø)
Windows_2 55.20% <ø> (ø)
Windows_3 44.75% <90.00%> (+0.02%) ⬆️
Windows_4 35.08% <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.

@@ -69,18 +70,24 @@ export class DataSourceSelectable extends React.Component<

async componentDidMount() {
this._isMounted = true;
getDataSources(this.props.savedObjectsClient)
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.

how we extend this, which not only can filter auth.type?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

we can extend by adding more fields, the fields entered here are to specify which fields should be returned from the API for data source object, and before, it restricts to id, title, description, auth type is required for security plugin to remove no auth data sources since they would indicate non-FGAC domains

perPage: 10000,
type: 'data-source',
});
expect(toasts.addWarning).toBeCalledTimes(0);
});

it('should filter options if configured', async () => {
Copy link
Member

Choose a reason for hiding this comment

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

Where we configure this filterfn, is configurable in the yml file or somewhere or must change the code to configure the filter? thanks

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This filterFn is passed by plugins when they consume the data source menu component, it is used then in the component when it is mounted to remove unwanted data sources before rendering

Signed-off-by: Lu Yu <nluyu@amazon.com>
a.label.toLowerCase().localeCompare(b.label.toLowerCase())
);
if (filteredDataSources.length === 0) {
filteredDataSources = fetchedDataSources;
Copy link
Member

@xinruiba xinruiba Mar 12, 2024

Choose a reason for hiding this comment

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

If no filteredDataSources exist after apply filter, we will show all dataSource instead. And those datasource won't meet the filter condition.

Will it introduce in some confusions? What if we just show nothing.

Thanks

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This filter is for plugins to decide how they want to render the options, there is possibility the filter would remove all options then there will be no options displayed. If plugins decide not to add filter options, then it should show all data sources, why it is confusing?

Copy link
Member

@xinruiba xinruiba Mar 12, 2024

Choose a reason for hiding this comment

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

This comment is not a blocker of this PR~

Suppose we have following dataSources:
[{datasource1, NoAuth}, {datasource2, NoAuth}, {datasource3, NoAuth}]

And filter out all "NoAuth" dataSources.

Looks like we will return [{datasource1, NoAuth}, {datasource2, NoAuth}, {datasource3, NoAuth}] here,
instead of an empty array. Is that expected?

Thanks~

@seraphjiang seraphjiang added the multiple datasource multiple datasource project label Mar 12, 2024
@BionIT BionIT merged commit 45096bb into opensearch-project:main Mar 12, 2024
70 of 71 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Mar 25, 2024
… allow filter data sources before rendering in navigation bar (#6113)

* expose filterfn in datasource menu component

Signed-off-by: Lu Yu <nluyu@amazon.com>

* add changelog

Signed-off-by: Lu Yu <nluyu@amazon.com>

---------

Signed-off-by: Lu Yu <nluyu@amazon.com>
(cherry picked from commit 45096bb)
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 Mar 25, 2024
… allow filter data sources before rendering in navigation bar (#6113) (#6261)

* expose filterfn in datasource menu component

Signed-off-by: Lu Yu <nluyu@amazon.com>

* add changelog

Signed-off-by: Lu Yu <nluyu@amazon.com>

---------

Signed-off-by: Lu Yu <nluyu@amazon.com>
(cherry picked from commit 45096bb)
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.

6 participants