Skip to content

Commit

Permalink
rename a variable
Browse files Browse the repository at this point in the history
  • Loading branch information
m-ajay committed Jun 9, 2021
1 parent a37057b commit 8fa4259
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import React, { useEffect, useMemo, useState } from 'react';
import { logging, SupersetClient, t, Metric } from '@superset-ui/core';
import { ColumnMeta } from '@superset-ui/chart-controls';
import { Tooltip } from 'src/components/Tooltip';
import { Operators, OPERATOR_MAPPING } from 'src/explore/constants';
import { Operators, OPERATOR_ENUM_TO_OPERATOR_TYPE } from 'src/explore/constants';
import { OptionSortType } from 'src/explore/types';
import {
DndFilterSelectProps,
Expand Down Expand Up @@ -191,7 +191,7 @@ export const DndFilterSelect = (props: DndFilterSelectProps) => {
props.datasource.type === 'druid'
? filterOptions.saved_metric_name
: getMetricExpression(filterOptions.saved_metric_name),
operator: OPERATOR_MAPPING[Operators.GREATER_THAN].operation,
operator: OPERATOR_ENUM_TO_OPERATOR_TYPE[Operators.GREATER_THAN].operation,
operatorId: Operators.GREATER_THAN,
comparator: 0,
clause: CLAUSES.HAVING,
Expand All @@ -208,7 +208,7 @@ export const DndFilterSelect = (props: DndFilterSelectProps) => {
props.datasource.type === 'druid'
? filterOptions.label
: new AdhocMetric(option).translateToSql(),
operator: OPERATOR_MAPPING[Operators.GREATER_THAN].operation,
operator: OPERATOR_ENUM_TO_OPERATOR_TYPE[Operators.GREATER_THAN].operation,
operatorId: Operators.GREATER_THAN,
comparator: 0,
clause: CLAUSES.HAVING,
Expand All @@ -219,7 +219,7 @@ export const DndFilterSelect = (props: DndFilterSelectProps) => {
return new AdhocFilter({
expressionType: EXPRESSION_TYPES.SIMPLE,
subject: filterOptions.column_name,
operator: OPERATOR_MAPPING[Operators.EQUALS].operation,
operator: OPERATOR_ENUM_TO_OPERATOR_TYPE[Operators.EQUALS].operation,
operatorId: Operators.EQUALS,
comparator: '',
clause: CLAUSES.WHERE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import {
CUSTOM_OPERATORS,
Operators,
OPERATOR_MAPPING,
OPERATOR_ENUM_TO_OPERATOR_TYPE,
} from 'src/explore/constants';
import { getSimpleSQLExpression } from 'src/explore/exploreUtils';

Expand Down Expand Up @@ -54,7 +54,7 @@ const OPERATORS_TO_SQL = {
};

const CUSTOM_OPERATIONS = [...CUSTOM_OPERATORS].map(
op => OPERATOR_MAPPING[op].operation,
op => OPERATOR_ENUM_TO_OPERATOR_TYPE[op].operation,
);

function translateToSql(adhocMetric, { useSimple } = {}) {
Expand Down Expand Up @@ -148,10 +148,10 @@ export default class AdhocFilter {

isValid() {
const nullCheckOperators = [Operators.IS_NOT_NULL, Operators.IS_NULL].map(
op => OPERATOR_MAPPING[op].operation,
op => OPERATOR_ENUM_TO_OPERATOR_TYPE[op].operation,
);
const truthCheckOperators = [Operators.IS_TRUE, Operators.IS_FALSE].map(
op => OPERATOR_MAPPING[op].operation,
op => OPERATOR_ENUM_TO_OPERATOR_TYPE[op].operation,
);
if (this.expressionType === EXPRESSION_TYPES.SIMPLE) {
if (nullCheckOperators.indexOf(this.operator) >= 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ import AdhocFilter, {
CLAUSES,
} from 'src/explore/components/controls/FilterControl/AdhocFilter';
import { LabelsContainer } from 'src/explore/components/controls/OptionControls';
import { AGGREGATES, Operators, OPERATOR_MAPPING } from 'src/explore/constants';
import { AGGREGATES, Operators, OPERATOR_ENUM_TO_OPERATOR_TYPE } from 'src/explore/constants';
import AdhocMetric from 'src/explore/components/controls/MetricControl/AdhocMetric';
import AdhocFilterControl from '.';

const simpleAdhocFilter = new AdhocFilter({
expressionType: EXPRESSION_TYPES.SIMPLE,
subject: 'value',
operator: OPERATOR_MAPPING[Operators.GREATER_THAN].operation,
operator: OPERATOR_ENUM_TO_OPERATOR_TYPE[Operators.GREATER_THAN].operation,
comparator: '10',
clause: CLAUSES.WHERE,
});
Expand Down Expand Up @@ -92,7 +92,7 @@ describe('AdhocFilterControl', () => {
new AdhocFilter({
expressionType: EXPRESSION_TYPES.SQL,
subject: savedMetric.expression,
operator: OPERATOR_MAPPING[Operators.GREATER_THAN].operation,
operator: OPERATOR_ENUM_TO_OPERATOR_TYPE[Operators.GREATER_THAN].operation,
comparator: 0,
clause: CLAUSES.HAVING,
}),
Expand All @@ -111,7 +111,7 @@ describe('AdhocFilterControl', () => {
new AdhocFilter({
expressionType: EXPRESSION_TYPES.SQL,
subject: sumValueAdhocMetric.label,
operator: OPERATOR_MAPPING[Operators.GREATER_THAN].operation,
operator: OPERATOR_ENUM_TO_OPERATOR_TYPE[Operators.GREATER_THAN].operation,
comparator: 0,
clause: CLAUSES.HAVING,
}),
Expand All @@ -134,7 +134,7 @@ describe('AdhocFilterControl', () => {
new AdhocFilter({
expressionType: EXPRESSION_TYPES.SIMPLE,
subject: columns[0].column_name,
operator: OPERATOR_MAPPING[Operators.EQUALS].operation,
operator: OPERATOR_ENUM_TO_OPERATOR_TYPE[Operators.EQUALS].operation,
comparator: '',
clause: CLAUSES.WHERE,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import ControlHeader from 'src/explore/components/ControlHeader';
import adhocMetricType from 'src/explore/components/controls/MetricControl/adhocMetricType';
import savedMetricType from 'src/explore/components/controls/MetricControl/savedMetricType';
import AdhocMetric from 'src/explore/components/controls/MetricControl/AdhocMetric';
import { Operators, OPERATOR_MAPPING } from 'src/explore/constants';
import { Operators, OPERATOR_ENUM_TO_OPERATOR_TYPE } from 'src/explore/constants';
import FilterDefinitionOption from 'src/explore/components/controls/MetricControl/FilterDefinitionOption';
import {
AddControlLabel,
Expand Down Expand Up @@ -242,7 +242,7 @@ class AdhocFilterControl extends React.Component {
this.props.datasource.type === 'druid'
? option.saved_metric_name
: this.getMetricExpression(option.saved_metric_name),
operator: OPERATOR_MAPPING[Operators.GREATER_THAN].operation,
operator: OPERATOR_ENUM_TO_OPERATOR_TYPE[Operators.GREATER_THAN].operation,
comparator: 0,
clause: CLAUSES.HAVING,
});
Expand All @@ -258,7 +258,7 @@ class AdhocFilterControl extends React.Component {
this.props.datasource.type === 'druid'
? option.label
: new AdhocMetric(option).translateToSql(),
operator: OPERATOR_MAPPING[Operators.GREATER_THAN].operation,
operator: OPERATOR_ENUM_TO_OPERATOR_TYPE[Operators.GREATER_THAN].operation,
comparator: 0,
clause: CLAUSES.HAVING,
});
Expand All @@ -268,7 +268,7 @@ class AdhocFilterControl extends React.Component {
return new AdhocFilter({
expressionType: EXPRESSION_TYPES.SIMPLE,
subject: option.column_name,
operator: OPERATOR_MAPPING[Operators.EQUALS].operation,
operator: OPERATOR_ENUM_TO_OPERATOR_TYPE[Operators.EQUALS].operation,
comparator: '',
clause: CLAUSES.WHERE,
isNew: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import AdhocFilter, {
EXPRESSION_TYPES,
CLAUSES,
} from 'src/explore/components/controls/FilterControl/AdhocFilter';
import { AGGREGATES, Operators, OPERATOR_MAPPING } from 'src/explore/constants';
import { AGGREGATES, Operators, OPERATOR_ENUM_TO_OPERATOR_TYPE } from 'src/explore/constants';
import AdhocMetric from 'src/explore/components/controls/MetricControl/AdhocMetric';
import AdhocFilterEditPopoverSimpleTabContent, {
useSimpleTabFilterProps,
Expand All @@ -35,7 +35,7 @@ const simpleAdhocFilter = new AdhocFilter({
expressionType: EXPRESSION_TYPES.SIMPLE,
subject: 'value',
operatorId: Operators.GREATER_THAN,
operator: OPERATOR_MAPPING[Operators.GREATER_THAN].operation,
operator: OPERATOR_ENUM_TO_OPERATOR_TYPE[Operators.GREATER_THAN].operation,
comparator: '10',
clause: CLAUSES.WHERE,
});
Expand All @@ -44,7 +44,7 @@ const simpleMultiAdhocFilter = new AdhocFilter({
expressionType: EXPRESSION_TYPES.SIMPLE,
subject: 'value',
operatorId: Operators.IN,
operator: OPERATOR_MAPPING[Operators.IN].operation,
operator: OPERATOR_ENUM_TO_OPERATOR_TYPE[Operators.IN].operation,
comparator: ['10'],
clause: CLAUSES.WHERE,
});
Expand Down Expand Up @@ -310,7 +310,7 @@ describe('AdhocFilterEditPopoverSimpleTabContent', () => {
expect(props.onChange.called).toBe(true);
expect(props.onChange.lastCall.args[0].operatorId).toBe(op);
expect(props.onChange.lastCall.args[0].operator).toBe(
OPERATOR_MAPPING[op].operation,
OPERATOR_ENUM_TO_OPERATOR_TYPE[op].operation,
);
expect(props.onChange.lastCall.args[0].comparator).toBe(null);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
CUSTOM_OPERATORS,
DISABLE_INPUT_OPERATORS,
AGGREGATES,
OPERATOR_MAPPING,
OPERATOR_ENUM_TO_OPERATOR_TYPE,
} from 'src/explore/constants';
import FilterDefinitionOption from 'src/explore/components/controls/MetricControl/FilterDefinitionOption';
import AdhocFilter, {
Expand Down Expand Up @@ -159,7 +159,7 @@ export const useSimpleTabFilterProps = (props: Props) => {
clause,
operator:
operator && isOperatorRelevant(operatorId, subject)
? OPERATOR_MAPPING[operatorId].operation
? OPERATOR_ENUM_TO_OPERATOR_TYPE[operatorId].operation
: null,
expressionType: EXPRESSION_TYPES.SIMPLE,
operatorId,
Expand Down Expand Up @@ -189,7 +189,7 @@ export const useSimpleTabFilterProps = (props: Props) => {
subject: props.adhocFilter.subject,
clause: CLAUSES.WHERE,
operatorId,
operator: OPERATOR_MAPPING[operatorId].operation,
operator: OPERATOR_ENUM_TO_OPERATOR_TYPE[operatorId].operation,
expressionType: EXPRESSION_TYPES.SQL,
datasource: props.datasource,
}),
Expand All @@ -198,7 +198,7 @@ export const useSimpleTabFilterProps = (props: Props) => {
props.onChange(
props.adhocFilter.duplicateWith({
operatorId,
operator: OPERATOR_MAPPING[operatorId].operation,
operator: OPERATOR_ENUM_TO_OPERATOR_TYPE[operatorId].operation,
comparator: newComparator,
expressionType: EXPRESSION_TYPES.SIMPLE,
}),
Expand Down Expand Up @@ -332,7 +332,7 @@ const AdhocFilterEditPopoverSimpleTabContent: React.FC<Props> = props => {
'%s operator(s)',
OPERATORS_OPTIONS.filter(op => isOperatorRelevant(op, subject)).length,
),
value: OPERATOR_MAPPING[operatorId]?.display,
value: OPERATOR_ENUM_TO_OPERATOR_TYPE[operatorId]?.display,
onChange: onOperatorChange,
autoFocus: !!subjectSelectProps.value && !operator,
name: 'select-operator',
Expand Down Expand Up @@ -411,7 +411,7 @@ const AdhocFilterEditPopoverSimpleTabContent: React.FC<Props> = props => {
{OPERATORS_OPTIONS.filter(op => isOperatorRelevant(op, subject)).map(
option => (
<Select.Option value={option} key={option}>
{OPERATOR_MAPPING[option].display}
{OPERATOR_ENUM_TO_OPERATOR_TYPE[option].display}
</Select.Option>
),
)}
Expand Down
4 changes: 3 additions & 1 deletion superset-frontend/src/explore/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ export interface OperatorType {
operation: string;
}

export const OPERATOR_MAPPING: { [key in Operators]: OperatorType } = {
export const OPERATOR_ENUM_TO_OPERATOR_TYPE: {
[key in Operators]: OperatorType;
} = {
[Operators.EQUALS]: { display: 'equals', operation: '==' },
[Operators.NOT_EQUALS]: { display: 'not equals', operation: '!=' },
[Operators.GREATER_THAN]: { display: '>', operation: '>' },
Expand Down
4 changes: 2 additions & 2 deletions superset-frontend/src/explore/exploreUtils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
import { availableDomains } from 'src/utils/hostNamesConfig';
import { safeStringify } from 'src/utils/safeStringify';
import { URL_PARAMS } from 'src/constants';
import { MULTI_OPERATORS, OPERATOR_MAPPING } from 'src/explore/constants';
import { MULTI_OPERATORS, OPERATOR_ENUM_TO_OPERATOR_TYPE } from 'src/explore/constants';
import { DashboardStandaloneMode } from 'src/dashboard/util/constants';

const MAX_URL_LENGTH = 8000;
Expand Down Expand Up @@ -321,7 +321,7 @@ export const useDebouncedEffect = (effect, delay, deps) => {
export const getSimpleSQLExpression = (subject, operator, comparator) => {
const isMulti =
[...MULTI_OPERATORS]
.map(op => OPERATOR_MAPPING[op].operation)
.map(op => OPERATOR_ENUM_TO_OPERATOR_TYPE[op].operation)
.indexOf(operator) >= 0;
let expression = subject ?? '';
if (subject && operator) {
Expand Down

0 comments on commit 8fa4259

Please sign in to comment.