mirror of
https://github.com/apache/superset.git
synced 2026-04-24 18:44:53 +00:00
feat(explore): default aggregate for string/numeric columns when creating metric (#15798)
* feat(explore): default aggregate for string/numeric columns when creating metric * Fix for editing items with the same label * Replace componentDidUpdate with getDerivedStateFromProps * Wrap changes in feature flag
This commit is contained in:
committed by
GitHub
parent
040b94119b
commit
5e1c469f42
@@ -18,7 +18,14 @@
|
||||
*/
|
||||
|
||||
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import { ensureIsArray, Metric, tn } from '@superset-ui/core';
|
||||
import {
|
||||
ensureIsArray,
|
||||
FeatureFlag,
|
||||
GenericDataType,
|
||||
isFeatureEnabled,
|
||||
Metric,
|
||||
tn,
|
||||
} from '@superset-ui/core';
|
||||
import { ColumnMeta } from '@superset-ui/chart-controls';
|
||||
import { isEqual } from 'lodash';
|
||||
import { usePrevious } from 'src/common/hooks/usePrevious';
|
||||
@@ -30,6 +37,7 @@ import { DatasourcePanelDndItem } from 'src/explore/components/DatasourcePanel/t
|
||||
import { DndItemType } from 'src/explore/components/DndItemType';
|
||||
import DndSelectLabel from 'src/explore/components/controls/DndColumnSelectControl/DndSelectLabel';
|
||||
import { savedMetricType } from 'src/explore/components/controls/MetricControl/types';
|
||||
import { AGGREGATES } from 'src/explore/constants';
|
||||
|
||||
const isDictionaryForAdhocMetric = (value: any) =>
|
||||
value && !(value instanceof AdhocMetric) && value.expressionType;
|
||||
@@ -254,12 +262,24 @@ export const DndMetricSelect = (props: any) => {
|
||||
const adhocMetric = useMemo(() => {
|
||||
if (droppedItem?.type === DndItemType.Column) {
|
||||
const itemValue = droppedItem?.value as ColumnMeta;
|
||||
return new AdhocMetric({
|
||||
const config: Partial<AdhocMetric> = {
|
||||
column: { column_name: itemValue?.column_name },
|
||||
});
|
||||
};
|
||||
if (isFeatureEnabled(FeatureFlag.UX_BETA)) {
|
||||
if (itemValue.type_generic === GenericDataType.NUMERIC) {
|
||||
config.aggregate = AGGREGATES.SUM;
|
||||
} else if (
|
||||
itemValue.type_generic === GenericDataType.STRING ||
|
||||
itemValue.type_generic === GenericDataType.BOOLEAN ||
|
||||
itemValue.type_generic === GenericDataType.TEMPORAL
|
||||
) {
|
||||
config.aggregate = AGGREGATES.COUNT_DISTINCT;
|
||||
}
|
||||
}
|
||||
return new AdhocMetric(config);
|
||||
}
|
||||
return new AdhocMetric({ isNew: true });
|
||||
}, [droppedItem?.type, droppedItem?.value]);
|
||||
}, [droppedItem]);
|
||||
|
||||
return (
|
||||
<div className="metrics-select">
|
||||
|
||||
Reference in New Issue
Block a user