-
Notifications
You must be signed in to change notification settings - Fork 918
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Multiple Datasource] Add component to show single selected data sour…
…ce in read only mode (#6125) * add component to show selected data source in read only mode Signed-off-by: Lu Yu <[email protected]> * add change log Signed-off-by: Lu Yu <[email protected]> * fix typo and remove unused fields Signed-off-by: Lu Yu <[email protected]> * fix snapshot Signed-off-by: Lu Yu <[email protected]> --------- Signed-off-by: Lu Yu <[email protected]>
- Loading branch information
Showing
8 changed files
with
250 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 18 additions & 2 deletions
20
...anagement/public/components/data_source_menu/__snapshots__/data_source_menu.test.tsx.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...anagement/public/components/data_source_view/__snapshots__/data_source_view.test.tsx.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
19 changes: 19 additions & 0 deletions
19
...ugins/data_source_management/public/components/data_source_view/data_source_view.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |
98 changes: 98 additions & 0 deletions
98
src/plugins/data_source_management/public/components/data_source_view/data_source_view.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* 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 { | ||
selectedOption: DataSourceOption[]; | ||
isPopoverOpen: boolean; | ||
} | ||
|
||
export class DataSourceView extends React.Component<DataSourceViewProps, DataSourceViewState> { | ||
constructor(props: DataSourceViewProps) { | ||
super(props); | ||
|
||
this.state = { | ||
isPopoverOpen: false, | ||
selectedOption: this.props.selectedOption ? this.props.selectedOption : [], | ||
}; | ||
} | ||
|
||
onClick() { | ||
this.setState({ ...this.state, isPopoverOpen: !this.state.isPopoverOpen }); | ||
} | ||
|
||
closePopover() { | ||
this.setState({ ...this.state, isPopoverOpen: false }); | ||
} | ||
|
||
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} | ||
> | ||
{this.props.selectedOption && this.props.selectedOption.length > 0 | ||
? this.props.selectedOption[0].label | ||
: ''} | ||
</EuiButtonEmpty> | ||
<EuiPopover | ||
id={'dataSourceViewContextMenuPopover'} | ||
button={button} | ||
isOpen={this.state.isPopoverOpen} | ||
closePopover={this.closePopover.bind(this)} | ||
panelPaddingSize="none" | ||
anchorPosition="downLeft" | ||
> | ||
<EuiContextMenu initialPanelId={0} panels={panels} /> | ||
</EuiPopover> | ||
</> | ||
); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/plugins/data_source_management/public/components/data_source_view/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export { DataSourceView } from './data_source_view'; |