-
Notifications
You must be signed in to change notification settings - Fork 916
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] Enhanced data source selector with default datasource shows as first choice #6293
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6293 +/- ##
=======================================
Coverage 67.50% 67.50%
=======================================
Files 3376 3376
Lines 65800 65830 +30
Branches 10639 10648 +9
=======================================
+ Hits 44417 44441 +24
- Misses 18800 18803 +3
- Partials 2583 2586 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
9a8f88b
to
01073e8
Compare
nit : add a prefix |
CHANGELOG.md
Outdated
@@ -162,6 +162,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) | |||
- [Discover] Enhanced the data source selector with added sorting functionality ([#5719](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5719)) | |||
- [Multiple Datasource] Add datasource picker component and use it in devtools and tutorial page when multiple datasource is enabled ([#5756](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5756)) | |||
- [Multiple Datasource] Add datasource picker to import saved object flyout when multiple data source is enabled ([#5781](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5781)) | |||
- [Multiple Datasource] Add show default datasource for selector picker ([#6293](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6293/files)) |
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 : add the changelog entry in the middle (say line 163) instead of append it in the last line would save some conflict resolve efforts in case any
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.
Got it! Good advise! It is ver helpful. 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.
correct the PR link to remove the "file" at the end?
- [Multiple Datasource] Add show default datasource for selector picker ([#6293](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6293/files)) | |
- [Multiple Datasource] Add show default datasource for selector picker ([#6293](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6293)) |
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.
+1
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.
Can we fix the position of the changelog, it is now under 2.12 section
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.
Got it
}); | ||
|
||
it('should return local cluster if it exists and no default options in the data sources', () => { | ||
mockUiSettingsCalls(uiSettings, 'get', null); |
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.
null
, Is it correct argument which passed here?
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.
Yes. So if the uiSettings could not find the defaultDataSource in the config, it will return null.
} else if ( | ||
uiSettings && | ||
uiSettings?.get('defaultDataSource', null) !== null && | ||
dataSources.find((dataSource) => dataSource.id === uiSettings?.get('defaultDataSource')) |
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.
There are two locations were used uiSettings?.get('defaultDataSource')
, is it possible to use const defaultDataSourceId = uiSettings?.get('defaultDataSource');
to simplify the code
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. I can work 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.
+1
) { | ||
let defaultShowingDataSource: DataSourceOption; | ||
|
||
if (defaultOption && dataSources.find((dataSource) => dataSource.id === defaultOption?.[0].id)) { |
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.
May be we can define the those value at the beginning, make the logic more clear
if (defaultDataSource) {
...
} else if (uiSettingsDataSource) {
....
} else if (!hideLocalCluster) {
....
} else {
...
}
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.
Make sense, let me check 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.
think about adopting early return pattern
https://gomakethings.com/the-early-return-pattern-in-javascript/
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. Will check on this.
.../data_source_management/public/components/data_source_selector/data_source_selector.test.tsx
Show resolved
Hide resolved
if (this.props.showDefault) { | ||
const dataSources = getFilterDataSources( | ||
this.state.allDataSources, | ||
this.props.dataSourceFilter | ||
); | ||
const defaultDataSource = getDefaultDataSource( | ||
dataSources, | ||
LocalCluster, | ||
this.props.uiSettings, | ||
this.props.hideLocalCluster, | ||
this.props.defaultOption | ||
); | ||
this.props.showDefault(defaultDataSource); | ||
} |
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 this change.
I remember @BionIT have a PR to Use data source filter function before rendering
And in this line: https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6175/files#diff-ec5b6ef64504177e50cad326dcc07ada2135faafe924d25b0f4df088bc7b4823L77 she move filter function call from componentDidMount()
to render()
.
Are there any concerns to follow the same format by also moving this logic into render()
function?
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.
Hi This showDefault should be use as a callback function that plugins team can use to get from the defaultShowing datasource. Below is how plugin team use it.
const [defaultDataSource, setDefaultDataSource] = React.useState<DataSourceOption>();
const showDefault = (source: DataSourceOption) => {
setDefaultDataSource(source);
};
<DataSourceSelector
.......
showDefault={showDefault}
/>
As componentDidMount should perform data fetching and initialization where render focus on rendering the UI based on component's state.Let me look into this more
@@ -78,6 +79,41 @@ export async function setFirstDataSourceAsDefault( | |||
} | |||
} | |||
|
|||
export function getFilterDataSources( |
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 getFilteredDataSources
be a better naming?
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 will rename it
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.
@zhongnansu @zhyuanqi , would you use suggested fix feature for quick apply the suggestion, like below
export function getFilterDataSources( | |
export function getFilteredDataSources( |
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.
good suggestion, will do!
import { AuthenticationMethod, AuthenticationMethodRegistry } from '../auth_registry'; | ||
import { deepEqual } from 'assert'; | ||
import { DataSourceAttributes } from 'src/plugins/data_source/common/data_sources'; // Import the missing 'SigV4Content' here |
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.
do we need to import SigV4Content? can we remove the comment?
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.
Let me remove this line here.
@@ -29,6 +30,8 @@ export interface DataSourceSelectorProps { | |||
removePrepend?: boolean; | |||
dataSourceFilter?: (dataSource: SavedObject<DataSourceAttributes>) => boolean; | |||
compressed?: boolean; | |||
uiSettings?: IUiSettingsClient; | |||
showDefault?: (source: DataSourceOption) => void; |
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.
might be a dumb question, but why do we want those 2 param to be optional? shouldn't we always show default?
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.
The uiSettings, for plugins, we want to pass it during plugin setup, so i set it as optional. The showDefault is a callback function, depends if plugin wants to call this the see what is the default or not. So it is optional
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.
got it, thx Ella
CHANGELOG.md
Outdated
@@ -162,6 +162,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) | |||
- [Discover] Enhanced the data source selector with added sorting functionality ([#5719](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5719)) | |||
- [Multiple Datasource] Add datasource picker component and use it in devtools and tutorial page when multiple datasource is enabled ([#5756](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5756)) | |||
- [Multiple Datasource] Add datasource picker to import saved object flyout when multiple data source is enabled ([#5781](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5781)) | |||
- [Multiple Datasource] Add show default datasource for selector picker ([#6293](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6293/files)) |
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.
Can we fix the position of the changelog, it is now under 2.12 section
...ource_management/public/components/data_source_selector/create_data_source_selector.test.tsx
Show resolved
Hide resolved
@@ -76,6 +79,20 @@ export class DataSourceSelector extends React.Component< | |||
allDataSources: fetchedDataSources, | |||
}); | |||
} | |||
if (this.props.showDefault) { | |||
const dataSources = getFilterDataSources( | |||
this.state.allDataSources, |
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.
we can just pass fetchedDataSources
@@ -76,6 +79,20 @@ export class DataSourceSelector extends React.Component< | |||
allDataSources: fetchedDataSources, | |||
}); | |||
} | |||
if (this.props.showDefault) { | |||
const dataSources = getFilterDataSources( |
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 should be filteredDataSources
this.props.hideLocalCluster, | ||
this.props.defaultOption | ||
); | ||
this.props.showDefault(defaultDataSource); |
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.
can we reuse the existing callback function? onSelectedDataSource
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 can make the change. Just worry about if it would break any existing behavior. Let me change on this
const dataSources = this.props.dataSourceFilter | ||
? this.state.allDataSources.filter((ds) => this.props.dataSourceFilter!(ds)) | ||
: this.state.allDataSources; | ||
const dataSources = getFilterDataSources( |
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.
instead of having 2 separate functions and have one of them called twice, would it be better to have one function which takes the filter function and does the filtering logic and store the default data source in the state here, so that we just need to call the function once here?
@@ -140,6 +159,16 @@ export class DataSourceSelector extends React.Component< | |||
isDisabled={this.props.disabled} | |||
fullWidth={this.props.fullWidth || false} | |||
data-test-subj={'dataSourceSelectorComboBox'} | |||
renderOption={(option) => ( | |||
<EuiFlexGroup alignItems="center"> | |||
<EuiFlexItem grow={1}>{option.label}</EuiFlexItem> |
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.
can we add a test?
} else if ( | ||
uiSettings && | ||
uiSettings?.get('defaultDataSource', null) !== null && | ||
dataSources.find((dataSource) => dataSource.id === uiSettings?.get('defaultDataSource')) |
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.
+1
9073369
to
3bc74ae
Compare
...ugins/data_source_management/public/components/data_source_selector/data_source_selector.tsx
Outdated
Show resolved
Hide resolved
}: DevToolsWrapperProps) { | ||
const mountedTool = useRef<MountedDevToolDescriptor | null>(null); | ||
const [isLoading, setIsLoading] = React.useState(false); |
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 isLoading be true initially, then set to false once it is loaded?
…t to customer Signed-off-by: Yuanqi(Ella) Zhu <[email protected]>
…ce_selector/data_source_selector.tsx Co-authored-by: Lu Yu <[email protected]> Signed-off-by: Yuanqi(Ella) Zhu <[email protected]>
Co-authored-by: Lu Yu <[email protected]> Signed-off-by: Yuanqi(Ella) Zhu <[email protected]>
d26ef5f
to
3bf9adf
Compare
Signed-off-by: Yuanqi(Ella) Zhu <[email protected]>
…source shows as first choice (#6293) * edit datasource selector to show dafault datasource and return default to customer Signed-off-by: Yuanqi(Ella) Zhu <[email protected]> * Update src/plugins/data_source_management/public/components/data_source_selector/data_source_selector.tsx Co-authored-by: Lu Yu <[email protected]> Signed-off-by: Yuanqi(Ella) Zhu <[email protected]> * Apply suggestions from code review Co-authored-by: Lu Yu <[email protected]> Signed-off-by: Yuanqi(Ella) Zhu <[email protected]> * fix syntax Signed-off-by: Yuanqi(Ella) Zhu <[email protected]> --------- Signed-off-by: Yuanqi(Ella) Zhu <[email protected]> Signed-off-by: Yuanqi(Ella) Zhu <[email protected]> Co-authored-by: Lu Yu <[email protected]> (cherry picked from commit 557fbcf) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> # Conflicts: # CHANGELOG.md
…source shows as first choice (#6293) (#6339) * edit datasource selector to show dafault datasource and return default to customer Signed-off-by: Yuanqi(Ella) Zhu <[email protected]> * Update src/plugins/data_source_management/public/components/data_source_selector/data_source_selector.tsx Co-authored-by: Lu Yu <[email protected]> Signed-off-by: Yuanqi(Ella) Zhu <[email protected]> * Apply suggestions from code review Co-authored-by: Lu Yu <[email protected]> Signed-off-by: Yuanqi(Ella) Zhu <[email protected]> * fix syntax Signed-off-by: Yuanqi(Ella) Zhu <[email protected]> --------- Signed-off-by: Yuanqi(Ella) Zhu <[email protected]> Signed-off-by: Yuanqi(Ella) Zhu <[email protected]> Co-authored-by: Lu Yu <[email protected]> (cherry picked from commit 557fbcf) 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
Issues Resolved
Screenshot
Screen.Recording.2024-04-01.at.9.53.47.AM.mov
Testing the changes
Check List
yarn test:jest
yarn test:jest_integration