Skip to content
This repository has been archived by the owner on Dec 10, 2021. It is now read-only.

chore: clean up a couple of TypeScript warnings #754

Merged
merged 1 commit into from
Aug 26, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import styled from '@superset-ui/style';
import InfoTooltipWithTrigger from './InfoTooltipWithTrigger';
import { ColumnTypeLabel } from './ColumnTypeLabel';
import CertifiedIconWithTooltip from './CertifiedIconWithTooltip';
import { Metric } from '../types';

const FlexRowContainer = styled.div`
align-items: center;
Expand All @@ -33,21 +34,11 @@ const FlexRowContainer = styled.div`
`;

export interface MetricOptionProps {
metric: {
verbose_name?: string;
metric_name: string;
label?: string;
description: string;
warning_text: string;
expression: string;
is_certified?: boolean;
certified_by?: string | null;
certification_details?: string | null;
};
metric: Metric;
Copy link
Member

Choose a reason for hiding this comment

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

Just merged in that other pr in case it affects this one.

openInNewWindow?: boolean;
showFormula?: boolean;
showType?: boolean;
url?: string;
url: string;
}

export function MetricOption({
Expand Down
2 changes: 1 addition & 1 deletion packages/superset-ui-chart-controls/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const internalSharedControls = sharedControlsModule;
export const sections = sectionModules;
export { D3_FORMAT_DOCS, D3_FORMAT_OPTIONS, D3_TIME_FORMAT_OPTIONS } from './utils/D3Formatting';
export { formatSelectOptions, formatSelectOptionsForRange } from './utils/selectOptions';
export * from './utils/mainMetric';
export { default as mainMetric } from './utils/mainMetric';
export * from './utils/expandControlConfig';

export * from './components/InfoTooltipWithTrigger';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ import {
import { legacyValidateInteger, validateNonEmpty } from '@superset-ui/validator';

import { formatSelectOptions } from '../utils/selectOptions';
import { mainMetric, Metric } from '../utils/mainMetric';
import mainMetric from '../utils/mainMetric';
import { TIME_FILTER_LABELS } from '../constants';
import {
Metric,
SharedControlConfig,
ColumnMeta,
DatasourceMeta,
Expand Down
12 changes: 12 additions & 0 deletions packages/superset-ui-chart-controls/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ import { QueryFormData } from '@superset-ui/query';
import sharedControls from './shared-controls';
import sharedControlComponents from './shared-controls/components';

export type Metric = {
metric_name: string;
verbose_name?: string;
label?: string;
description?: string;
warning_text?: string;
expression?: string;
is_certified?: boolean;
certified_by?: string | null;
certification_details?: string | null;
};

// eslint-disable-next-line @typescript-eslint/no-explicit-any
type AnyDict = Record<string, any>;
interface Action {
Expand Down
8 changes: 2 additions & 6 deletions packages/superset-ui-chart-controls/src/utils/mainMetric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
/* eslint-disable camelcase */
import { Metric } from '../types';

export type Metric = {
metric_name: string;
};

export function mainMetric(savedMetrics?: Metric[] | null) {
export default function mainMetric(savedMetrics?: Metric[] | null) {
// Using 'count' as default metric if it exists, otherwise using whatever one shows up first
let metric;
if (savedMetrics && savedMetrics.length > 0) {
Expand Down
1 change: 0 additions & 1 deletion packages/superset-ui-translation/src/Translator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export default class Translator {

constructor(config: TranslatorConfig = {}) {
const { languagePack = DEFAULT_LANGUAGE_PACK } = config;
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
this.i18n = new UntypedJed(languagePack) as Jed;
this.locale = this.i18n.options.locale_data.superset[''].lang as Locale;
}
Expand Down
18 changes: 8 additions & 10 deletions plugins/legacy-plugin-chart-time-table/src/TimeTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { formatNumber } from '@superset-ui/number-format';
import { formatTime } from '@superset-ui/time-format';
import styled from '@superset-ui/style';
import moment from 'moment';
import { InfoTooltipWithTrigger, MetricOption } from '@superset-ui/chart-controls';
import { InfoTooltipWithTrigger, MetricOption, Metric } from '@superset-ui/chart-controls';

import FormattedNumber from './FormattedNumber';
import SparklineCell from './SparklineCell';
Expand All @@ -51,11 +51,12 @@ function colorFromBounds(

// @ts-ignore
return colorScale(value);
// eslint-disable-next-line no-else-return
Copy link
Member

Choose a reason for hiding this comment

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

Honestly, I kind of prefer reading "else" statements... seems more logical to me. ¯\_(ツ)_/¯

Appreciate all this cleanup work nonetheless! ✨

} else if (min !== null) {
}
if (min !== null) {
// @ts-ignore
return value >= min ? maxColor : minColor;
} else if (max !== null) {
}
if (max !== null) {
// @ts-ignore
return value < max ? maxColor : minColor;
}
Expand Down Expand Up @@ -104,7 +105,6 @@ class TimeTable extends React.PureComponent<ChartProps, {}> {
renderLeftCell(row: RowData) {
const { rowType, url } = this.props;
const context = { metric: row };
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
const fullUrl = url ? Mustache.render(url, context) : null;

if (rowType === 'column') {
Expand All @@ -119,10 +119,9 @@ class TimeTable extends React.PureComponent<ChartProps, {}> {
return column.label;
}

const metric = row;

// @ts-ignore
return <MetricOption openInNewWindow metric={metric} url={fullUrl} showFormula={false} />;
return (
<MetricOption openInNewWindow metric={row as Metric} url={fullUrl} showFormula={false} />
);
}

// eslint-disable-next-line class-methods-use-this
Expand All @@ -141,7 +140,6 @@ class TimeTable extends React.PureComponent<ChartProps, {}> {
}
}
} else {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
sparkData = entries.map(d => d[valueField]);
}

Expand Down
15 changes: 7 additions & 8 deletions plugins/legacy-plugin-chart-time-table/src/transformProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* under the License.
*/
import { ChartProps, DataRecord } from '@superset-ui/chart';
import { QueryObjectMetric } from '@superset-ui/query';

interface FormData {
groupby: string[];
Expand All @@ -38,7 +39,7 @@ export type TableChartProps = ChartProps & {
};

interface ColumnData {
timeLag?: string;
timeLag?: string | number;
}
export default function transformProps(chartProps: TableChartProps) {
const { height, datasource, formData, queryData } = chartProps;
Expand All @@ -56,20 +57,18 @@ export default function transformProps(chartProps: TableChartProps) {
} else {
const metricMap = datasource.metrics.reduce((acc, current) => {
const map = acc;
// @ts-ignore
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
map[current.metric_name] = current;
if (current.metric_name) {
map[current.metric_name] = current;
}
return map;
}, {});
}, {} as Record<string, QueryObjectMetric>);
rows = metrics.map(metric => (typeof metric === 'object' ? metric : metricMap[metric]));
}

// TODO: Better parse this from controls instead of mutative value here.
columnCollection.forEach(column => {
const c: ColumnData = column;
if (c.timeLag !== undefined && c.timeLag !== null && c.timeLag !== '') {
// @ts-ignore
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
if (typeof c.timeLag === 'string' && c.timeLag) {
c.timeLag = parseInt(c.timeLag, 10);
}
});
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13359,7 +13359,7 @@ murmurhash-js@^1.0.0:
resolved "https://registry.yarnpkg.com/murmurhash-js/-/murmurhash-js-1.0.0.tgz#b06278e21fc6c37fa5313732b0412bcb6ae15f51"
integrity sha1-sGJ44h/Gw3+lMTcysEEry2rhX1E=

mustache@^4.0.0, mustache@^4.0.1:
mustache@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/mustache/-/mustache-4.0.1.tgz#d99beb031701ad433338e7ea65e0489416c854a2"
integrity sha512-yL5VE97+OXn4+Er3THSmTdCFCtx5hHWzrolvH+JObZnUYwuaG7XV+Ch4fR2cIrcYI0tFHxS7iyFYl14bW8y2sA==
Expand Down