chore: Move styles from .less stylesheet to emotion in Explore (#14485)

* Move some styles from .less stylesheet to emotion in Explore

* Replace Global styles with local styled components

* Address comments
This commit is contained in:
Kamil Gabryjelski 2021-05-05 15:36:52 +02:00 committed by GitHub
parent 93c7f5bb44
commit b030c9801c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 197 additions and 311 deletions

View File

@ -1,42 +0,0 @@
/**
* 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.
*/
/* eslint-disable no-unused-expressions */
import React from 'react';
import { shallow } from 'enzyme';
import { AGGREGATES } from 'src/explore/constants';
import AdhocMetricStaticOption from 'src/explore/components/controls/MetricControl/AdhocMetricStaticOption';
import AdhocMetric, {
EXPRESSION_TYPES,
} from 'src/explore/components/controls/MetricControl/AdhocMetric';
const sumValueAdhocMetric = new AdhocMetric({
expressionType: EXPRESSION_TYPES.SIMPLE,
column: { type: 'VARCHAR(255)', column_name: 'source' },
aggregate: AGGREGATES.SUM,
});
describe('AdhocMetricStaticOption', () => {
it('renders the adhoc metrics label', () => {
const wrapper = shallow(
<AdhocMetricStaticOption adhocMetric={sumValueAdhocMetric} />,
);
expect(wrapper.text()).toBe('SUM(source)');
});
});

View File

@ -19,14 +19,13 @@
/* eslint-disable no-unused-expressions */ /* eslint-disable no-unused-expressions */
import React from 'react'; import React from 'react';
import { shallow } from 'enzyme'; import { shallow } from 'enzyme';
import { styledMount as mount } from 'spec/helpers/theming';
import { ColumnOption } from '@superset-ui/chart-controls';
import FilterDefinitionOption from 'src/explore/components/controls/MetricControl/FilterDefinitionOption'; import FilterDefinitionOption from 'src/explore/components/controls/MetricControl/FilterDefinitionOption';
import AdhocMetricStaticOption from 'src/explore/components/controls/MetricControl/AdhocMetricStaticOption';
import { AGGREGATES } from 'src/explore/constants'; import { AGGREGATES } from 'src/explore/constants';
import AdhocMetric, { import AdhocMetric, {
EXPRESSION_TYPES, EXPRESSION_TYPES,
} from 'src/explore/components/controls/MetricControl/AdhocMetric'; } from 'src/explore/components/controls/MetricControl/AdhocMetric';
import { StyledColumnOption } from 'src/explore/components/optionRenderers';
const sumValueAdhocMetric = new AdhocMetric({ const sumValueAdhocMetric = new AdhocMetric({
expressionType: EXPRESSION_TYPES.SIMPLE, expressionType: EXPRESSION_TYPES.SIMPLE,
@ -35,26 +34,26 @@ const sumValueAdhocMetric = new AdhocMetric({
}); });
describe('FilterDefinitionOption', () => { describe('FilterDefinitionOption', () => {
it('renders a ColumnOption given a column', () => { it('renders a StyledColumnOption given a column', () => {
const wrapper = shallow( const wrapper = shallow(
<FilterDefinitionOption option={{ column_name: 'a_column' }} />, <FilterDefinitionOption option={{ column_name: 'a_column' }} />,
); );
expect(wrapper.find(ColumnOption)).toExist(); expect(wrapper.find(StyledColumnOption)).toExist();
}); });
it('renders a AdhocMetricStaticOption given an adhoc metric', () => { it('renders a StyledColumnOption given an adhoc metric', () => {
const wrapper = shallow( const wrapper = shallow(
<FilterDefinitionOption option={sumValueAdhocMetric} />, <FilterDefinitionOption option={sumValueAdhocMetric} />,
); );
expect(wrapper.find(AdhocMetricStaticOption)).toExist(); expect(wrapper.find(StyledColumnOption)).toExist();
}); });
it('renders the metric name given a saved metric', () => { it('renders the metric name given a saved metric', () => {
const wrapper = shallow( const wrapper = mount(
<FilterDefinitionOption <FilterDefinitionOption
option={{ saved_metric_name: 'my_custom_metric' }} option={{ saved_metric_name: 'my_custom_metric' }}
/>, />,
); );
expect(wrapper.text()).toBe('<ColumnTypeLabel />my_custom_metric'); expect(wrapper.find('.option-label').text()).toBe('my_custom_metric');
}); });
}); });

View File

@ -19,10 +19,13 @@
import React from 'react'; import React from 'react';
import configureStore from 'redux-mock-store'; import configureStore from 'redux-mock-store';
import { shallow } from 'enzyme'; import { shallow } from 'enzyme';
import { ColumnOption, MetricOption } from '@superset-ui/chart-controls';
import MetricDefinitionOption from 'src/explore/components/controls/MetricControl/MetricDefinitionOption'; import MetricDefinitionOption from 'src/explore/components/controls/MetricControl/MetricDefinitionOption';
import AggregateOption from 'src/explore/components/controls/MetricControl/AggregateOption'; import AggregateOption from 'src/explore/components/controls/MetricControl/AggregateOption';
import {
StyledMetricOption,
StyledColumnOption,
} from 'src/explore/components/optionRenderers';
describe('MetricDefinitionOption', () => { describe('MetricDefinitionOption', () => {
const mockStore = configureStore([]); const mockStore = configureStore([]);
@ -32,16 +35,16 @@ describe('MetricDefinitionOption', () => {
return shallow(<MetricDefinitionOption store={store} {...props} />).dive(); return shallow(<MetricDefinitionOption store={store} {...props} />).dive();
} }
it('renders a MetricOption given a saved metric', () => { it('renders a StyledMetricOption given a saved metric', () => {
const wrapper = setup({ const wrapper = setup({
option: { metric_name: 'a_saved_metric', expression: 'COUNT(*)' }, option: { metric_name: 'a_saved_metric', expression: 'COUNT(*)' },
}); });
expect(wrapper.find(MetricOption)).toExist(); expect(wrapper.find(StyledMetricOption)).toExist();
}); });
it('renders a ColumnOption given a column', () => { it('renders a StyledColumnOption given a column', () => {
const wrapper = setup({ option: { column_name: 'a_column' } }); const wrapper = setup({ option: { column_name: 'a_column' } });
expect(wrapper.find(ColumnOption)).toExist(); expect(wrapper.find(StyledColumnOption)).toExist();
}); });
it('renders an AggregateOption given an aggregate metric', () => { it('renders an AggregateOption given an aggregate metric', () => {

View File

@ -66,8 +66,6 @@ import {
CASCADING_FILTERS, CASCADING_FILTERS,
getFiltersConfigModalTestId, getFiltersConfigModalTestId,
} from '../FiltersConfigModal'; } from '../FiltersConfigModal';
// TODO: move styles from AdhocFilterControl to emotion and delete this ./main.less
import './main.less';
const StyledContainer = styled.div` const StyledContainer = styled.div`
display: flex; display: flex;

View File

@ -1,86 +0,0 @@
/**
* 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 '../../../../../../stylesheets/less/variables.less';
.option-label {
display: inline-block;
& ~ i {
margin-left: 4px;
}
}
.type-label {
margin-right: 8px;
width: 30px;
display: inline-block;
text-align: center;
font-weight: @font-weight-bold;
}
.adhoc-filter-edit-tabs > .nav-tabs {
margin-bottom: 8px;
& > li > a {
padding: 4px;
}
}
.edit-popover-resize {
transform: scaleX(-1);
-moz-transform: scaleX(-1);
-webkit-transform: scaleX(-1);
-ms-transform: scaleX(-1);
float: right;
margin-top: 18px;
margin-right: -10px;
cursor: nwse-resize;
}
#filter-edit-popover {
max-width: none;
}
.filter-edit-clause-dropdown {
width: 120px;
margin-right: 5px;
}
.filter-edit-clause-info {
font-size: @font-size-xs;
padding-left: 5px;
}
.filter-edit-clause-section {
display: inline-flex;
}
.adhoc-filter-sql-editor {
border: @gray-light solid thin;
}
.adhoc-filter-simple-column-dropdown {
margin-top: 20px;
}
.custom-sql-disabled-message {
color: @gray;
font-size: @font-size-xs;
text-align: center;
margin-top: 60px;
}

View File

@ -19,12 +19,7 @@
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react';
import { styled, t } from '@superset-ui/core'; import { styled, t } from '@superset-ui/core';
import Collapse from 'src/components/Collapse'; import Collapse from 'src/components/Collapse';
import { import { ControlConfig, DatasourceMeta } from '@superset-ui/chart-controls';
ColumnOption,
MetricOption,
ControlConfig,
DatasourceMeta,
} from '@superset-ui/chart-controls';
import { debounce } from 'lodash'; import { debounce } from 'lodash';
import { matchSorter, rankings } from 'match-sorter'; import { matchSorter, rankings } from 'match-sorter';
import { FAST_DEBOUNCE } from 'src/constants'; import { FAST_DEBOUNCE } from 'src/constants';
@ -33,6 +28,7 @@ import { ExploreActions } from 'src/explore/actions/exploreActions';
import Control from 'src/explore/components/Control'; import Control from 'src/explore/components/Control';
import DatasourcePanelDragWrapper from './DatasourcePanelDragWrapper'; import DatasourcePanelDragWrapper from './DatasourcePanelDragWrapper';
import { DndItemType } from '../DndItemType'; import { DndItemType } from '../DndItemType';
import { StyledColumnOption, StyledMetricOption } from '../optionRenderers';
interface DatasourceControl extends ControlConfig { interface DatasourceControl extends ControlConfig {
datasource?: DatasourceMeta; datasource?: DatasourceMeta;
@ -216,10 +212,10 @@ export default function DataSourcePanel({
value={m} value={m}
type={DndItemType.Metric} type={DndItemType.Metric}
> >
<MetricOption metric={m} showType /> <StyledMetricOption metric={m} showType />
</DatasourcePanelDragWrapper> </DatasourcePanelDragWrapper>
) : ( ) : (
<MetricOption metric={m} showType /> <StyledMetricOption metric={m} showType />
)} )}
</LabelContainer> </LabelContainer>
))} ))}
@ -238,10 +234,10 @@ export default function DataSourcePanel({
value={col} value={col}
type={DndItemType.Column} type={DndItemType.Column}
> >
<ColumnOption column={col} showType /> <StyledColumnOption column={col} showType />
</DatasourcePanelDragWrapper> </DatasourcePanelDragWrapper>
) : ( ) : (
<ColumnOption column={col} showType /> <StyledColumnOption column={col} showType />
)} )}
</LabelContainer> </LabelContainer>
))} ))}

View File

@ -16,26 +16,23 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
import React from 'react'; import { styled } from '@superset-ui/core';
import PropTypes from 'prop-types';
import { ColumnTypeLabel } from '@superset-ui/chart-controls';
import adhocMetricType from './adhocMetricType'; export const ExplorePopoverContent = styled.div`
.edit-popover-resize {
const propTypes = { transform: scaleX(-1);
adhocMetric: adhocMetricType, float: right;
showType: PropTypes.bool, margin-top: ${({ theme }) => theme.gridUnit * 4}px;
}; margin-right: ${({ theme }) => theme.gridUnit * -2}px;
cursor: nwse-resize;
export default function AdhocMetricStaticOption({ }
adhocMetric, .filter-sql-editor {
showType = false, border: ${({ theme }) => theme.colors.grayscale.light2} solid thin;
}) { }
return ( .custom-sql-disabled-message {
<div> color: ${({ theme }) => theme.colors.grayscale.light1};
{showType && <ColumnTypeLabel type="expression" />} font-size: ${({ theme }) => theme.typography.sizes.xs}px;
<span className="option-label">{adhocMetric.label}</span> text-align: center;
</div> margin-top: ${({ theme }) => theme.gridUnit * 15}px;
); }
} `;
AdhocMetricStaticOption.propTypes = propTypes;

View File

@ -17,7 +17,7 @@
* under the License. * under the License.
*/ */
import React, { useState } from 'react'; import React, { useState } from 'react';
import { ColumnMeta, ColumnOption } from '@superset-ui/chart-controls'; import { ColumnMeta } from '@superset-ui/chart-controls';
import { isEmpty } from 'lodash'; import { isEmpty } from 'lodash';
import { LabelProps } from 'src/explore/components/controls/DndColumnSelectControl/types'; import { LabelProps } from 'src/explore/components/controls/DndColumnSelectControl/types';
import DndSelectLabel from 'src/explore/components/controls/DndColumnSelectControl/DndSelectLabel'; import DndSelectLabel from 'src/explore/components/controls/DndColumnSelectControl/DndSelectLabel';
@ -25,6 +25,7 @@ import OptionWrapper from 'src/explore/components/controls/DndColumnSelectContro
import { OptionSelector } from 'src/explore/components/controls/DndColumnSelectControl/utils'; import { OptionSelector } from 'src/explore/components/controls/DndColumnSelectControl/utils';
import { DatasourcePanelDndItem } from 'src/explore/components/DatasourcePanel/types'; import { DatasourcePanelDndItem } from 'src/explore/components/DatasourcePanel/types';
import { DndItemType } from 'src/explore/components/DndItemType'; import { DndItemType } from 'src/explore/components/DndItemType';
import { StyledColumnOption } from 'src/explore/components/optionRenderers';
export const DndColumnSelect = (props: LabelProps) => { export const DndColumnSelect = (props: LabelProps) => {
const { value, options } = props; const { value, options } = props;
@ -66,7 +67,7 @@ export const DndColumnSelect = (props: LabelProps) => {
onShiftOptions={onShiftOptions} onShiftOptions={onShiftOptions}
type={DndItemType.ColumnOption} type={DndItemType.ColumnOption}
> >
<ColumnOption column={column} showType /> <StyledColumnOption column={column} showType />
</OptionWrapper> </OptionWrapper>
)); ));

View File

@ -55,6 +55,38 @@ const ResizeIcon = styled.i`
const startingWidth = 320; const startingWidth = 320;
const startingHeight = 240; const startingHeight = 240;
const FilterPopoverContentContainer = styled.div`
.adhoc-filter-edit-tabs > .nav-tabs {
margin-bottom: ${({ theme }) => theme.gridUnit * 2}px;
& > li > a {
padding: ${({ theme }) => theme.gridUnit}px;
}
}
#filter-edit-popover {
max-width: none;
}
.filter-edit-clause-dropdown {
width: ${({ theme }) => theme.gridUnit * 30}px;
margin-right: ${({ theme }) => theme.gridUnit}px;
}
.filter-edit-clause-info {
font-size: ${({ theme }) => theme.typography.sizes.xs}px;
padding-left: ${({ theme }) => theme.gridUnit}px;
}
.filter-edit-clause-section {
display: inline-flex;
}
.adhoc-filter-simple-column-dropdown {
margin-top: ${({ theme }) => theme.gridUnit * 5}px;
}
`;
export default class AdhocFilterEditPopover extends React.Component { export default class AdhocFilterEditPopover extends React.Component {
constructor(props) { constructor(props) {
super(props); super(props);
@ -149,7 +181,7 @@ export default class AdhocFilterEditPopover extends React.Component {
const hasUnsavedChanges = !adhocFilter.equals(propsAdhocFilter); const hasUnsavedChanges = !adhocFilter.equals(propsAdhocFilter);
return ( return (
<div <FilterPopoverContentContainer
id="filter-edit-popover" id="filter-edit-popover"
{...popoverProps} {...popoverProps}
data-test="filter-edit-popover" data-test="filter-edit-popover"
@ -229,7 +261,7 @@ export default class AdhocFilterEditPopover extends React.Component {
className="fa fa-expand edit-popover-resize text-muted" className="fa fa-expand edit-popover-resize text-muted"
/> />
</div> </div>
</div> </FilterPopoverContentContainer>
); );
} }
} }

View File

@ -145,7 +145,7 @@ export default class AdhocFilterEditPopoverSqlTabContent extends React.Component
value={adhocFilter.sqlExpression || adhocFilter.translateToSql()} value={adhocFilter.sqlExpression || adhocFilter.translateToSql()}
editorProps={{ $blockScrolling: true }} editorProps={{ $blockScrolling: true }}
enableLiveAutocompletion enableLiveAutocompletion
className="adhoc-filter-sql-editor" className="filter-sql-editor"
wrapEnabled wrapEnabled
/> />
</FormGroup> </FormGroup>

View File

@ -21,6 +21,7 @@ import Popover from 'src/components/Popover';
import { OptionSortType } from 'src/explore/types'; import { OptionSortType } from 'src/explore/types';
import AdhocFilterEditPopover from 'src/explore/components/controls/FilterControl/AdhocFilterEditPopover'; import AdhocFilterEditPopover from 'src/explore/components/controls/FilterControl/AdhocFilterEditPopover';
import AdhocFilter from 'src/explore/components/controls/FilterControl/AdhocFilter'; import AdhocFilter from 'src/explore/components/controls/FilterControl/AdhocFilter';
import { ExplorePopoverContent } from 'src/explore/components/ExploreContentPopover';
interface AdhocFilterPopoverTriggerProps { interface AdhocFilterPopoverTriggerProps {
adhocFilter: AdhocFilter; adhocFilter: AdhocFilter;
@ -82,15 +83,17 @@ class AdhocFilterPopoverTrigger extends React.PureComponent<
closePopover: this.closePopover, closePopover: this.closePopover,
}; };
const overlayContent = ( const overlayContent = (
<AdhocFilterEditPopover <ExplorePopoverContent>
adhocFilter={adhocFilter} <AdhocFilterEditPopover
options={this.props.options} adhocFilter={adhocFilter}
datasource={this.props.datasource} options={this.props.options}
partitionColumn={this.props.partitionColumn} datasource={this.props.datasource}
onResize={this.onPopoverResize} partitionColumn={this.props.partitionColumn}
onClose={closePopover} onResize={this.onPopoverResize}
onChange={this.props.onFilterEdit} onClose={closePopover}
/> onChange={this.props.onFilterEdit}
/>
</ExplorePopoverContent>
); );
return ( return (

View File

@ -23,8 +23,7 @@ import { FormGroup } from 'react-bootstrap';
import Tabs from 'src/components/Tabs'; import Tabs from 'src/components/Tabs';
import Button from 'src/components/Button'; import Button from 'src/components/Button';
import { NativeSelect as Select } from 'src/components/Select'; import { NativeSelect as Select } from 'src/components/Select';
import { styled, t } from '@superset-ui/core'; import { t } from '@superset-ui/core';
import { ColumnOption, MetricOption } from '@superset-ui/chart-controls';
import FormLabel from 'src/components/FormLabel'; import FormLabel from 'src/components/FormLabel';
import { SQLEditor } from 'src/components/AsyncAceEditor'; import { SQLEditor } from 'src/components/AsyncAceEditor';
@ -37,6 +36,10 @@ import savedMetricType from 'src/explore/components/controls/MetricControl/saved
import AdhocMetric, { import AdhocMetric, {
EXPRESSION_TYPES, EXPRESSION_TYPES,
} from 'src/explore/components/controls/MetricControl/AdhocMetric'; } from 'src/explore/components/controls/MetricControl/AdhocMetric';
import {
StyledMetricOption,
StyledColumnOption,
} from 'src/explore/components/optionRenderers';
const propTypes = { const propTypes = {
onChange: PropTypes.func.isRequired, onChange: PropTypes.func.isRequired,
@ -56,16 +59,6 @@ const defaultProps = {
getCurrentTab: noOp, getCurrentTab: noOp,
}; };
const ResizeIcon = styled.i`
margin-left: ${({ theme }) => theme.gridUnit * 2}px;
`;
const ColumnOptionStyle = styled.span`
.option-label {
display: inline;
}
`;
export const SAVED_TAB_KEY = 'SAVED'; export const SAVED_TAB_KEY = 'SAVED';
const startingWidth = 320; const startingWidth = 320;
@ -255,11 +248,7 @@ export default class AdhocMetricEditPopover extends React.PureComponent {
if (column.metric_name && !column.verbose_name) { if (column.metric_name && !column.verbose_name) {
column.verbose_name = column.metric_name; column.verbose_name = column.metric_name;
} }
return ( return <StyledColumnOption column={column} showType />;
<ColumnOptionStyle>
<ColumnOption column={column} showType />
</ColumnOptionStyle>
);
} }
render() { render() {
@ -369,7 +358,7 @@ export default class AdhocMetricEditPopover extends React.PureComponent {
} }
key={savedMetric.id} key={savedMetric.id}
> >
<MetricOption metric={savedMetric} showType /> <StyledMetricOption metric={savedMetric} showType />
</Select.Option> </Select.Option>
))} ))}
</Select> </Select>
@ -433,7 +422,7 @@ export default class AdhocMetricEditPopover extends React.PureComponent {
} }
editorProps={{ $blockScrolling: true }} editorProps={{ $blockScrolling: true }}
enableLiveAutocompletion enableLiveAutocompletion
className="adhoc-filter-sql-editor" className="filter-sql-editor"
wrapEnabled wrapEnabled
/> />
</FormGroup> </FormGroup>
@ -465,7 +454,7 @@ export default class AdhocMetricEditPopover extends React.PureComponent {
> >
{t('Save')} {t('Save')}
</Button> </Button>
<ResizeIcon <i
role="button" role="button"
aria-label="Resize" aria-label="Resize"
tabIndex={0} tabIndex={0}

View File

@ -20,6 +20,7 @@ import React, { ReactNode } from 'react';
import { Metric } from '@superset-ui/core'; import { Metric } from '@superset-ui/core';
import Popover from 'src/components/Popover'; import Popover from 'src/components/Popover';
import AdhocMetricEditPopoverTitle from 'src/explore/components/controls/MetricControl/AdhocMetricEditPopoverTitle'; import AdhocMetricEditPopoverTitle from 'src/explore/components/controls/MetricControl/AdhocMetricEditPopoverTitle';
import { ExplorePopoverContent } from 'src/explore/components/ExploreContentPopover';
import AdhocMetricEditPopover, { import AdhocMetricEditPopover, {
SAVED_TAB_KEY, SAVED_TAB_KEY,
} from './AdhocMetricEditPopover'; } from './AdhocMetricEditPopover';
@ -176,19 +177,21 @@ class AdhocMetricPopoverTrigger extends React.PureComponent<
}; };
const overlayContent = ( const overlayContent = (
<AdhocMetricEditPopover <ExplorePopoverContent>
adhocMetric={adhocMetric} <AdhocMetricEditPopover
title={title} adhocMetric={adhocMetric}
columns={columns} title={title}
savedMetricsOptions={savedMetricsOptions} columns={columns}
savedMetric={savedMetric} savedMetricsOptions={savedMetricsOptions}
datasourceType={datasourceType} savedMetric={savedMetric}
onResize={this.onPopoverResize} datasourceType={datasourceType}
onClose={closePopover} onResize={this.onPopoverResize}
onChange={this.onChange} onClose={closePopover}
getCurrentTab={this.getCurrentTab} onChange={this.onChange}
getCurrentLabel={this.getCurrentLabel} getCurrentTab={this.getCurrentTab}
/> getCurrentLabel={this.getCurrentLabel}
/>
</ExplorePopoverContent>
); );
const popoverTitle = ( const popoverTitle = (

View File

@ -18,11 +18,10 @@
*/ */
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { ColumnOption, ColumnTypeLabel } from '@superset-ui/chart-controls';
import columnType from './columnType'; import columnType from './columnType';
import AdhocMetricStaticOption from './AdhocMetricStaticOption';
import adhocMetricType from './adhocMetricType'; import adhocMetricType from './adhocMetricType';
import { StyledColumnOption } from '../../optionRenderers';
const propTypes = { const propTypes = {
option: PropTypes.oneOfType([ option: PropTypes.oneOfType([
@ -35,17 +34,22 @@ const propTypes = {
export default function FilterDefinitionOption({ option }) { export default function FilterDefinitionOption({ option }) {
if (option.saved_metric_name) { if (option.saved_metric_name) {
return ( return (
<div> <StyledColumnOption
<ColumnTypeLabel type="expression" /> column={{ column_name: option.saved_metric_name, type: 'expression' }}
<span className="option-label">{option.saved_metric_name}</span> showType
</div> />
); );
} }
if (option.column_name) { if (option.column_name) {
return <ColumnOption column={option} showType />; return <StyledColumnOption column={option} showType />;
} }
if (option.label) { if (option.label) {
return <AdhocMetricStaticOption adhocMetric={option} showType />; return (
<StyledColumnOption
column={{ column_name: option.label, type: 'expression' }}
showType
/>
);
} }
} }
FilterDefinitionOption.propTypes = propTypes; FilterDefinitionOption.propTypes = propTypes;

View File

@ -18,9 +18,12 @@
*/ */
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { ColumnOption, MetricOption } from '@superset-ui/chart-controls';
import withToasts from 'src/messageToasts/enhancers/withToasts'; import withToasts from 'src/messageToasts/enhancers/withToasts';
import {
StyledColumnOption,
StyledMetricOption,
} from 'src/explore/components/optionRenderers';
import AggregateOption from './AggregateOption'; import AggregateOption from './AggregateOption';
import columnType from './columnType'; import columnType from './columnType';
import aggregateOptionType from './aggregateOptionType'; import aggregateOptionType from './aggregateOptionType';
@ -37,10 +40,10 @@ const propTypes = {
function MetricDefinitionOption({ option, addWarningToast }) { function MetricDefinitionOption({ option, addWarningToast }) {
if (option.metric_name) { if (option.metric_name) {
return <MetricOption metric={option} showType />; return <StyledMetricOption metric={option} showType />;
} }
if (option.column_name) { if (option.column_name) {
return <ColumnOption column={option} showType />; return <StyledColumnOption column={option} showType />;
} }
if (option.aggregate_name) { if (option.aggregate_name) {
return <AggregateOption aggregate={option} showType />; return <AggregateOption aggregate={option} showType />;

View File

@ -19,14 +19,12 @@
import React, { useRef } from 'react'; import React, { useRef } from 'react';
import { useDrag, useDrop, DropTargetMonitor } from 'react-dnd'; import { useDrag, useDrop, DropTargetMonitor } from 'react-dnd';
import { styled, t, useTheme } from '@superset-ui/core'; import { styled, t, useTheme } from '@superset-ui/core';
import { import { InfoTooltipWithTrigger } from '@superset-ui/chart-controls';
MetricOption,
InfoTooltipWithTrigger,
} from '@superset-ui/chart-controls';
import { Tooltip } from 'src/components/Tooltip'; import { Tooltip } from 'src/components/Tooltip';
import Icon from 'src/components/Icon'; import Icon from 'src/components/Icon';
import { savedMetricType } from 'src/explore/components/controls/MetricControl/types'; import { savedMetricType } from 'src/explore/components/controls/MetricControl/types';
import AdhocMetric from 'src/explore/components/controls/MetricControl/AdhocMetric'; import AdhocMetric from 'src/explore/components/controls/MetricControl/AdhocMetric';
import { StyledMetricOption } from '../../optionRenderers';
export const DragContainer = styled.div` export const DragContainer = styled.div`
margin-bottom: ${({ theme }) => theme.gridUnit}px; margin-bottom: ${({ theme }) => theme.gridUnit}px;
@ -246,7 +244,7 @@ export const OptionControlLabel = ({
const getLabelContent = () => { const getLabelContent = () => {
if (savedMetric?.metric_name) { if (savedMetric?.metric_name) {
return <MetricOption metric={savedMetric} />; return <StyledMetricOption metric={savedMetric} />;
} }
return <Tooltip title={label}>{label}</Tooltip>; return <Tooltip title={label}>{label}</Tooltip>;
}; };

View File

@ -0,0 +1,55 @@
/**
* 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 { styled } from '@superset-ui/core';
import {
MetricOption,
ColumnOption,
MetricOptionProps,
ColumnOptionProps,
} from '@superset-ui/chart-controls';
const OptionContainer = styled.div`
.option-label {
display: inline-block;
& ~ i {
margin-left: ${({ theme }) => theme.gridUnit}px;
}
}
.type-label {
margin-right: ${({ theme }) => theme.gridUnit * 2}px;
width: ${({ theme }) => theme.gridUnit * 7}px;
display: inline-block;
text-align: center;
font-weight: ${({ theme }) => theme.typography.weights.bold};
}
`;
export const StyledMetricOption = (props: MetricOptionProps) => (
<OptionContainer>
<MetricOption {...props} />
</OptionContainer>
);
export const StyledColumnOption = (props: ColumnOptionProps) => (
<OptionContainer>
<ColumnOption {...props} />
</OptionContainer>
);

View File

@ -64,9 +64,9 @@ import {
legacyValidateInteger, legacyValidateInteger,
validateNonEmpty, validateNonEmpty,
} from '@superset-ui/core'; } from '@superset-ui/core';
import { ColumnOption } from '@superset-ui/chart-controls';
import { formatSelectOptions, mainMetric } from 'src/modules/utils'; import { formatSelectOptions, mainMetric } from 'src/modules/utils';
import { TIME_FILTER_LABELS } from './constants'; import { TIME_FILTER_LABELS } from './constants';
import { StyledColumnOption } from './components/optionRenderers';
const categoricalSchemeRegistry = getCategoricalSchemeRegistry(); const categoricalSchemeRegistry = getCategoricalSchemeRegistry();
const sequentialSchemeRegistry = getSequentialSchemeRegistry(); const sequentialSchemeRegistry = getSequentialSchemeRegistry();
@ -124,8 +124,8 @@ const groupByControl = {
default: [], default: [],
includeTime: false, includeTime: false,
description: t('One or many controls to group by'), description: t('One or many controls to group by'),
optionRenderer: c => <ColumnOption column={c} showType />, optionRenderer: c => <StyledColumnOption column={c} showType />,
valueRenderer: c => <ColumnOption column={c} />, valueRenderer: c => <StyledColumnOption column={c} />,
valueKey: 'column_name', valueKey: 'column_name',
allowAll: true, allowAll: true,
filterOption: ({ data: opt }, text) => filterOption: ({ data: opt }, text) =>
@ -308,8 +308,8 @@ export const controls = {
'expression', 'expression',
), ),
clearable: false, clearable: false,
optionRenderer: c => <ColumnOption column={c} showType />, optionRenderer: c => <StyledColumnOption column={c} showType />,
valueRenderer: c => <ColumnOption column={c} />, valueRenderer: c => <StyledColumnOption column={c} />,
valueKey: 'column_name', valueKey: 'column_name',
mapStateToProps: state => { mapStateToProps: state => {
const props = {}; const props = {};

View File

@ -97,21 +97,6 @@
margin-left: 3px; margin-left: 3px;
} }
.option-label {
display: inline-block;
& ~ i {
margin-left: 4px;
}
}
.type-label {
margin-right: 8px;
width: 30px;
display: inline-block;
text-align: center;
font-weight: @font-weight-bold;
}
.datasource-container { .datasource-container {
overflow: auto; overflow: auto;
} }
@ -124,25 +109,6 @@
} }
} }
.adhoc-filter-edit-tabs > .nav-tabs {
margin-bottom: 8px;
& > li > a {
padding: 4px;
}
}
.edit-popover-resize {
transform: scaleX(-1);
-moz-transform: scaleX(-1);
-webkit-transform: scaleX(-1);
-ms-transform: scaleX(-1);
float: right;
margin-top: 18px;
margin-right: -10px;
cursor: nwse-resize;
}
#metrics-edit-popover { #metrics-edit-popover {
max-width: none; max-width: none;
@ -151,32 +117,10 @@
} }
} }
#filter-edit-popover {
max-width: none;
}
.filter-edit-clause-dropdown {
width: 120px;
margin-right: 5px;
}
.filter-edit-clause-info {
font-size: @font-size-xs;
padding-left: 5px;
}
.filter-edit-clause-section {
display: inline-flex;
}
.adhoc-option { .adhoc-option {
cursor: pointer; cursor: pointer;
} }
.adhoc-filter-sql-editor {
border: @gray-light solid thin;
}
.label-dropdown ul.dropdown-menu { .label-dropdown ul.dropdown-menu {
position: fixed; position: fixed;
top: auto; top: auto;
@ -193,10 +137,6 @@
cursor: pointer; cursor: pointer;
} }
.adhoc-filter-simple-column-dropdown {
margin-top: 20px;
}
.adhoc-label-arrow { .adhoc-label-arrow {
font-size: @font-size-s; font-size: @font-size-s;
margin-left: 3px; margin-left: 3px;
@ -211,13 +151,6 @@
} }
} }
.custom-sql-disabled-message {
color: @gray;
font-size: @font-size-xs;
text-align: center;
margin-top: 60px;
}
h1.section-header { h1.section-header {
font-size: @font-size-m; font-size: @font-size-m;
font-weight: @font-weight-bold; font-weight: @font-weight-bold;