Skip to content
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

chore: Remove FilterBox.less #19462

Merged
merged 4 commits into from
Apr 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
93 changes: 72 additions & 21 deletions superset-frontend/src/visualizations/FilterBox/FilterBox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,15 @@ import { debounce } from 'lodash';
import { max as d3Max } from 'd3-array';
import { AsyncCreatableSelect, CreatableSelect } from 'src/components/Select';
import Button from 'src/components/Button';
import { t, SupersetClient, ensureIsArray } from '@superset-ui/core';
import {
css,
styled,
t,
SupersetClient,
ensureIsArray,
withTheme,
} from '@superset-ui/core';
import { Global } from '@emotion/react';

import {
BOOL_FALSE_DISPLAY,
Expand All @@ -43,8 +51,6 @@ import {
TIME_FILTER_MAP,
} from 'src/explore/constants';

import './FilterBox.less';

// a shortcut to a map key, used by many components
export const TIME_RANGE = TIME_FILTER_MAP.time_range;

Expand Down Expand Up @@ -91,6 +97,32 @@ const defaultProps = {
instantFiltering: false,
};

const StyledFilterContainer = styled.div`
${({ theme }) => `
display: flex;
flex-direction: column;
margin-bottom: ${theme.gridUnit * 2 + 2}px;

&:last-child {
margin-bottom: 0;
}

label {
display: flex;
font-weight: ${theme.typography.weights.bold};
}

.filter-badge-container {
width: 30px;
padding-right: ${theme.gridUnit * 2 + 2}px;
}

.filter-badge-container + div {
width: 100%;
}
`}
`;

class FilterBox extends React.PureComponent {
constructor(props) {
super(props);
Expand Down Expand Up @@ -409,37 +441,56 @@ class FilterBox extends React.PureComponent {
return filtersFields.map(filterConfig => {
const { label, key } = filterConfig;
return (
<div key={key} className="m-b-5 filter-container">
<StyledFilterContainer key={key} className="filter-container">
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This className is used by other less files. We should probably remove it once all the less files have been removed from the codebase

<FormLabel htmlFor={`LABEL-${key}`}>{label}</FormLabel>
{this.renderSelect(filterConfig)}
</div>
</StyledFilterContainer>
);
});
}

render() {
const { instantFiltering, width, height } = this.props;
const { zIndex, gridUnit } = this.props.theme;
return (
<div style={{ width, height, overflow: 'auto' }}>
{this.renderDateFilter()}
{this.renderDatasourceFilters()}
{this.renderFilters()}
{!instantFiltering && (
<Button
buttonSize="small"
buttonStyle="primary"
onClick={this.clickApply.bind(this)}
disabled={!this.state.hasChanged}
>
{t('Apply')}
</Button>
)}
</div>
<>
<Global
styles={css`
.dashboard .filter_box .slice_container > div:not(.alert) {
padding-top: 0;
}

.filter_box {
padding: ${gridUnit * 2 + 2}px 0;
overflow: visible !important;

&:hover {
z-index: ${zIndex.max};
}
}
`}
/>
<div style={{ width, height, overflow: 'auto' }}>
{this.renderDateFilter()}
{this.renderDatasourceFilters()}
{this.renderFilters()}
{!instantFiltering && (
<Button
buttonSize="small"
buttonStyle="primary"
onClick={this.clickApply.bind(this)}
disabled={!this.state.hasChanged}
>
{t('Apply')}
</Button>
)}
</div>
</>
);
}
}

FilterBox.propTypes = propTypes;
FilterBox.defaultProps = defaultProps;

export default FilterBox;
export default withTheme(FilterBox);
78 changes: 0 additions & 78 deletions superset-frontend/src/visualizations/FilterBox/FilterBox.less

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@
* under the License.
*/
import React from 'react';
import { shallow } from 'enzyme';
import { styledMount as mount } from 'spec/helpers/theming';
import FilterBox from 'src/visualizations/FilterBox/FilterBox';
import SelectControl from 'src/explore/components/controls/SelectControl';

describe('FilterBox', () => {
it('should only add defined non-predefined options to filtersChoices', () => {
const wrapper = shallow(
const wrapper = mount(
<FilterBox
chartId={1001}
datasource={{ id: 1 }}
Expand All @@ -48,7 +47,7 @@ describe('FilterBox', () => {
origSelectedValues={{}}
/>,
);
const inst = wrapper.instance();
const inst = wrapper.find('FilterBox').instance();
// choose a predefined value
inst.setState({ selectedValues: { name: ['John'] } });
expect(inst.props.filtersChoices.name.length).toEqual(2);
Expand Down