sadpandajoe commented on code in PR #42483:
URL: https://github.com/apache/superset/pull/42483#discussion_r3867897882
##########
superset-frontend/src/explore/components/controls/DndColumnSelectControl/DndMetricSelect.tsx:
##########
@@ -46,7 +46,31 @@ import { AGGREGATES } from 'src/explore/constants';
import { datasetLabelLower } from 'src/features/semanticLayers/label';
const EMPTY_OBJECT = {};
-const DND_ACCEPTED_TYPES = [DndItemType.Column, DndItemType.Metric];
+const DND_ACCEPTED_TYPES = [
+ DndItemType.Column,
+ DndItemType.Metric,
+ DndItemType.Folder,
+];
+
+/**
+ * Build an adhoc metric from a dropped column, picking a sensible default
+ * aggregation from the column's data type: SUM for numeric columns,
+ * COUNT_DISTINCT for string/boolean/temporal ones.
+ */
+export const createAdhocMetricFromColumn = (
+ column: ColumnMeta,
+): AdhocMetric => {
+ // Cast config to handle ColumnMeta/ColumnType mismatch
+ const config = {
+ column,
+ } as Partial<AdhocMetric>;
+ if (column.type_generic === GenericDataType.Numeric) {
+ config.aggregate = AGGREGATES.SUM;
+ } else {
Review Comment:
This now assigns `COUNT_DISTINCT` to `MultiValue` and untyped columns, while
a folder drop immediately creates and applies these adhoc metrics without
opening the configuration popover. Previously only string, boolean, and
temporal columns got that default, so a folder containing a multi-value field
can now emit a different aggregation without a user choice. Could this keep the
explicit supported-type check (or add coverage documenting why the broader
default is valid)?
--
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]