From eebc953dd599ed13a4893e9c9c726bddb19f7666 Mon Sep 17 00:00:00 2001 From: simcha90 <56388545+simcha90@users.noreply.github.com> Date: Fri, 15 Oct 2021 14:14:04 +0300 Subject: [PATCH] feat: Custom filters control (#17006) * fix:fix get permission function * feat: customize filter control * fix: fix types * fix: fix merge * refactor: update according CR * refactor: fix CR notes --- .../AdhocFilterControl/index.jsx | 6 + .../AdhocFilterEditPopover/index.jsx | 122 +++++++++++------- .../index.tsx | 46 ++++--- .../FilterControl/AdhocFilterOption/index.jsx | 6 + .../AdhocFilterPopoverTrigger/index.tsx | 5 + 5 files changed, 118 insertions(+), 67 deletions(-) diff --git a/superset-frontend/src/explore/components/controls/FilterControl/AdhocFilterControl/index.jsx b/superset-frontend/src/explore/components/controls/FilterControl/AdhocFilterControl/index.jsx index 414745467e57..44f04b1b4522 100644 --- a/superset-frontend/src/explore/components/controls/FilterControl/AdhocFilterControl/index.jsx +++ b/superset-frontend/src/explore/components/controls/FilterControl/AdhocFilterControl/index.jsx @@ -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, @@ -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} @@ -324,6 +328,8 @@ class AdhocFilterControl extends React.Component { addNewFilterPopoverTrigger(trigger) { return ( theme.gridUnit * 4}px; + } +`; const FilterPopoverContentContainer = styled.div` .adhoc-filter-edit-tabs > .nav-tabs { @@ -166,15 +173,51 @@ 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 = {}; + + sectionRenders.CUSTOM_SQL = ( + + + + ); + + sectionRenders.SIMPLE = ( + + + + ); + return ( - - - - - - - 1 ? ( + - - {!this.props.datasource || - this.props.datasource.type !== 'druid' ? ( - - ) : ( -
- Custom SQL Filters are not available on druid datasources -
- )} -
-
-
+ {resultSections.includes('SIMPLE') && ( + + {sectionRenders.SIMPLE} + + )} + {resultSections.includes('CUSTOM_SQL') && ( + + {sectionRenders.CUSTOM_SQL} + + )} + + ) : ( + {sectionRenders[resultSections[0]]} + )}