bito-code-review[bot] commented on code in PR #36760:
URL: https://github.com/apache/superset/pull/36760#discussion_r2641588588
##########
superset-frontend/src/explore/components/controls/MetricControl/AdhocMetricOption.tsx:
##########
@@ -18,12 +18,32 @@
*/
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';
+import { savedMetricType as SavedMetricTypeDef } from './types';
+
+interface AdhocMetricOptionProps {
+ adhocMetric: AdhocMetric;
+ onMetricEdit: (newMetric: Metric, oldMetric: Metric) => void;
+ onRemoveMetric?: (index: number) => void;
+ columns?: { column_name: string; type: string }[];
+ savedMetricsOptions?: SavedMetricTypeDef[];
+ savedMetric?: SavedMetricTypeDef | Record<string, never>;
Review Comment:
<!-- Bito Reply -->
Your explanation makes sense for matching JavaScript's default empty object
behavior and enabling conditional rendering based on property presence.
However, since `SavedMetricTypeDef` requires fields like `metric_name` and
`expression`, allowing `Record<string, never>` (which is `{}`) and then casting
it as `SavedMetricTypeDef` creates type safety risks—code might assume required
properties exist. Consider changing the type to `SavedMetricTypeDef |
undefined` and defaulting `savedMetric` to `undefined` instead of `{}` for
stricter typing.
**superset-frontend/src/explore/components/controls/MetricControl/types.ts**
```
export type savedMetricType = {
metric_name: string;
verbose_name?: string;
expression: string;
error_text?: string;
id?: number | string;
};
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]