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

feat: Custom filters control #17006

Merged
merged 26 commits into from
Oct 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
6eb04b1
fix:fix get permission function
simcha90 Apr 13, 2021
5e9a1d8
Merge branch 'master' of github.com:apache/superset
simcha90 Apr 18, 2021
2c5800a
Merge branch 'master' of github.com:apache/superset
simcha90 Apr 20, 2021
ea9aa8b
Merge branch 'master' of github.com:apache/superset
simcha90 Apr 25, 2021
402918a
Merge branch 'master' of github.com:apache/superset
simcha90 Apr 27, 2021
1a3cc39
Merge branch 'master' of github.com:apache/superset
simcha90 Apr 28, 2021
f6d4590
Merge branch 'master' of github.com:apache/superset
simcha90 May 10, 2021
97f2c15
Merge branch 'master' of github.com:apache/superset
simcha90 May 24, 2021
1f31df7
Merge branch 'master' of github.com:apache/superset
simcha90 May 24, 2021
dce7b7a
Merge branch 'master' of github.com:apache/superset
simcha90 May 26, 2021
0334f35
Merge branch 'master' of github.com:apache/superset
simcha90 May 30, 2021
f6dd314
Merge branch 'master' of github.com:apache/superset
simcha90 Jun 17, 2021
64267e1
Merge branch 'master' of github.com:apache/superset
simcha90 Jun 20, 2021
385eddc
Merge branch 'master' of github.com:apache/superset
simcha90 Jun 24, 2021
51a00a3
Merge branch 'master' of github.com:apache/superset
simcha90 Jul 1, 2021
4e94cb5
Merge branch 'master' of github.com:apache/superset
simcha90 Jul 4, 2021
e7fa0a6
Merge branch 'master' of github.com:apache/superset
simcha90 Jul 7, 2021
c3d24d7
Merge branch 'master' of github.com:apache/superset
simcha90 Aug 31, 2021
a3893a4
Merge branch 'master' of github.com:apache/superset
simcha90 Sep 29, 2021
30c516b
Merge branch 'master' of github.com:apache/superset
simcha90 Oct 5, 2021
03165d1
Merge branch 'master' of github.com:apache/superset
simcha90 Oct 7, 2021
4733433
feat: customize filter control
simcha90 Oct 7, 2021
b3fbb17
fix: fix types
simcha90 Oct 7, 2021
65f7ec1
fix: fix merge
simcha90 Oct 7, 2021
0593265
refactor: update according CR
simcha90 Oct 12, 2021
a3556f9
refactor: fix CR notes
simcha90 Oct 14, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ const selectedMetricType = PropTypes.oneOfType([
const propTypes = {
label: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
name: PropTypes.string,
sections: PropTypes.arrayOf(PropTypes.string),
operators: PropTypes.arrayOf(PropTypes.string),
onChange: PropTypes.func,
value: PropTypes.arrayOf(adhocFilterType),
datasource: PropTypes.object,
Expand Down Expand Up @@ -107,6 +109,8 @@ class AdhocFilterControl extends React.Component {
adhocFilter={adhocFilter}
onFilterEdit={this.onFilterEdit}
options={this.state.options}
sections={this.props.sections}
operators={this.props.operators}
datasource={this.props.datasource}
onRemoveFilter={() => this.onRemoveFilter(index)}
onMoveLabel={this.moveLabel}
Expand Down Expand Up @@ -324,6 +328,8 @@ class AdhocFilterControl extends React.Component {
addNewFilterPopoverTrigger(trigger) {
return (
<AdhocFilterPopoverTrigger
operators={this.props.operators}
sections={this.props.sections}
adhocFilter={new AdhocFilter({})}
datasource={this.props.datasource}
options={this.state.options}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ const propTypes = {
datasource: PropTypes.object,
partitionColumn: PropTypes.string,
theme: PropTypes.object,
sections: PropTypes.arrayOf(PropTypes.string),
operators: PropTypes.arrayOf(PropTypes.string),
};

const ResizeIcon = styled.i`
Expand All @@ -54,6 +56,11 @@ const ResizeIcon = styled.i`

const startingWidth = 320;
const startingHeight = 240;
const SectionWrapper = styled.div`
.ant-select {
margin-bottom: ${({ theme }) => theme.gridUnit * 4}px;
}
`;

const FilterPopoverContentContainer = styled.div`
.adhoc-filter-edit-tabs > .nav-tabs {
Expand Down Expand Up @@ -166,71 +173,90 @@ export default class AdhocFilterEditPopover extends React.Component {
onResize,
datasource,
partitionColumn,
sections = ['SIMPLE', 'CUSTOM_SQL'],
theme,
operators,
...popoverProps
} = this.props;

const { adhocFilter } = this.state;

const resultSections =
datasource?.type === 'druid'
? sections.filter(s => s !== 'CUSTOM_SQL')
: sections;

const stateIsValid = adhocFilter.isValid();
const hasUnsavedChanges = !adhocFilter.equals(propsAdhocFilter);

const sectionRenders = {};
villebro marked this conversation as resolved.
Show resolved Hide resolved

sectionRenders.CUSTOM_SQL = (
<ErrorBoundary>
<AdhocFilterEditPopoverSqlTabContent
adhocFilter={this.state.adhocFilter}
onChange={this.onAdhocFilterChange}
options={this.props.options}
height={this.state.height}
activeKey={this.state.activeKey}
/>
</ErrorBoundary>
);

sectionRenders.SIMPLE = (
<ErrorBoundary>
<AdhocFilterEditPopoverSimpleTabContent
operators={operators}
adhocFilter={this.state.adhocFilter}
onChange={this.onAdhocFilterChange}
options={options}
datasource={datasource}
onHeightChange={this.adjustHeight}
partitionColumn={partitionColumn}
popoverRef={this.popoverContentRef.current}
/>
</ErrorBoundary>
);

return (
<FilterPopoverContentContainer
id="filter-edit-popover"
{...popoverProps}
data-test="filter-edit-popover"
ref={this.popoverContentRef}
>
<Tabs
id="adhoc-filter-edit-tabs"
defaultActiveKey={adhocFilter.expressionType}
className="adhoc-filter-edit-tabs"
data-test="adhoc-filter-edit-tabs"
style={{ minHeight: this.state.height, width: this.state.width }}
allowOverflow
onChange={this.onTabChange}
>
<Tabs.TabPane
className="adhoc-filter-edit-tab"
key={EXPRESSION_TYPES.SIMPLE}
tab={t('Simple')}
>
<ErrorBoundary>
<AdhocFilterEditPopoverSimpleTabContent
adhocFilter={this.state.adhocFilter}
onChange={this.onAdhocFilterChange}
options={options}
datasource={datasource}
onHeightChange={this.adjustHeight}
partitionColumn={partitionColumn}
popoverRef={this.popoverContentRef.current}
/>
</ErrorBoundary>
</Tabs.TabPane>
<Tabs.TabPane
className="adhoc-filter-edit-tab"
key={EXPRESSION_TYPES.SQL}
tab={t('Custom SQL')}
{resultSections.length > 1 ? (
<Tabs
id="adhoc-filter-edit-tabs"
defaultActiveKey={adhocFilter.expressionType}
className="adhoc-filter-edit-tabs"
data-test="adhoc-filter-edit-tabs"
style={{ minHeight: this.state.height, width: this.state.width }}
allowOverflow
onChange={this.onTabChange}
>
<ErrorBoundary>
{!this.props.datasource ||
this.props.datasource.type !== 'druid' ? (
<AdhocFilterEditPopoverSqlTabContent
adhocFilter={this.state.adhocFilter}
onChange={this.onAdhocFilterChange}
options={this.props.options}
height={this.state.height}
activeKey={this.state.activeKey}
/>
) : (
<div className="custom-sql-disabled-message">
Custom SQL Filters are not available on druid datasources
</div>
)}
</ErrorBoundary>
</Tabs.TabPane>
</Tabs>
{resultSections.includes('SIMPLE') && (
<Tabs.TabPane
className="adhoc-filter-edit-tab"
key={EXPRESSION_TYPES.SIMPLE}
tab={t('Simple')}
>
{sectionRenders.SIMPLE}
</Tabs.TabPane>
)}
{resultSections.includes('CUSTOM_SQL') && (
<Tabs.TabPane
className="adhoc-filter-edit-tab"
key={EXPRESSION_TYPES.SQL}
tab={t('Custom SQL')}
>
{sectionRenders.CUSTOM_SQL}
</Tabs.TabPane>
)}
</Tabs>
) : (
<SectionWrapper>{sectionRenders[resultSections[0]]}</SectionWrapper>
)}
<div>
<Button buttonSize="small" onClick={this.props.onClose} cta>
{t('Close')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ import AdhocFilter, {
} from 'src/explore/components/controls/FilterControl/AdhocFilter';
import { Input } from 'src/common/components';

const StyledInput = styled(Input)`
margin-bottom: ${({ theme }) => theme.gridUnit * 4}px;
`;

const SelectWithLabel = styled(Select)<{ labelText: string }>`
.ant-select-selector::after {
content: ${({ labelText }) => labelText || '\\A0'};
display: inline-block;
white-space: nowrap;
color: ${({ theme }) => theme.colors.grayscale.light1};
width: max-content;
}
`;

export interface SimpleColumnType {
id: number;
column_name: string;
Expand Down Expand Up @@ -81,6 +95,7 @@ export interface Props {
filter_select: boolean;
};
partitionColumn: string;
operators?: Operators[];
}
export const useSimpleTabFilterProps = (props: Props) => {
const isOperatorRelevant = (operator: Operators, subject: string) => {
Expand Down Expand Up @@ -280,7 +295,9 @@ const AdhocFilterEditPopoverSimpleTabContent: React.FC<Props> = props => {
const operatorSelectProps = {
placeholder: t(
'%s operator(s)',
OPERATORS_OPTIONS.filter(op => isOperatorRelevant(op, subject)).length,
(props.operators ?? OPERATORS_OPTIONS).filter(op =>
isOperatorRelevant(op, subject),
).length,
),
value: operatorId,
onChange: onOperatorChange,
Expand Down Expand Up @@ -310,16 +327,6 @@ const AdhocFilterEditPopoverSimpleTabContent: React.FC<Props> = props => {
const labelText =
comparator && comparator.length > 0 && createSuggestionsPlaceholder();

const SelectWithLabel = styled(Select)`
.ant-select-selector::after {
content: ${() => labelText || '\\A0'};
display: inline-block;
white-space: nowrap;
color: ${({ theme }) => theme.colors.grayscale.light1};
width: max-content;
}
`;

useEffect(() => {
const refreshComparatorSuggestions = () => {
const { datasource } = props;
Expand Down Expand Up @@ -380,25 +387,26 @@ const AdhocFilterEditPopoverSimpleTabContent: React.FC<Props> = props => {
/>
<Select
css={theme => ({ marginBottom: theme.gridUnit * 4 })}
options={OPERATORS_OPTIONS.filter(op =>
isOperatorRelevant(op, subject),
).map(option => ({
value: option,
label: OPERATOR_ENUM_TO_OPERATOR_TYPE[option].display,
key: option,
}))}
options={(props.operators ?? OPERATORS_OPTIONS)
.filter(op => isOperatorRelevant(op, subject))
.map(option => ({
value: option,
label: OPERATOR_ENUM_TO_OPERATOR_TYPE[option].display,
key: option,
}))}
{...operatorSelectProps}
/>
{MULTI_OPERATORS.has(operatorId) || suggestions.length > 0 ? (
<SelectWithLabel
labelText={labelText}
options={suggestions.map((suggestion: string) => ({
value: suggestion,
label: String(suggestion),
}))}
{...comparatorSelectProps}
/>
) : (
<Input
<StyledInput
data-test="adhoc-filter-simple-value"
name="filter-value"
ref={ref => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ const propTypes = {
adhocMetricType,
]),
).isRequired,
sections: PropTypes.arrayOf(PropTypes.string),
operators: PropTypes.arrayOf(PropTypes.string),
datasource: PropTypes.object,
partitionColumn: PropTypes.string,
onMoveLabel: PropTypes.func,
Expand All @@ -53,8 +55,12 @@ const AdhocFilterOption = ({
onMoveLabel,
onDropLabel,
index,
sections,
operators,
}) => (
<AdhocFilterPopoverTrigger
sections={sections}
operators={operators}
adhocFilter={adhocFilter}
options={options}
datasource={datasource}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ import { OptionSortType } from 'src/explore/types';
import AdhocFilterEditPopover from 'src/explore/components/controls/FilterControl/AdhocFilterEditPopover';
import AdhocFilter from 'src/explore/components/controls/FilterControl/AdhocFilter';
import { ExplorePopoverContent } from 'src/explore/components/ExploreContentPopover';
import { Operators } from 'src/explore/constants';

interface AdhocFilterPopoverTriggerProps {
sections?: string[];
operators?: Operators[];
adhocFilter: AdhocFilter;
options: OptionSortType[];
datasource: Record<string, any>;
Expand Down Expand Up @@ -90,6 +93,8 @@ class AdhocFilterPopoverTrigger extends React.PureComponent<
partitionColumn={this.props.partitionColumn}
onResize={this.onPopoverResize}
onClose={closePopover}
sections={this.props.sections}
operators={this.props.operators}
onChange={this.props.onFilterEdit}
/>
</ExplorePopoverContent>
Expand Down