-
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
[Multiple Datasource] Expose filterfn in datasource menu component to allow filter data sources before rendering in navigation bar #6113
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ import { | |
EuiSpacer, | ||
} from '@elastic/eui'; | ||
import { SavedObjectsClientContract, ToastsStart } from 'opensearch-dashboards/public'; | ||
import { getDataSources } from '../utils'; | ||
import { getDataSourcesWithFields } from '../utils'; | ||
import { DataSourceOption, LocalCluster } from '../data_source_selector/data_source_selector'; | ||
|
||
interface DataSourceSelectableProps { | ||
|
@@ -26,6 +26,7 @@ interface DataSourceSelectableProps { | |
hideLocalCluster: boolean; | ||
fullWidth: boolean; | ||
selectedOption?: DataSourceOption[]; | ||
filterFn?: (dataSource: any) => boolean; | ||
} | ||
|
||
interface DataSourceSelectableState { | ||
|
@@ -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']) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how we extend this, which not only can filter auth.type? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
.then((fetchedDataSources) => { | ||
if (fetchedDataSources?.length) { | ||
let dataSourceOptions = fetchedDataSources.map((dataSource) => ({ | ||
id: dataSource.id, | ||
label: dataSource.title, | ||
})); | ||
let filteredDataSources = []; | ||
if (this.props.filterFn) { | ||
filteredDataSources = fetchedDataSources.filter((ds) => this.props.filterFn!(ds)); | ||
} | ||
|
||
dataSourceOptions = dataSourceOptions.sort((a, b) => | ||
a.label.toLowerCase().localeCompare(b.label.toLowerCase()) | ||
); | ||
if (filteredDataSources.length === 0) { | ||
filteredDataSources = fetchedDataSources; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: And filter out all "NoAuth" dataSources. Looks like we will return Thanks~ |
||
} | ||
|
||
const dataSourceOptions = filteredDataSources | ||
.map((dataSource) => ({ | ||
id: dataSource.id, | ||
label: dataSource.attributes?.title || '', | ||
})) | ||
.sort((a, b) => a.label.toLowerCase().localeCompare(b.label.toLowerCase())); | ||
if (!this.props.hideLocalCluster) { | ||
dataSourceOptions.unshift(LocalCluster); | ||
} | ||
|
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.
Where we configure this filterfn, is configurable in the yml file or somewhere or must change the code to configure the filter? thanks
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 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