-
Notifications
You must be signed in to change notification settings - Fork 14.2k
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
refactor: Use Antd Dropdown instead of react-bootstrap in DatasourceControl #11395
Changes from 5 commits
9780dc8
c8ba705
d0038bb
5561a80
6ee0e24
764734f
7a3864b
6bdca35
018c714
009bd79
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
import React from 'react'; | ||
import { Tooltip as BaseTooltip } from 'src/common/components'; | ||
import { TooltipProps } from 'antd/lib/tooltip'; | ||
|
||
const Tooltip = (props: TooltipProps) => ( | ||
<BaseTooltip overlayStyle={{ fontSize: '12px' }} {...props} /> | ||
); | ||
|
||
export default Tooltip; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,21 +18,12 @@ | |
*/ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { | ||
Col, | ||
Collapse, | ||
DropdownButton, | ||
MenuItem, | ||
OverlayTrigger, | ||
Row, | ||
Tooltip, | ||
Well, | ||
} from 'react-bootstrap'; | ||
import { Col, Collapse, Row, Well } from 'react-bootstrap'; | ||
import { t, styled } from '@superset-ui/core'; | ||
import { ColumnOption, MetricOption } from '@superset-ui/chart-controls'; | ||
|
||
import TooltipWrapper from 'src/components/TooltipWrapper'; | ||
|
||
import { Dropdown, Menu } from 'src/common/components'; | ||
import Tooltip from 'src/common/components/Tooltip'; | ||
import Icon from 'src/components/Icon'; | ||
import ChangeDatasourceModal from 'src/datasource/ChangeDatasourceModal'; | ||
import DatasourceModal from 'src/datasource/DatasourceModal'; | ||
|
@@ -58,7 +49,7 @@ const defaultProps = { | |
}; | ||
|
||
const Styles = styled.div` | ||
#datasource_menu { | ||
.ant-dropdown-trigger { | ||
margin-left: ${({ theme }) => theme.gridUnit}px; | ||
box-shadow: none; | ||
&:active { | ||
|
@@ -98,6 +89,7 @@ class DatasourceControl extends React.PureComponent { | |
this.toggleEditDatasourceModal = this.toggleEditDatasourceModal.bind(this); | ||
this.toggleShowDatasource = this.toggleShowDatasource.bind(this); | ||
this.renderDatasource = this.renderDatasource.bind(this); | ||
this.handleMenuItemClick = this.handleMenuItemClick.bind(this); | ||
} | ||
|
||
onDatasourceSave(datasource) { | ||
|
@@ -125,6 +117,15 @@ class DatasourceControl extends React.PureComponent { | |
})); | ||
} | ||
|
||
handleMenuItemClick({ key }) { | ||
if (key === '1') { | ||
this.toggleChangeDatasourceModal(); | ||
} | ||
if (key === '3') { | ||
this.toggleEditDatasourceModal(); | ||
} | ||
} | ||
|
||
renderDatasource() { | ||
const { datasource } = this.props; | ||
const { showDatasource } = this.state; | ||
|
@@ -176,18 +177,32 @@ class DatasourceControl extends React.PureComponent { | |
showDatasource, | ||
} = this.state; | ||
const { datasource, onChange, value } = this.props; | ||
|
||
const datasourceMenu = ( | ||
<Menu onClick={this.handleMenuItemClick}> | ||
<Menu.Item key="1">{t('Change Dataset')}</Menu.Item> | ||
<Menu.Item key="2"> | ||
<a | ||
href={`/superset/sqllab?datasourceKey=${value}`} | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
> | ||
{t('Explore in SQL Lab')} | ||
</a> | ||
</Menu.Item> | ||
{this.props.isEditable && ( | ||
<Menu.Item key="3" data-test="edit-dataset"> | ||
{t('Edit Dataset')} | ||
</Menu.Item> | ||
)} | ||
</Menu> | ||
); | ||
|
||
return ( | ||
<Styles className="DatasourceControl"> | ||
<ControlHeader {...this.props} /> | ||
<div> | ||
<OverlayTrigger | ||
placement="top" | ||
overlay={ | ||
<Tooltip id="toggle-dataset-tooltip"> | ||
{t('Expand/collapse dataset configuration')} | ||
</Tooltip> | ||
} | ||
> | ||
<Tooltip title={t('Expand/collapse dataset configuration')}> | ||
<Label | ||
style={{ textTransform: 'none' }} | ||
onClick={this.toggleShowDatasource} | ||
|
@@ -199,43 +214,17 @@ class DatasourceControl extends React.PureComponent { | |
}`} | ||
/> | ||
</Label> | ||
</OverlayTrigger> | ||
<TooltipWrapper | ||
label="change-datasource" | ||
tooltip={t('More dataset related options')} | ||
trigger={['hover']} | ||
</Tooltip> | ||
<Dropdown | ||
overlay={datasourceMenu} | ||
trigger={['click']} | ||
id="datasource_menu" | ||
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. Maybe we can get rid 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. Actually there are some styles for that, in DatasourceControl.less. @kgabryje would you mind seeing if those styles are still necessary/relevant? If they are, this may be the right opportunity to bring them into the component with Emotion Theme variables wired in. One less LESS file! 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. Done, 1 less file less 🙂 |
||
data-test="datasource-menu" | ||
> | ||
<DropdownButton | ||
title={<Icon name="more-horiz" />} | ||
className="" | ||
bsSize="sm" | ||
id="datasource_menu" | ||
data-test="datasource-menu" | ||
> | ||
<MenuItem eventKey="3" onClick={this.toggleChangeDatasourceModal}> | ||
{t('Change Dataset')} | ||
</MenuItem> | ||
{datasource.type === 'table' && ( | ||
<MenuItem | ||
eventKey="3" | ||
href={`/superset/sqllab?datasourceKey=${value}`} | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
> | ||
{t('Explore in SQL Lab')} | ||
</MenuItem> | ||
)} | ||
{this.props.isEditable && ( | ||
<MenuItem | ||
data-test="edit-dataset" | ||
eventKey="3" | ||
onClick={this.toggleEditDatasourceModal} | ||
> | ||
{t('Edit Dataset')} | ||
</MenuItem> | ||
)} | ||
</DropdownButton> | ||
</TooltipWrapper> | ||
<Tooltip title={t('More dataset related options')}> | ||
<Icon data-test="datasource-menu" name="more-horiz" /> | ||
</Tooltip> | ||
</Dropdown> | ||
</div> | ||
<Collapse in={this.state.showDatasource}> | ||
{this.renderDatasource()} | ||
|
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 are already here, can you make these keys more human readable and maybe use constants?
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.
Done