Skip to content

Commit

Permalink
chore: make TS enums strictly PascalCase (apache#26875)
Browse files Browse the repository at this point in the history
  • Loading branch information
villebro authored Feb 1, 2024
1 parent 0db3374 commit 020bffe
Show file tree
Hide file tree
Showing 362 changed files with 2,001 additions and 2,031 deletions.
11 changes: 11 additions & 0 deletions superset-frontend/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,17 @@ module.exports = {
'@typescript-eslint/ban-ts-ignore': 0,
'@typescript-eslint/ban-ts-comment': 0, // disabled temporarily
'@typescript-eslint/ban-types': 0, // disabled temporarily
'@typescript-eslint/naming-convention': [
'error',
{
selector: 'enum',
format: ['PascalCase'],
},
{
selector: 'enumMember',
format: ['PascalCase'],
},
],
'@typescript-eslint/no-empty-function': 0,
'@typescript-eslint/no-explicit-any': 0,
'@typescript-eslint/no-use-before-define': 1, // disabled temporarily
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ export function ColumnTypeLabel({ type }: ColumnTypeLabelProps) {

if (type === '' || type === 'expression') {
typeIcon = <FunctionSvg aria-label={t('function type icon')} />;
} else if (type === GenericDataType.STRING) {
} else if (type === GenericDataType.String) {
typeIcon = <StringSvg aria-label={t('string type icon')} />;
} else if (type === GenericDataType.NUMERIC) {
} else if (type === GenericDataType.Numeric) {
typeIcon = <NumSvg aria-label={t('numeric type icon')} />;
} else if (type === GenericDataType.BOOLEAN) {
} else if (type === GenericDataType.Boolean) {
typeIcon = <BooleanSvg aria-label={t('boolean type icon')} />;
} else if (type === GenericDataType.TEMPORAL) {
} else if (type === GenericDataType.Temporal) {
typeIcon = <ClockCircleOutlined aria-label={t('temporal type icon')} />;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const DATASET_TIME_COLUMN_OPTION: ColumnMeta = {
verbose_name: COLUMN_NAME_ALIASES[DTTM_ALIAS],
column_name: DTTM_ALIAS,
type: 'TIMESTAMP',
type_generic: GenericDataType.TEMPORAL,
type_generic: GenericDataType.Temporal,
description: t(
'A reference to the [Time] configuration, taking granularity into account',
),
Expand All @@ -53,12 +53,12 @@ export const QUERY_TIME_COLUMN_OPTION: QueryColumn = {
column_name: DTTM_ALIAS,
is_dttm: true,
type: 'TIMESTAMP',
type_generic: GenericDataType.TEMPORAL,
type_generic: GenericDataType.Temporal,
};

export const QueryModeLabel = {
[QueryMode.aggregate]: t('Aggregate'),
[QueryMode.raw]: t('Raw records'),
[QueryMode.Aggregate]: t('Aggregate'),
[QueryMode.Raw]: t('Raw records'),
};

export const DEFAULT_SORT_SERIES_DATA: SortSeriesData = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const TestDataset: Dataset = {
is_dttm: false,
python_date_format: null,
type: 'BIGINT',
type_generic: GenericDataType.NUMERIC,
type_generic: GenericDataType.Numeric,
verbose_name: null,
warning_markdown: null,
},
Expand All @@ -55,7 +55,7 @@ export const TestDataset: Dataset = {
is_dttm: false,
python_date_format: null,
type: 'VARCHAR(16)',
type_generic: GenericDataType.STRING,
type_generic: GenericDataType.String,
verbose_name: '',
warning_markdown: null,
},
Expand All @@ -73,7 +73,7 @@ export const TestDataset: Dataset = {
is_dttm: false,
python_date_format: null,
type: 'VARCHAR(10)',
type_generic: GenericDataType.STRING,
type_generic: GenericDataType.String,
verbose_name: null,
warning_markdown: null,
},
Expand All @@ -91,7 +91,7 @@ export const TestDataset: Dataset = {
is_dttm: true,
python_date_format: null,
type: 'TIMESTAMP WITHOUT TIME ZONE',
type_generic: GenericDataType.TEMPORAL,
type_generic: GenericDataType.Temporal,
verbose_name: null,
warning_markdown: null,
},
Expand All @@ -109,7 +109,7 @@ export const TestDataset: Dataset = {
is_dttm: false,
python_date_format: null,
type: 'VARCHAR(255)',
type_generic: GenericDataType.STRING,
type_generic: GenericDataType.String,
verbose_name: null,
warning_markdown: null,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function isForcedCategorical(controls: ControlStateMapping): boolean {
checkColumnType(
getColumnLabel(controls?.x_axis?.value as QueryFormColumn),
controls?.datasource?.datasource,
[GenericDataType.NUMERIC],
[GenericDataType.Numeric],
) && !!controls?.xAxisForceCategorical?.value
);
}
Expand All @@ -71,7 +71,7 @@ function isSortable(controls: ControlStateMapping): boolean {
checkColumnType(
getColumnLabel(controls?.x_axis?.value as QueryFormColumn),
controls?.datasource?.datasource,
[GenericDataType.STRING, GenericDataType.BOOLEAN],
[GenericDataType.String, GenericDataType.Boolean],
)
);
}
Expand Down Expand Up @@ -173,7 +173,7 @@ export const xAxisForceCategoricalControl = {
checkColumnType(
getColumnLabel(controls?.x_axis?.value as QueryFormColumn),
controls?.datasource?.datasource,
[GenericDataType.NUMERIC],
[GenericDataType.Numeric],
),
shouldMapStateToProps: () => true,
},
Expand Down
36 changes: 18 additions & 18 deletions superset-frontend/packages/superset-ui-chart-controls/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,29 +420,29 @@ export type SectionOverrides = {

// Ref:
// - superset-frontend/src/explore/components/ConditionalFormattingControl.tsx
export enum COMPARATOR {
NONE = 'None',
GREATER_THAN = '>',
LESS_THAN = '<',
GREATER_OR_EQUAL = '≥',
LESS_OR_EQUAL = '≤',
EQUAL = '=',
NOT_EQUAL = '≠',
BETWEEN = '< x <',
BETWEEN_OR_EQUAL = '≤ x ≤',
BETWEEN_OR_LEFT_EQUAL = '≤ x <',
BETWEEN_OR_RIGHT_EQUAL = '< x ≤',
export enum Comparator {
None = 'None',
GreaterThan = '>',
LessThan = '<',
GreaterOrEqual = '≥',
LessOrEqual = '≤',
Equal = '=',
NotEqual = '≠',
Between = '< x <',
BetweenOrEqual = '≤ x ≤',
BetweenOrLeftEqual = '≤ x <',
BetweenOrRightEqual = '< x ≤',
}

export const MULTIPLE_VALUE_COMPARATORS = [
COMPARATOR.BETWEEN,
COMPARATOR.BETWEEN_OR_EQUAL,
COMPARATOR.BETWEEN_OR_LEFT_EQUAL,
COMPARATOR.BETWEEN_OR_RIGHT_EQUAL,
export const MultipleValueComparators = [
Comparator.Between,
Comparator.BetweenOrEqual,
Comparator.BetweenOrLeftEqual,
Comparator.BetweenOrRightEqual,
];

export type ConditionalFormattingConfig = {
operator?: COMPARATOR;
operator?: Comparator;
targetValue?: number;
targetValueLeft?: number;
targetValueRight?: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import memoizeOne from 'memoize-one';
import { addAlpha, DataRecord } from '@superset-ui/core';
import {
ColorFormatters,
COMPARATOR,
Comparator,
ConditionalFormattingConfig,
MULTIPLE_VALUE_COMPARATORS,
MultipleValueComparators,
} from '../types';

export const round = (num: number, precision = 0) =>
Expand Down Expand Up @@ -75,20 +75,20 @@ export const getColorFunction = (
return () => undefined;
}
if (
MULTIPLE_VALUE_COMPARATORS.includes(operator) &&
MultipleValueComparators.includes(operator) &&
(targetValueLeft === undefined || targetValueRight === undefined)
) {
return () => undefined;
}
if (
operator !== COMPARATOR.NONE &&
!MULTIPLE_VALUE_COMPARATORS.includes(operator) &&
operator !== Comparator.None &&
!MultipleValueComparators.includes(operator) &&
targetValue === undefined
) {
return () => undefined;
}
switch (operator) {
case COMPARATOR.NONE:
case Comparator.None:
minOpacity = MIN_OPACITY_UNBOUNDED;
comparatorFunction = (value: number, allValues: number[]) => {
const cutoffValue = Math.min(...allValues);
Expand All @@ -98,37 +98,37 @@ export const getColorFunction = (
: false;
};
break;
case COMPARATOR.GREATER_THAN:
case Comparator.GreaterThan:
comparatorFunction = (value: number, allValues: number[]) =>
value > targetValue!
? { cutoffValue: targetValue!, extremeValue: Math.max(...allValues) }
: false;
break;
case COMPARATOR.LESS_THAN:
case Comparator.LessThan:
comparatorFunction = (value: number, allValues: number[]) =>
value < targetValue!
? { cutoffValue: targetValue!, extremeValue: Math.min(...allValues) }
: false;
break;
case COMPARATOR.GREATER_OR_EQUAL:
case Comparator.GreaterOrEqual:
comparatorFunction = (value: number, allValues: number[]) =>
value >= targetValue!
? { cutoffValue: targetValue!, extremeValue: Math.max(...allValues) }
: false;
break;
case COMPARATOR.LESS_OR_EQUAL:
case Comparator.LessOrEqual:
comparatorFunction = (value: number, allValues: number[]) =>
value <= targetValue!
? { cutoffValue: targetValue!, extremeValue: Math.min(...allValues) }
: false;
break;
case COMPARATOR.EQUAL:
case Comparator.Equal:
comparatorFunction = (value: number) =>
value === targetValue!
? { cutoffValue: targetValue!, extremeValue: targetValue! }
: false;
break;
case COMPARATOR.NOT_EQUAL:
case Comparator.NotEqual:
comparatorFunction = (value: number, allValues: number[]) => {
if (value === targetValue!) {
return false;
Expand All @@ -144,25 +144,25 @@ export const getColorFunction = (
};
};
break;
case COMPARATOR.BETWEEN:
case Comparator.Between:
comparatorFunction = (value: number) =>
value > targetValueLeft! && value < targetValueRight!
? { cutoffValue: targetValueLeft!, extremeValue: targetValueRight! }
: false;
break;
case COMPARATOR.BETWEEN_OR_EQUAL:
case Comparator.BetweenOrEqual:
comparatorFunction = (value: number) =>
value >= targetValueLeft! && value <= targetValueRight!
? { cutoffValue: targetValueLeft!, extremeValue: targetValueRight! }
: false;
break;
case COMPARATOR.BETWEEN_OR_LEFT_EQUAL:
case Comparator.BetweenOrLeftEqual:
comparatorFunction = (value: number) =>
value >= targetValueLeft! && value < targetValueRight!
? { cutoffValue: targetValueLeft!, extremeValue: targetValueRight! }
: false;
break;
case COMPARATOR.BETWEEN_OR_RIGHT_EQUAL:
case Comparator.BetweenOrRightEqual:
comparatorFunction = (value: number) =>
value > targetValueLeft! && value <= targetValueRight!
? { cutoffValue: targetValueLeft!, extremeValue: targetValueRight! }
Expand Down Expand Up @@ -197,9 +197,9 @@ export const getColorFormatters = memoizeOne(
(acc: ColorFormatters, config: ConditionalFormattingConfig) => {
if (
config?.column !== undefined &&
(config?.operator === COMPARATOR.NONE ||
(config?.operator === Comparator.None ||
(config?.operator !== undefined &&
(MULTIPLE_VALUE_COMPARATORS.includes(config?.operator)
(MultipleValueComparators.includes(config?.operator)
? config?.targetValueLeft !== undefined &&
config?.targetValueRight !== undefined
: config?.targetValue !== undefined)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('ColumnOption', () => {
column: {
column_name: 'foo',
type: 'VARCHAR',
type_generic: GenericDataType.STRING,
type_generic: GenericDataType.String,
},
}),
);
Expand All @@ -92,11 +92,11 @@ describe('ColumnOption', () => {
it('dttm column has correct column label if showType is true', () => {
props.showType = true;
props.column.expression = undefined;
props.column.type_generic = GenericDataType.TEMPORAL;
props.column.type_generic = GenericDataType.Temporal;
wrapper = shallow(factory(props));
expect(wrapper.find(ColumnTypeLabel)).toHaveLength(1);
expect(wrapper.find(ColumnTypeLabel).props().type).toBe(
GenericDataType.TEMPORAL,
GenericDataType.Temporal,
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { ColumnTypeLabel, ColumnTypeLabelProps } from '../../src';

describe('ColumnOption', () => {
const defaultProps = {
type: GenericDataType.STRING,
type: GenericDataType.String,
};

const props = { ...defaultProps };
Expand All @@ -40,15 +40,15 @@ describe('ColumnOption', () => {
);
});
it('string type shows ABC icon', () => {
renderColumnTypeLabel({ type: GenericDataType.STRING });
renderColumnTypeLabel({ type: GenericDataType.String });
expect(screen.getByLabelText('string type icon')).toBeVisible();
});
it('int type shows # icon', () => {
renderColumnTypeLabel({ type: GenericDataType.NUMERIC });
renderColumnTypeLabel({ type: GenericDataType.Numeric });
expect(screen.getByLabelText('numeric type icon')).toBeVisible();
});
it('bool type shows 1|0 icon', () => {
renderColumnTypeLabel({ type: GenericDataType.BOOLEAN });
renderColumnTypeLabel({ type: GenericDataType.Boolean });
expect(screen.getByLabelText('boolean type icon')).toBeVisible();
});
it('expression type shows function icon', () => {
Expand All @@ -60,7 +60,7 @@ describe('ColumnOption', () => {
expect(screen.getByLabelText('unknown type icon')).toBeVisible();
});
it('datetime type displays', () => {
renderColumnTypeLabel({ type: GenericDataType.TEMPORAL });
renderColumnTypeLabel({ type: GenericDataType.Temporal });
expect(screen.getByLabelText('temporal type icon')).toBeVisible();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,25 @@ import { checkColumnType, TestDataset } from '../../src';

test('checkColumnType columns from a Dataset', () => {
expect(
checkColumnType('num', TestDataset, [GenericDataType.NUMERIC]),
checkColumnType('num', TestDataset, [GenericDataType.Numeric]),
).toEqual(true);
expect(checkColumnType('num', TestDataset, [GenericDataType.STRING])).toEqual(
expect(checkColumnType('num', TestDataset, [GenericDataType.String])).toEqual(
false,
);
expect(
checkColumnType('gender', TestDataset, [GenericDataType.STRING]),
checkColumnType('gender', TestDataset, [GenericDataType.String]),
).toEqual(true);
expect(
checkColumnType('gender', TestDataset, [GenericDataType.NUMERIC]),
checkColumnType('gender', TestDataset, [GenericDataType.Numeric]),
).toEqual(false);
});

test('checkColumnType from a QueryResponse', () => {
expect(
checkColumnType('Column 1', testQueryResponse, [GenericDataType.STRING]),
checkColumnType('Column 1', testQueryResponse, [GenericDataType.String]),
).toEqual(true);
expect(
checkColumnType('Column 1', testQueryResponse, [GenericDataType.NUMERIC]),
checkColumnType('Column 1', testQueryResponse, [GenericDataType.Numeric]),
).toEqual(false);
});

Expand Down
Loading

0 comments on commit 020bffe

Please sign in to comment.