chore: update search bar in inspect modal

This commit is contained in:
amlannandy 2025-08-19 10:20:07 +07:00 committed by Amlan Kumar Nandy
parent 7128d78415
commit cd525221e5
11 changed files with 222 additions and 119 deletions

View File

@ -33,7 +33,7 @@ function ExpandedView({
options, options,
spaceAggregationSeriesMap, spaceAggregationSeriesMap,
step, step,
metricInspectionOptions, appliedMetricInspectionOptions,
timeAggregatedSeriesMap, timeAggregatedSeriesMap,
}: ExpandedViewProps): JSX.Element { }: ExpandedViewProps): JSX.Element {
const [ const [
@ -44,17 +44,17 @@ function ExpandedView({
useEffect(() => { useEffect(() => {
logEvent(MetricsExplorerEvents.InspectPointClicked, { logEvent(MetricsExplorerEvents.InspectPointClicked, {
[MetricsExplorerEventKeys.Modal]: 'inspect', [MetricsExplorerEventKeys.Modal]: 'inspect',
[MetricsExplorerEventKeys.Filters]: metricInspectionOptions.filters, [MetricsExplorerEventKeys.Filters]: appliedMetricInspectionOptions.filters,
[MetricsExplorerEventKeys.TimeAggregationInterval]: [MetricsExplorerEventKeys.TimeAggregationInterval]:
metricInspectionOptions.timeAggregationInterval, appliedMetricInspectionOptions.timeAggregationInterval,
[MetricsExplorerEventKeys.TimeAggregationOption]: [MetricsExplorerEventKeys.TimeAggregationOption]:
metricInspectionOptions.timeAggregationOption, appliedMetricInspectionOptions.timeAggregationOption,
[MetricsExplorerEventKeys.SpaceAggregationOption]: [MetricsExplorerEventKeys.SpaceAggregationOption]:
metricInspectionOptions.spaceAggregationOption, appliedMetricInspectionOptions.spaceAggregationOption,
[MetricsExplorerEventKeys.SpaceAggregationLabels]: [MetricsExplorerEventKeys.SpaceAggregationLabels]:
metricInspectionOptions.spaceAggregationLabels, appliedMetricInspectionOptions.spaceAggregationLabels,
}); });
}, [metricInspectionOptions]); }, [appliedMetricInspectionOptions]);
useEffect(() => { useEffect(() => {
if (step !== InspectionStep.COMPLETED) { if (step !== InspectionStep.COMPLETED) {
@ -167,7 +167,7 @@ function ExpandedView({
<Typography.Text strong> <Typography.Text strong>
{`${absoluteValue} is the ${ {`${absoluteValue} is the ${
SPACE_AGGREGATION_OPTIONS_FOR_EXPANDED_VIEW[ SPACE_AGGREGATION_OPTIONS_FOR_EXPANDED_VIEW[
metricInspectionOptions.spaceAggregationOption ?? appliedMetricInspectionOptions.spaceAggregationOption ??
SpaceAggregationOptions.SUM_BY SpaceAggregationOptions.SUM_BY
] ]
} of`} } of`}
@ -240,7 +240,7 @@ function ExpandedView({
)?.value ?? options?.value )?.value ?? options?.value
} is the ${ } is the ${
TIME_AGGREGATION_OPTIONS[ TIME_AGGREGATION_OPTIONS[
metricInspectionOptions.timeAggregationOption ?? appliedMetricInspectionOptions.timeAggregationOption ??
TimeAggregationOptions.SUM TimeAggregationOptions.SUM
] ]
} of` } of`
@ -299,7 +299,7 @@ function ExpandedView({
<Typography.Text strong> <Typography.Text strong>
{`${absoluteValue} is the ${ {`${absoluteValue} is the ${
TIME_AGGREGATION_OPTIONS[ TIME_AGGREGATION_OPTIONS[
metricInspectionOptions.timeAggregationOption ?? appliedMetricInspectionOptions.timeAggregationOption ??
TimeAggregationOptions.SUM TimeAggregationOptions.SUM
] ]
} of`} } of`}

View File

@ -29,7 +29,7 @@ function GraphView({
popoverOptions, popoverOptions,
setShowExpandedView, setShowExpandedView,
setExpandedViewOptions, setExpandedViewOptions,
metricInspectionOptions, appliedMetricInspectionOptions,
isInspectMetricsRefetching, isInspectMetricsRefetching,
}: GraphViewProps): JSX.Element { }: GraphViewProps): JSX.Element {
const isDarkMode = useIsDarkMode(); const isDarkMode = useIsDarkMode();
@ -233,7 +233,7 @@ function GraphView({
inspectMetricsTimeSeries={inspectMetricsTimeSeries} inspectMetricsTimeSeries={inspectMetricsTimeSeries}
setShowExpandedView={setShowExpandedView} setShowExpandedView={setShowExpandedView}
setExpandedViewOptions={setExpandedViewOptions} setExpandedViewOptions={setExpandedViewOptions}
metricInspectionOptions={metricInspectionOptions} appliedMetricInspectionOptions={appliedMetricInspectionOptions}
isInspectMetricsRefetching={isInspectMetricsRefetching} isInspectMetricsRefetching={isInspectMetricsRefetching}
/> />
)} )}
@ -255,7 +255,7 @@ function GraphView({
<HoverPopover <HoverPopover
options={hoverPopoverOptions} options={hoverPopoverOptions}
step={inspectionStep} step={inspectionStep}
metricInspectionOptions={metricInspectionOptions} appliedMetricInspectionOptions={appliedMetricInspectionOptions}
/> />
)} )}
</div> </div>

View File

@ -122,6 +122,10 @@
gap: 4px; gap: 4px;
.inspect-metrics-query-builder-header { .inspect-metrics-query-builder-header {
display: flex;
align-items: center;
justify-content: space-between;
.query-builder-button-label { .query-builder-button-label {
display: flex; display: flex;
align-items: center; align-items: center;

View File

@ -24,6 +24,7 @@ import {
MetricInspectionAction, MetricInspectionAction,
} from './types'; } from './types';
import { useInspectMetrics } from './useInspectMetrics'; import { useInspectMetrics } from './useInspectMetrics';
import { useMetricName } from './utils';
function Inspect({ function Inspect({
metricName: defaultMetricName, metricName: defaultMetricName,
@ -31,7 +32,12 @@ function Inspect({
onClose, onClose,
}: InspectProps): JSX.Element { }: InspectProps): JSX.Element {
const isDarkMode = useIsDarkMode(); const isDarkMode = useIsDarkMode();
const [metricName, setMetricName] = useState<string | null>(defaultMetricName); const {
currentMetricName,
setCurrentMetricName,
appliedMetricName,
setAppliedMetricName,
} = useMetricName(defaultMetricName);
const [ const [
popoverOptions, popoverOptions,
setPopoverOptions, setPopoverOptions,
@ -42,9 +48,12 @@ function Inspect({
] = useState<GraphPopoverOptions | null>(null); ] = useState<GraphPopoverOptions | null>(null);
const [showExpandedView, setShowExpandedView] = useState(false); const [showExpandedView, setShowExpandedView] = useState(false);
const { data: metricDetailsData } = useGetMetricDetails(metricName ?? '', { const { data: metricDetailsData } = useGetMetricDetails(
enabled: !!metricName, appliedMetricName ?? '',
}); {
enabled: !!appliedMetricName,
},
);
const { currentQuery } = useQueryBuilder(); const { currentQuery } = useQueryBuilder();
const { handleChangeQueryData } = useQueryOperations({ const { handleChangeQueryData } = useQueryOperations({
@ -97,25 +106,16 @@ function Inspect({
aggregatedTimeSeries, aggregatedTimeSeries,
timeAggregatedSeriesMap, timeAggregatedSeriesMap,
reset, reset,
} = useInspectMetrics(metricName); } = useInspectMetrics(appliedMetricName);
const handleDispatchMetricInspectionOptions = useCallback( const handleDispatchMetricInspectionOptions = useCallback(
(action: MetricInspectionAction): void => { (action: MetricInspectionAction): void => {
dispatchMetricInspectionOptions(action); dispatchMetricInspectionOptions(action);
logEvent(MetricsExplorerEvents.InspectQueryChanged, { logEvent(MetricsExplorerEvents.InspectQueryChanged, {
[MetricsExplorerEventKeys.Modal]: 'inspect', [MetricsExplorerEventKeys.Modal]: 'inspect',
[MetricsExplorerEventKeys.Filters]: metricInspectionOptions.filters,
[MetricsExplorerEventKeys.TimeAggregationInterval]:
metricInspectionOptions.timeAggregationInterval,
[MetricsExplorerEventKeys.TimeAggregationOption]:
metricInspectionOptions.timeAggregationOption,
[MetricsExplorerEventKeys.SpaceAggregationOption]:
metricInspectionOptions.spaceAggregationOption,
[MetricsExplorerEventKeys.SpaceAggregationLabels]:
metricInspectionOptions.spaceAggregationLabels,
}); });
}, },
[dispatchMetricInspectionOptions, metricInspectionOptions], [dispatchMetricInspectionOptions],
); );
const selectedMetricType = useMemo( const selectedMetricType = useMemo(
@ -135,12 +135,6 @@ function Inspect({
reset(); reset();
}, [reset]); }, [reset]);
// Reset inspection when the selected metric changes
useEffect(() => {
resetInspection();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [metricName]);
// Hide expanded view whenever inspection step changes // Hide expanded view whenever inspection step changes
useEffect(() => { useEffect(() => {
setShowExpandedView(false); setShowExpandedView(false);
@ -193,7 +187,7 @@ function Inspect({
inspectMetricsTimeSeries={aggregatedTimeSeries} inspectMetricsTimeSeries={aggregatedTimeSeries}
formattedInspectMetricsTimeSeries={formattedInspectMetricsTimeSeries} formattedInspectMetricsTimeSeries={formattedInspectMetricsTimeSeries}
resetInspection={resetInspection} resetInspection={resetInspection}
metricName={metricName} metricName={appliedMetricName}
metricUnit={selectedMetricUnit} metricUnit={selectedMetricUnit}
metricType={selectedMetricType} metricType={selectedMetricType}
spaceAggregationSeriesMap={spaceAggregationSeriesMap} spaceAggregationSeriesMap={spaceAggregationSeriesMap}
@ -203,15 +197,16 @@ function Inspect({
showExpandedView={showExpandedView} showExpandedView={showExpandedView}
setExpandedViewOptions={setExpandedViewOptions} setExpandedViewOptions={setExpandedViewOptions}
popoverOptions={popoverOptions} popoverOptions={popoverOptions}
metricInspectionOptions={metricInspectionOptions} appliedMetricInspectionOptions={metricInspectionOptions.appliedOptions}
isInspectMetricsRefetching={isInspectMetricsRefetching} isInspectMetricsRefetching={isInspectMetricsRefetching}
/> />
<QueryBuilder <QueryBuilder
metricName={metricName} currentMetricName={currentMetricName}
setCurrentMetricName={setCurrentMetricName}
setAppliedMetricName={setAppliedMetricName}
metricType={selectedMetricType} metricType={selectedMetricType}
setMetricName={setMetricName}
spaceAggregationLabels={spaceAggregationLabels} spaceAggregationLabels={spaceAggregationLabels}
metricInspectionOptions={metricInspectionOptions} currentMetricInspectionOptions={metricInspectionOptions.currentOptions}
dispatchMetricInspectionOptions={handleDispatchMetricInspectionOptions} dispatchMetricInspectionOptions={handleDispatchMetricInspectionOptions}
inspectionStep={inspectionStep} inspectionStep={inspectionStep}
inspectMetricsTimeSeries={inspectMetricsTimeSeries} inspectMetricsTimeSeries={inspectMetricsTimeSeries}
@ -228,7 +223,7 @@ function Inspect({
options={expandedViewOptions} options={expandedViewOptions}
spaceAggregationSeriesMap={spaceAggregationSeriesMap} spaceAggregationSeriesMap={spaceAggregationSeriesMap}
step={inspectionStep} step={inspectionStep}
metricInspectionOptions={metricInspectionOptions} appliedMetricInspectionOptions={metricInspectionOptions.appliedOptions}
timeAggregatedSeriesMap={timeAggregatedSeriesMap} timeAggregatedSeriesMap={timeAggregatedSeriesMap}
/> />
)} )}
@ -244,7 +239,10 @@ function Inspect({
aggregatedTimeSeries, aggregatedTimeSeries,
formattedInspectMetricsTimeSeries, formattedInspectMetricsTimeSeries,
resetInspection, resetInspection,
metricName, appliedMetricName,
currentMetricName,
setCurrentMetricName,
setAppliedMetricName,
selectedMetricUnit, selectedMetricUnit,
selectedMetricType, selectedMetricType,
spaceAggregationSeriesMap, spaceAggregationSeriesMap,

View File

@ -1,5 +1,6 @@
import { Button, Card } from 'antd'; import { Button, Card } from 'antd';
import { Atom } from 'lucide-react'; import { Atom, Play } from 'lucide-react';
import { useCallback } from 'react';
import { QueryBuilderProps } from './types'; import { QueryBuilderProps } from './types';
import { import {
@ -10,16 +11,24 @@ import {
} from './utils'; } from './utils';
function QueryBuilder({ function QueryBuilder({
metricName, currentMetricName,
setMetricName, setCurrentMetricName,
setAppliedMetricName,
spaceAggregationLabels, spaceAggregationLabels,
metricInspectionOptions, currentMetricInspectionOptions,
dispatchMetricInspectionOptions, dispatchMetricInspectionOptions,
inspectionStep, inspectionStep,
inspectMetricsTimeSeries, inspectMetricsTimeSeries,
searchQuery, searchQuery,
metricType, metricType,
}: QueryBuilderProps): JSX.Element { }: QueryBuilderProps): JSX.Element {
const applyInspectionOptions = useCallback(() => {
setAppliedMetricName(currentMetricName ?? '');
dispatchMetricInspectionOptions({
type: 'APPLY_INSPECTION_OPTIONS',
});
}, [currentMetricName, setAppliedMetricName, dispatchMetricInspectionOptions]);
return ( return (
<div className="inspect-metrics-query-builder"> <div className="inspect-metrics-query-builder">
<div className="inspect-metrics-query-builder-header"> <div className="inspect-metrics-query-builder-header">
@ -31,25 +40,36 @@ function QueryBuilder({
> >
Query Builder Query Builder
</Button> </Button>
<Button
type="primary"
className="stage-run-query"
icon={<Play size={14} />}
onClick={applyInspectionOptions}
>
Stage & Run Query
</Button>
</div> </div>
<Card className="inspect-metrics-query-builder-content"> <Card className="inspect-metrics-query-builder-content">
<MetricNameSearch metricName={metricName} setMetricName={setMetricName} /> <MetricNameSearch
currentMetricName={currentMetricName}
setCurrentMetricName={setCurrentMetricName}
/>
<MetricFilters <MetricFilters
dispatchMetricInspectionOptions={dispatchMetricInspectionOptions} dispatchMetricInspectionOptions={dispatchMetricInspectionOptions}
searchQuery={searchQuery} searchQuery={searchQuery}
metricName={metricName} currentMetricName={currentMetricName}
metricType={metricType || null} metricType={metricType || null}
/> />
<MetricTimeAggregation <MetricTimeAggregation
inspectionStep={inspectionStep} inspectionStep={inspectionStep}
metricInspectionOptions={metricInspectionOptions} currentMetricInspectionOptions={currentMetricInspectionOptions}
dispatchMetricInspectionOptions={dispatchMetricInspectionOptions} dispatchMetricInspectionOptions={dispatchMetricInspectionOptions}
inspectMetricsTimeSeries={inspectMetricsTimeSeries} inspectMetricsTimeSeries={inspectMetricsTimeSeries}
/> />
<MetricSpaceAggregation <MetricSpaceAggregation
inspectionStep={inspectionStep} inspectionStep={inspectionStep}
spaceAggregationLabels={spaceAggregationLabels} spaceAggregationLabels={spaceAggregationLabels}
metricInspectionOptions={metricInspectionOptions} currentMetricInspectionOptions={currentMetricInspectionOptions}
dispatchMetricInspectionOptions={dispatchMetricInspectionOptions} dispatchMetricInspectionOptions={dispatchMetricInspectionOptions}
/> />
</Card> </Card>

View File

@ -11,13 +11,13 @@ function TableView({
setShowExpandedView, setShowExpandedView,
setExpandedViewOptions, setExpandedViewOptions,
isInspectMetricsRefetching, isInspectMetricsRefetching,
metricInspectionOptions, appliedMetricInspectionOptions,
}: TableViewProps): JSX.Element { }: TableViewProps): JSX.Element {
const isSpaceAggregatedWithoutLabel = useMemo( const isSpaceAggregatedWithoutLabel = useMemo(
() => () =>
!!metricInspectionOptions.spaceAggregationOption && !!appliedMetricInspectionOptions.spaceAggregationOption &&
metricInspectionOptions.spaceAggregationLabels.length === 0, appliedMetricInspectionOptions.spaceAggregationLabels.length === 0,
[metricInspectionOptions], [appliedMetricInspectionOptions],
); );
const labelKeys = useMemo(() => { const labelKeys = useMemo(() => {
if (isSpaceAggregatedWithoutLabel) { if (isSpaceAggregatedWithoutLabel) {

View File

@ -72,13 +72,25 @@ export const SPACE_AGGREGATION_OPTIONS_FOR_EXPANDED_VIEW: Record<
}; };
export const INITIAL_INSPECT_METRICS_OPTIONS: MetricInspectionOptions = { export const INITIAL_INSPECT_METRICS_OPTIONS: MetricInspectionOptions = {
timeAggregationOption: undefined, currentOptions: {
timeAggregationInterval: undefined, timeAggregationOption: undefined,
spaceAggregationOption: undefined, timeAggregationInterval: undefined,
spaceAggregationLabels: [], spaceAggregationOption: undefined,
filters: { spaceAggregationLabels: [],
items: [], filters: {
op: 'AND', items: [],
op: 'AND',
},
},
appliedOptions: {
timeAggregationOption: undefined,
timeAggregationInterval: undefined,
spaceAggregationOption: undefined,
spaceAggregationLabels: [],
filters: {
items: [],
op: 'AND',
},
}, },
}; };

View File

@ -43,16 +43,17 @@ export interface GraphViewProps {
showExpandedView: boolean; showExpandedView: boolean;
setShowExpandedView: (showExpandedView: boolean) => void; setShowExpandedView: (showExpandedView: boolean) => void;
setExpandedViewOptions: (options: GraphPopoverOptions | null) => void; setExpandedViewOptions: (options: GraphPopoverOptions | null) => void;
metricInspectionOptions: MetricInspectionOptions; appliedMetricInspectionOptions: InspectOptions;
isInspectMetricsRefetching: boolean; isInspectMetricsRefetching: boolean;
} }
export interface QueryBuilderProps { export interface QueryBuilderProps {
metricName: string | null; currentMetricName: string | null;
setMetricName: (metricName: string) => void; setCurrentMetricName: (metricName: string) => void;
setAppliedMetricName: (metricName: string) => void;
metricType: MetricType | undefined; metricType: MetricType | undefined;
spaceAggregationLabels: string[]; spaceAggregationLabels: string[];
metricInspectionOptions: MetricInspectionOptions; currentMetricInspectionOptions: InspectOptions;
dispatchMetricInspectionOptions: (action: MetricInspectionAction) => void; dispatchMetricInspectionOptions: (action: MetricInspectionAction) => void;
inspectionStep: InspectionStep; inspectionStep: InspectionStep;
inspectMetricsTimeSeries: InspectMetricsSeries[]; inspectMetricsTimeSeries: InspectMetricsSeries[];
@ -60,19 +61,19 @@ export interface QueryBuilderProps {
} }
export interface MetricNameSearchProps { export interface MetricNameSearchProps {
metricName: string | null; currentMetricName: string | null;
setMetricName: (metricName: string) => void; setCurrentMetricName: (metricName: string) => void;
} }
export interface MetricFiltersProps { export interface MetricFiltersProps {
searchQuery: IBuilderQuery; searchQuery: IBuilderQuery;
dispatchMetricInspectionOptions: (action: MetricInspectionAction) => void; dispatchMetricInspectionOptions: (action: MetricInspectionAction) => void;
metricName: string | null; currentMetricName: string | null;
metricType: MetricType | null; metricType: MetricType | null;
} }
export interface MetricTimeAggregationProps { export interface MetricTimeAggregationProps {
metricInspectionOptions: MetricInspectionOptions; currentMetricInspectionOptions: InspectOptions;
dispatchMetricInspectionOptions: (action: MetricInspectionAction) => void; dispatchMetricInspectionOptions: (action: MetricInspectionAction) => void;
inspectionStep: InspectionStep; inspectionStep: InspectionStep;
inspectMetricsTimeSeries: InspectMetricsSeries[]; inspectMetricsTimeSeries: InspectMetricsSeries[];
@ -80,7 +81,7 @@ export interface MetricTimeAggregationProps {
export interface MetricSpaceAggregationProps { export interface MetricSpaceAggregationProps {
spaceAggregationLabels: string[]; spaceAggregationLabels: string[];
metricInspectionOptions: MetricInspectionOptions; currentMetricInspectionOptions: InspectOptions;
dispatchMetricInspectionOptions: (action: MetricInspectionAction) => void; dispatchMetricInspectionOptions: (action: MetricInspectionAction) => void;
inspectionStep: InspectionStep; inspectionStep: InspectionStep;
} }
@ -101,7 +102,7 @@ export enum SpaceAggregationOptions {
AVG_BY = 'avg_by', AVG_BY = 'avg_by',
} }
export interface MetricInspectionOptions { export interface InspectOptions {
timeAggregationOption: TimeAggregationOptions | undefined; timeAggregationOption: TimeAggregationOptions | undefined;
timeAggregationInterval: number | undefined; timeAggregationInterval: number | undefined;
spaceAggregationOption: SpaceAggregationOptions | undefined; spaceAggregationOption: SpaceAggregationOptions | undefined;
@ -109,13 +110,19 @@ export interface MetricInspectionOptions {
filters: TagFilter; filters: TagFilter;
} }
export interface MetricInspectionOptions {
currentOptions: InspectOptions;
appliedOptions: InspectOptions;
}
export type MetricInspectionAction = export type MetricInspectionAction =
| { type: 'SET_TIME_AGGREGATION_OPTION'; payload: TimeAggregationOptions } | { type: 'SET_TIME_AGGREGATION_OPTION'; payload: TimeAggregationOptions }
| { type: 'SET_TIME_AGGREGATION_INTERVAL'; payload: number } | { type: 'SET_TIME_AGGREGATION_INTERVAL'; payload: number }
| { type: 'SET_SPACE_AGGREGATION_OPTION'; payload: SpaceAggregationOptions } | { type: 'SET_SPACE_AGGREGATION_OPTION'; payload: SpaceAggregationOptions }
| { type: 'SET_SPACE_AGGREGATION_LABELS'; payload: string[] } | { type: 'SET_SPACE_AGGREGATION_LABELS'; payload: string[] }
| { type: 'SET_FILTERS'; payload: TagFilter } | { type: 'SET_FILTERS'; payload: TagFilter }
| { type: 'RESET_INSPECTION' }; | { type: 'RESET_INSPECTION' }
| { type: 'APPLY_INSPECTION_OPTIONS' };
export enum InspectionStep { export enum InspectionStep {
TIME_AGGREGATION = 1, TIME_AGGREGATION = 1,
@ -156,7 +163,7 @@ export interface ExpandedViewProps {
options: GraphPopoverOptions | null; options: GraphPopoverOptions | null;
spaceAggregationSeriesMap: Map<string, InspectMetricsSeries[]>; spaceAggregationSeriesMap: Map<string, InspectMetricsSeries[]>;
step: InspectionStep; step: InspectionStep;
metricInspectionOptions: MetricInspectionOptions; appliedMetricInspectionOptions: InspectOptions;
timeAggregatedSeriesMap: Map<number, GraphPopoverData[]>; timeAggregatedSeriesMap: Map<number, GraphPopoverData[]>;
} }
@ -165,7 +172,7 @@ export interface TableViewProps {
inspectMetricsTimeSeries: InspectMetricsSeries[]; inspectMetricsTimeSeries: InspectMetricsSeries[];
setShowExpandedView: (showExpandedView: boolean) => void; setShowExpandedView: (showExpandedView: boolean) => void;
setExpandedViewOptions: (options: GraphPopoverOptions | null) => void; setExpandedViewOptions: (options: GraphPopoverOptions | null) => void;
metricInspectionOptions: MetricInspectionOptions; appliedMetricInspectionOptions: InspectOptions;
isInspectMetricsRefetching: boolean; isInspectMetricsRefetching: boolean;
} }

View File

@ -27,30 +27,55 @@ const metricInspectionReducer = (
case 'SET_TIME_AGGREGATION_OPTION': case 'SET_TIME_AGGREGATION_OPTION':
return { return {
...state, ...state,
timeAggregationOption: action.payload, currentOptions: {
...state.currentOptions,
timeAggregationOption: action.payload,
},
}; };
case 'SET_TIME_AGGREGATION_INTERVAL': case 'SET_TIME_AGGREGATION_INTERVAL':
return { return {
...state, ...state,
timeAggregationInterval: action.payload, currentOptions: {
...state.currentOptions,
timeAggregationInterval: action.payload,
},
}; };
case 'SET_SPACE_AGGREGATION_OPTION': case 'SET_SPACE_AGGREGATION_OPTION':
return { return {
...state, ...state,
spaceAggregationOption: action.payload, currentOptions: {
...state.currentOptions,
spaceAggregationOption: action.payload,
},
}; };
case 'SET_SPACE_AGGREGATION_LABELS': case 'SET_SPACE_AGGREGATION_LABELS':
return { return {
...state, ...state,
spaceAggregationLabels: action.payload, currentOptions: {
...state.currentOptions,
spaceAggregationLabels: action.payload,
},
}; };
case 'SET_FILTERS': case 'SET_FILTERS':
return { return {
...state, ...state,
filters: action.payload, currentOptions: {
...state.currentOptions,
filters: action.payload,
},
};
case 'APPLY_INSPECTION_OPTIONS':
return {
...state,
appliedOptions: {
...state.appliedOptions,
...state.currentOptions,
},
}; };
case 'RESET_INSPECTION': case 'RESET_INSPECTION':
return { ...INITIAL_INSPECT_METRICS_OPTIONS }; return {
...INITIAL_INSPECT_METRICS_OPTIONS,
};
default: default:
return state; return state;
} }
@ -84,7 +109,7 @@ export function useInspectMetrics(
metricName: metricName ?? '', metricName: metricName ?? '',
start, start,
end, end,
filters: metricInspectionOptions.filters, filters: metricInspectionOptions.appliedOptions.filters,
}, },
{ {
enabled: !!metricName, enabled: !!metricName,
@ -117,13 +142,26 @@ export function useInspectMetrics(
); );
// Evaluate inspection step // Evaluate inspection step
const inspectionStep = useMemo(() => { const currentInspectionStep = useMemo(() => {
if (metricInspectionOptions.spaceAggregationOption) { if (metricInspectionOptions.currentOptions.spaceAggregationOption) {
return InspectionStep.COMPLETED; return InspectionStep.COMPLETED;
} }
if ( if (
metricInspectionOptions.timeAggregationOption && metricInspectionOptions.currentOptions.timeAggregationOption &&
metricInspectionOptions.timeAggregationInterval metricInspectionOptions.currentOptions.timeAggregationInterval
) {
return InspectionStep.SPACE_AGGREGATION;
}
return InspectionStep.TIME_AGGREGATION;
}, [metricInspectionOptions]);
const appliedInspectionStep = useMemo(() => {
if (metricInspectionOptions.appliedOptions.spaceAggregationOption) {
return InspectionStep.COMPLETED;
}
if (
metricInspectionOptions.appliedOptions.timeAggregationOption &&
metricInspectionOptions.appliedOptions.timeAggregationInterval
) { ) {
return InspectionStep.SPACE_AGGREGATION; return InspectionStep.SPACE_AGGREGATION;
} }
@ -149,23 +187,26 @@ export function useInspectMetrics(
// Apply time aggregation once required options are set // Apply time aggregation once required options are set
if ( if (
inspectionStep >= InspectionStep.SPACE_AGGREGATION && appliedInspectionStep >= InspectionStep.SPACE_AGGREGATION &&
metricInspectionOptions.timeAggregationOption && metricInspectionOptions.appliedOptions.timeAggregationOption &&
metricInspectionOptions.timeAggregationInterval metricInspectionOptions.appliedOptions.timeAggregationInterval
) { ) {
const { const {
timeAggregatedSeries, timeAggregatedSeries,
timeAggregatedSeriesMap, timeAggregatedSeriesMap,
} = applyTimeAggregation(inspectMetricsTimeSeries, metricInspectionOptions); } = applyTimeAggregation(
inspectMetricsTimeSeries,
metricInspectionOptions.appliedOptions,
);
timeSeries = timeAggregatedSeries; timeSeries = timeAggregatedSeries;
setTimeAggregatedSeriesMap(timeAggregatedSeriesMap); setTimeAggregatedSeriesMap(timeAggregatedSeriesMap);
setAggregatedTimeSeries(timeSeries); setAggregatedTimeSeries(timeSeries);
} }
// Apply space aggregation // Apply space aggregation
if (inspectionStep === InspectionStep.COMPLETED) { if (appliedInspectionStep === InspectionStep.COMPLETED) {
const { aggregatedSeries, spaceAggregatedSeriesMap } = applySpaceAggregation( const { aggregatedSeries, spaceAggregatedSeriesMap } = applySpaceAggregation(
timeSeries, timeSeries,
metricInspectionOptions, metricInspectionOptions.appliedOptions,
); );
timeSeries = aggregatedSeries; timeSeries = aggregatedSeries;
setSpaceAggregatedSeriesMap(spaceAggregatedSeriesMap); setSpaceAggregatedSeriesMap(spaceAggregatedSeriesMap);
@ -186,7 +227,7 @@ export function useInspectMetrics(
const rawData = [timestamps, ...timeseriesArray]; const rawData = [timestamps, ...timeseriesArray];
return rawData.map((series) => new Float64Array(series)); return rawData.map((series) => new Float64Array(series));
}, [inspectMetricsTimeSeries, inspectionStep, metricInspectionOptions]); }, [inspectMetricsTimeSeries, appliedInspectionStep, metricInspectionOptions]);
const spaceAggregationLabels = useMemo(() => { const spaceAggregationLabels = useMemo(() => {
const labels = new Set<string>(); const labels = new Set<string>();
@ -216,7 +257,7 @@ export function useInspectMetrics(
spaceAggregationLabels, spaceAggregationLabels,
metricInspectionOptions, metricInspectionOptions,
dispatchMetricInspectionOptions, dispatchMetricInspectionOptions,
inspectionStep, inspectionStep: currentInspectionStep,
isInspectMetricsRefetching, isInspectMetricsRefetching,
spaceAggregatedSeriesMap, spaceAggregatedSeriesMap,
aggregatedTimeSeries, aggregatedTimeSeries,

View File

@ -29,8 +29,8 @@ import {
GraphPopoverData, GraphPopoverData,
GraphPopoverOptions, GraphPopoverOptions,
InspectionStep, InspectionStep,
InspectOptions,
MetricFiltersProps, MetricFiltersProps,
MetricInspectionOptions,
MetricNameSearchProps, MetricNameSearchProps,
MetricSpaceAggregationProps, MetricSpaceAggregationProps,
MetricTimeAggregationProps, MetricTimeAggregationProps,
@ -74,13 +74,13 @@ export function getDefaultTimeAggregationInterval(
} }
export function MetricNameSearch({ export function MetricNameSearch({
metricName, currentMetricName,
setMetricName, setCurrentMetricName,
}: MetricNameSearchProps): JSX.Element { }: MetricNameSearchProps): JSX.Element {
const [searchText, setSearchText] = useState(metricName); const [searchText, setSearchText] = useState(currentMetricName);
const handleSetMetricName = (value: BaseAutocompleteData): void => { const handleSetMetricName = (value: BaseAutocompleteData): void => {
setMetricName(value.key); setCurrentMetricName(value.key);
}; };
const handleChange = (value: BaseAutocompleteData): void => { const handleChange = (value: BaseAutocompleteData): void => {
@ -106,19 +106,19 @@ export function MetricNameSearch({
export function MetricFilters({ export function MetricFilters({
dispatchMetricInspectionOptions, dispatchMetricInspectionOptions,
searchQuery, searchQuery,
metricName, currentMetricName,
metricType, metricType,
}: MetricFiltersProps): JSX.Element { }: MetricFiltersProps): JSX.Element {
const aggregateAttribute = useMemo( const aggregateAttribute = useMemo(
() => ({ () => ({
key: metricName ?? '', key: currentMetricName ?? '',
dataType: DataTypes.String, dataType: DataTypes.String,
type: metricType, type: metricType,
isColumn: true, isColumn: true,
isJSON: false, isJSON: false,
id: `${metricName}--${DataTypes.String}--${metricType}--true`, id: `${currentMetricName}--${DataTypes.String}--${metricType}--true`,
}), }),
[metricName, metricType], [currentMetricName, metricType],
); );
const [currentQuery, setCurrentQuery] = useState<IBuilderQuery>({ const [currentQuery, setCurrentQuery] = useState<IBuilderQuery>({
@ -169,7 +169,7 @@ export function MetricFilters({
} }
export function MetricTimeAggregation({ export function MetricTimeAggregation({
metricInspectionOptions, currentMetricInspectionOptions,
dispatchMetricInspectionOptions, dispatchMetricInspectionOptions,
inspectionStep, inspectionStep,
inspectMetricsTimeSeries, inspectMetricsTimeSeries,
@ -190,14 +190,14 @@ export function MetricTimeAggregation({
<div className="inspect-metrics-input-group"> <div className="inspect-metrics-input-group">
<Typography.Text>Align with</Typography.Text> <Typography.Text>Align with</Typography.Text>
<Select <Select
value={metricInspectionOptions.timeAggregationOption} value={currentMetricInspectionOptions.timeAggregationOption}
onChange={(value): void => { onChange={(value): void => {
dispatchMetricInspectionOptions({ dispatchMetricInspectionOptions({
type: 'SET_TIME_AGGREGATION_OPTION', type: 'SET_TIME_AGGREGATION_OPTION',
payload: value, payload: value,
}); });
// set the time aggregation interval to the default value if it is not set // set the time aggregation interval to the default value if it is not set
if (!metricInspectionOptions.timeAggregationInterval) { if (!currentMetricInspectionOptions.timeAggregationInterval) {
dispatchMetricInspectionOptions({ dispatchMetricInspectionOptions({
type: 'SET_TIME_AGGREGATION_INTERVAL', type: 'SET_TIME_AGGREGATION_INTERVAL',
payload: getDefaultTimeAggregationInterval( payload: getDefaultTimeAggregationInterval(
@ -221,7 +221,7 @@ export function MetricTimeAggregation({
<Input <Input
type="number" type="number"
className="no-arrows-input" className="no-arrows-input"
value={metricInspectionOptions.timeAggregationInterval} value={currentMetricInspectionOptions.timeAggregationInterval}
placeholder="Select interval..." placeholder="Select interval..."
suffix="seconds" suffix="seconds"
onChange={(e): void => { onChange={(e): void => {
@ -240,7 +240,7 @@ export function MetricTimeAggregation({
export function MetricSpaceAggregation({ export function MetricSpaceAggregation({
spaceAggregationLabels, spaceAggregationLabels,
metricInspectionOptions, currentMetricInspectionOptions,
dispatchMetricInspectionOptions, dispatchMetricInspectionOptions,
inspectionStep, inspectionStep,
}: MetricSpaceAggregationProps): JSX.Element { }: MetricSpaceAggregationProps): JSX.Element {
@ -259,7 +259,7 @@ export function MetricSpaceAggregation({
<div className="metric-space-aggregation-content"> <div className="metric-space-aggregation-content">
<div className="metric-space-aggregation-content-left"> <div className="metric-space-aggregation-content-left">
<Select <Select
value={metricInspectionOptions.spaceAggregationOption} value={currentMetricInspectionOptions.spaceAggregationOption}
placeholder="Select option" placeholder="Select option"
onChange={(value): void => { onChange={(value): void => {
dispatchMetricInspectionOptions({ dispatchMetricInspectionOptions({
@ -282,7 +282,7 @@ export function MetricSpaceAggregation({
mode="multiple" mode="multiple"
style={{ width: '100%' }} style={{ width: '100%' }}
placeholder="Search for attributes..." placeholder="Search for attributes..."
value={metricInspectionOptions.spaceAggregationLabels} value={currentMetricInspectionOptions.spaceAggregationLabels}
onChange={(value): void => { onChange={(value): void => {
dispatchMetricInspectionOptions({ dispatchMetricInspectionOptions({
type: 'SET_SPACE_AGGREGATION_LABELS', type: 'SET_SPACE_AGGREGATION_LABELS',
@ -338,7 +338,7 @@ export function applyFilters(
export function applyTimeAggregation( export function applyTimeAggregation(
inspectMetricsTimeSeries: InspectMetricsSeries[], inspectMetricsTimeSeries: InspectMetricsSeries[],
metricInspectionOptions: MetricInspectionOptions, appliedMetricInspectionOptions: InspectOptions,
): { ): {
timeAggregatedSeries: InspectMetricsSeries[]; timeAggregatedSeries: InspectMetricsSeries[];
timeAggregatedSeriesMap: Map<number, GraphPopoverData[]>; timeAggregatedSeriesMap: Map<number, GraphPopoverData[]>;
@ -346,7 +346,7 @@ export function applyTimeAggregation(
const { const {
timeAggregationOption, timeAggregationOption,
timeAggregationInterval, timeAggregationInterval,
} = metricInspectionOptions; } = appliedMetricInspectionOptions;
if (!timeAggregationInterval) { if (!timeAggregationInterval) {
return { return {
@ -431,7 +431,7 @@ export function applyTimeAggregation(
export function applySpaceAggregation( export function applySpaceAggregation(
inspectMetricsTimeSeries: InspectMetricsSeries[], inspectMetricsTimeSeries: InspectMetricsSeries[],
metricInspectionOptions: MetricInspectionOptions, appliedMetricInspectionOptions: InspectOptions,
): { ): {
aggregatedSeries: InspectMetricsSeries[]; aggregatedSeries: InspectMetricsSeries[];
spaceAggregatedSeriesMap: Map<string, InspectMetricsSeries[]>; spaceAggregatedSeriesMap: Map<string, InspectMetricsSeries[]>;
@ -441,7 +441,7 @@ export function applySpaceAggregation(
inspectMetricsTimeSeries.forEach((series) => { inspectMetricsTimeSeries.forEach((series) => {
// Create composite key from selected labels // Create composite key from selected labels
const key = metricInspectionOptions.spaceAggregationLabels const key = appliedMetricInspectionOptions.spaceAggregationLabels
.map((label) => `${label}:${series.labels[label]}`) .map((label) => `${label}:${series.labels[label]}`)
.join(','); .join(',');
@ -476,7 +476,7 @@ export function applySpaceAggregation(
([timestamp, values]) => { ([timestamp, values]) => {
let aggregatedValue: number; let aggregatedValue: number;
switch (metricInspectionOptions.spaceAggregationOption) { switch (appliedMetricInspectionOptions.spaceAggregationOption) {
case SpaceAggregationOptions.SUM_BY: case SpaceAggregationOptions.SUM_BY:
aggregatedValue = values.reduce((sum, val) => sum + val, 0); aggregatedValue = values.reduce((sum, val) => sum + val, 0);
break; break;
@ -730,11 +730,11 @@ export function getTimeSeriesLabel(
export function HoverPopover({ export function HoverPopover({
options, options,
step, step,
metricInspectionOptions, appliedMetricInspectionOptions,
}: { }: {
options: GraphPopoverOptions; options: GraphPopoverOptions;
step: InspectionStep; step: InspectionStep;
metricInspectionOptions: MetricInspectionOptions; appliedMetricInspectionOptions: InspectOptions;
}): JSX.Element { }): JSX.Element {
const closestTimestamp = useMemo(() => { const closestTimestamp = useMemo(() => {
if (!options.timeSeries) { if (!options.timeSeries) {
@ -762,7 +762,7 @@ export function HoverPopover({
const title = useMemo(() => { const title = useMemo(() => {
if ( if (
step === InspectionStep.COMPLETED && step === InspectionStep.COMPLETED &&
metricInspectionOptions.spaceAggregationLabels.length === 0 appliedMetricInspectionOptions.spaceAggregationLabels.length === 0
) { ) {
return undefined; return undefined;
} }
@ -776,7 +776,7 @@ export function HoverPopover({
options.timeSeries, options.timeSeries,
options.timeSeries?.strokeColor, options.timeSeries?.strokeColor,
); );
}, [step, options.timeSeries, metricInspectionOptions]); }, [step, options.timeSeries, appliedMetricInspectionOptions]);
return ( return (
<Card <Card
@ -846,3 +846,26 @@ export function onGraphHover(
timeSeries: series, timeSeries: series,
}); });
} }
export function useMetricName(
metricName: string | null,
): {
currentMetricName: string | null;
setCurrentMetricName: (metricName: string | null) => void;
appliedMetricName: string | null;
setAppliedMetricName: (metricName: string | null) => void;
} {
const [currentMetricName, setCurrentMetricName] = useState<string | null>(
metricName,
);
const [appliedMetricName, setAppliedMetricName] = useState<string | null>(
metricName,
);
return {
currentMetricName,
setCurrentMetricName,
appliedMetricName,
setAppliedMetricName,
};
}

View File

@ -292,8 +292,6 @@ function Summary(): JSX.Element {
], ],
); );
console.log(searchQuery.filters);
return ( return (
<Sentry.ErrorBoundary fallback={<ErrorBoundaryFallback />}> <Sentry.ErrorBoundary fallback={<ErrorBoundaryFallback />}>
<div className="metrics-explorer-summary-tab"> <div className="metrics-explorer-summary-tab">