fix(types): fix more TypeScript errors in Metric controls

- Fix savedMetric?.metric_name optional chaining in getDefaultTab
- Update onChange signature to accept two parameters
- Fix aggregate Select value to use nullish coalescing
- Update AdhocMetricOption to use proper imported types
- Add default values for optional props passed to children

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Evan Rusackas
2025-12-20 00:30:15 -08:00
parent 53a584d527
commit de9dc4fa32
2 changed files with 18 additions and 26 deletions

View File

@@ -76,8 +76,10 @@ interface ExtraConfig {
[key: string]: unknown;
}
type Metric = AdhocMetric | SavedMetricType;
interface AdhocMetricEditPopoverProps {
onChange: (adhocMetric: AdhocMetric) => void;
onChange: (newMetric: Metric, oldMetric?: Metric) => void;
onClose: () => void;
onResize: () => void;
getCurrentTab?: (tab: string) => void;
@@ -216,7 +218,7 @@ export default class AdhocMetricEditPopover extends PureComponent<
return adhocMetric.expressionType;
}
if (
(isNewMetric || savedMetric.metric_name) &&
(isNewMetric || savedMetric?.metric_name) &&
Array.isArray(savedMetricsOptions) &&
savedMetricsOptions.length > 0
) {
@@ -387,7 +389,7 @@ export default class AdhocMetricEditPopover extends PureComponent<
const aggregateSelectProps = {
ariaLabel: t('Select aggregate options'),
placeholder: t('%s aggregates(s)', AGGREGATES_OPTIONS.length),
value: adhocMetric.aggregate || adhocMetric.inferSqlExpressionAggregate(),
value: adhocMetric.aggregate ?? adhocMetric.inferSqlExpressionAggregate() ?? undefined,
onChange: this.onAggregateChange,
allowClear: true,
autoFocus: !!columnValue,

View File

@@ -18,35 +18,25 @@
*/
import { PureComponent } from 'react';
import PropTypes from 'prop-types';
import { Metric } from '@superset-ui/core';
import { OptionControlLabel } from 'src/explore/components/controls/OptionControls';
import { DndItemType } from 'src/explore/components/DndItemType';
import { Datasource } from 'src/explore/types';
import { ISaveableDatasource } from 'src/SqlLab/components/SaveDatasetModal';
import columnType from './columnType';
import AdhocMetric from './AdhocMetric';
import savedMetricType from './savedMetricType';
import AdhocMetricPopoverTrigger from './AdhocMetricPopoverTrigger';
interface ColumnType {
column_name: string;
verbose_name?: string;
[key: string]: unknown;
}
interface SavedMetricType {
metric_name: string;
verbose_name?: string;
expression?: string;
error_text?: string;
[key: string]: unknown;
}
import { savedMetricType as SavedMetricTypeDef } from './types';
interface AdhocMetricOptionProps {
adhocMetric: AdhocMetric;
onMetricEdit: (metric: AdhocMetric) => void;
onMetricEdit: (newMetric: Metric, oldMetric: Metric) => void;
onRemoveMetric?: (index: number) => void;
columns?: ColumnType[];
savedMetricsOptions?: SavedMetricType[];
savedMetric: SavedMetricType;
datasource?: Record<string, unknown>;
columns?: { column_name: string; type: string }[];
savedMetricsOptions?: SavedMetricTypeDef[];
savedMetric: SavedMetricTypeDef;
datasource?: Datasource & ISaveableDatasource;
onMoveLabel?: (dragIndex: number, hoverIndex: number) => void;
onDropLabel?: () => void;
index?: number;
@@ -103,10 +93,10 @@ class AdhocMetricOption extends PureComponent<AdhocMetricOptionProps> {
<AdhocMetricPopoverTrigger
adhocMetric={adhocMetric}
onMetricEdit={onMetricEdit}
columns={columns}
savedMetricsOptions={savedMetricsOptions}
columns={columns ?? []}
savedMetricsOptions={savedMetricsOptions ?? []}
savedMetric={savedMetric}
datasource={datasource}
datasource={datasource!}
>
<OptionControlLabel
savedMetric={savedMetric}
@@ -115,7 +105,7 @@ class AdhocMetricOption extends PureComponent<AdhocMetricOptionProps> {
onRemove={() => this.onRemoveMetric()}
onMoveLabel={onMoveLabel}
onDropLabel={onDropLabel}
index={index}
index={index ?? 0}
type={type ?? DndItemType.AdhocMetricOption}
withCaret={withCaret}
isFunction