-
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] Add component to show single selected data source in read only mode #6125
Changes from 2 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.
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { ShallowWrapper, shallow } from 'enzyme'; | ||
import React from 'react'; | ||
import { DataSourceView } from './data_source_view'; | ||
|
||
describe('DataSourceView', () => { | ||
let component: ShallowWrapper<any, Readonly<{}>, React.Component<{}, {}, any>>; | ||
|
||
it('should render normally with local cluster not hidden', () => { | ||
component = shallow( | ||
<DataSourceView fullWidth={false} selectedOption={[{ id: 'test1', label: 'test1' }]} /> | ||
); | ||
expect(component).toMatchSnapshot(); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React from 'react'; | ||
import { i18n } from '@osd/i18n'; | ||
import { EuiPopover, EuiButtonEmpty, EuiButtonIcon, EuiContextMenu } from '@elastic/eui'; | ||
import { DataSourceOption } from '../data_source_selector/data_source_selector'; | ||
|
||
interface DataSourceViewProps { | ||
fullWidth: boolean; | ||
selectedOption?: DataSourceOption[]; | ||
} | ||
|
||
interface DataSourceViewState { | ||
dataSourceOptions: DataSourceOption[]; | ||
selectedOption: DataSourceOption[]; | ||
isPopoverOpen: boolean; | ||
} | ||
|
||
export class DataSourceView extends React.Component<DataSourceViewProps, DataSourceViewState> { | ||
private _isMounted: boolean = false; | ||
|
||
constructor(props: DataSourceViewProps) { | ||
super(props); | ||
|
||
this.state = { | ||
isPopoverOpen: false, | ||
selectedOption: this.props.selectedOption ? this.props.selectedOption : [], | ||
}; | ||
} | ||
|
||
componentWillUnmount() { | ||
this._isMounted = false; | ||
Check warning on line 35 in src/plugins/data_source_management/public/components/data_source_view/data_source_view.tsx Codecov / codecov/patchsrc/plugins/data_source_management/public/components/data_source_view/data_source_view.tsx#L35
|
||
} | ||
|
||
onClick() { | ||
this.setState({ ...this.state, isPopoverOpen: !this.state.isPopoverOpen }); | ||
Check warning on line 39 in src/plugins/data_source_management/public/components/data_source_view/data_source_view.tsx Codecov / codecov/patchsrc/plugins/data_source_management/public/components/data_source_view/data_source_view.tsx#L39
|
||
} | ||
|
||
closePopover() { | ||
this.setState({ ...this.state, isPopoverOpen: false }); | ||
Check warning on line 43 in src/plugins/data_source_management/public/components/data_source_view/data_source_view.tsx Codecov / codecov/patchsrc/plugins/data_source_management/public/components/data_source_view/data_source_view.tsx#L43
|
||
} | ||
|
||
async componentDidMount() { | ||
BionIT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
this._isMounted = true; | ||
} | ||
|
||
render() { | ||
const button = ( | ||
<EuiButtonIcon | ||
iconType="iInCircle" | ||
display="empty" | ||
aria-label="Next" | ||
onClick={this.onClick.bind(this)} | ||
/> | ||
); | ||
|
||
let items = []; | ||
|
||
if (this.props.selectedOption) { | ||
items = this.props.selectedOption.map((option) => { | ||
return { | ||
name: option.label, | ||
disabled: true, | ||
}; | ||
}); | ||
} | ||
|
||
const panels = [ | ||
{ | ||
id: 0, | ||
title: 'Selected data source', | ||
items, | ||
}, | ||
]; | ||
|
||
return ( | ||
<> | ||
<EuiButtonEmpty | ||
className="euiHeaderLink" | ||
data-test-subj="dataSourceViewContextMenuHeaderLink" | ||
aria-label={i18n.translate('dataSourceView.dataSourceOptionsButtonAriaLabel', { | ||
defaultMessage: 'dataSourceViewMenuButton', | ||
})} | ||
iconType="database" | ||
iconSide="left" | ||
size="s" | ||
disabled={true} | ||
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. should we have some condition here to dynamically compute the value of 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 is always disabled based on requirements, since this component is only used in readyonly mode |
||
> | ||
{this.props.selectedOption && this.props.selectedOption.length > 0 | ||
? this.props.selectedOption[0].label | ||
: ''} | ||
</EuiButtonEmpty> | ||
<EuiPopover | ||
id={'dataSourceSViewContextMenuPopover'} | ||
BionIT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
button={button} | ||
isOpen={this.state.isPopoverOpen} | ||
closePopover={this.closePopover.bind(this)} | ||
panelPaddingSize="none" | ||
anchorPosition="downLeft" | ||
> | ||
<EuiContextMenu initialPanelId={0} panels={panels} /> | ||
</EuiPopover> | ||
</> | ||
); | ||
} | ||
} |
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.
Since we do "!" operation here: https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6125/files#diff-ca572b8e5224968b4b5cfd2a810b1280195b20f6eff17b93657fefa89bb50ed1R75
Any reason we set these props as 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.
the callback function doesn't make sense for read only component, since there is no change to the selection, but only makes sense for selectables, hope it makes sense
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 the response.
In that case I assume we don't need this line?:
https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6125/files#diff-ca572b8e5224968b4b5cfd2a810b1280195b20f6eff17b93657fefa89bb50ed1R91