|
@@ -11,9 +11,10 @@ import {Tooltip} from 'sentry/components/tooltip';
|
|
|
import {IconLightning, IconReleases, IconWarning} from 'sentry/icons';
|
|
|
import {t} from 'sentry/locale';
|
|
|
import {space} from 'sentry/styles/space';
|
|
|
-import type {MetricMeta, MetricsOperation, MRI} from 'sentry/types';
|
|
|
+import type {MetricMeta, MRI} from 'sentry/types/metrics';
|
|
|
import {trackAnalytics} from 'sentry/utils/analytics';
|
|
|
import {
|
|
|
+ getDefaultAggregate,
|
|
|
isAllowedOp,
|
|
|
isCustomMetric,
|
|
|
isSpanMeasurement,
|
|
@@ -53,10 +54,6 @@ const isShownByDefault = (metric: MetricMeta) =>
|
|
|
isVisibleTransactionMetric(metric) ||
|
|
|
isVisibleSpanMetric(metric);
|
|
|
|
|
|
-function getOpsForMRI(mri: MRI, meta: MetricMeta[]) {
|
|
|
- return meta.find(metric => metric.mri === mri)?.operations.filter(isAllowedOp) ?? [];
|
|
|
-}
|
|
|
-
|
|
|
function useMriMode() {
|
|
|
const [mriMode, setMriMode] = useState(false);
|
|
|
const mriModeKeyPressed = useKeyPress('`', undefined, true);
|
|
@@ -153,24 +150,34 @@ export const QueryBuilder = memo(function QueryBuilder({
|
|
|
|
|
|
const handleMRIChange = useCallback(
|
|
|
({value}) => {
|
|
|
- const availableOps = getOpsForMRI(value, meta);
|
|
|
- const selectedOp = availableOps.includes(
|
|
|
- (metricsQuery.op ?? '') as MetricsOperation
|
|
|
- )
|
|
|
- ? metricsQuery.op
|
|
|
- : availableOps?.[0];
|
|
|
-
|
|
|
- const queryChanges = {
|
|
|
- mri: value,
|
|
|
- op: selectedOp,
|
|
|
- groupBy: undefined,
|
|
|
- };
|
|
|
+ const currentMRI = parseMRI(metricsQuery.mri);
|
|
|
+ const newMRI = parseMRI(value);
|
|
|
+
|
|
|
+ if (!currentMRI || !newMRI) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ let queryChanges = {};
|
|
|
+
|
|
|
+ // If the type is the same, we can keep the current aggregate
|
|
|
+ if (currentMRI.type === newMRI.type) {
|
|
|
+ queryChanges = {
|
|
|
+ mri: value,
|
|
|
+ groupBy: undefined,
|
|
|
+ };
|
|
|
+ } else {
|
|
|
+ queryChanges = {
|
|
|
+ mri: value,
|
|
|
+ op: getDefaultAggregate(value),
|
|
|
+ groupBy: undefined,
|
|
|
+ };
|
|
|
+ }
|
|
|
|
|
|
trackAnalytics('ddm.widget.metric', {organization});
|
|
|
incrementQueryMetric('ddm.widget.metric', queryChanges);
|
|
|
onChange(queryChanges);
|
|
|
},
|
|
|
- [incrementQueryMetric, meta, metricsQuery.op, onChange, organization]
|
|
|
+ [incrementQueryMetric, metricsQuery.mri, onChange, organization]
|
|
|
);
|
|
|
|
|
|
const handleOpChange = useCallback(
|