SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.
TypeScript apmapplication-monitoringdistributed-tracinggogood-first-issuejaegerloglogsmetricsmonitoringnextjsobservabilityopen-sourceopentelemetryprometheusreactreactjsself-hostedtracingtypescript
import { useMemo } from 'react';
import {
VARIABLE_TYPE_EVENT_LABEL,
type VariableFormModel,
} from '../../../DashboardSettings/Variables/variableFormModel';
import type {
VariableSelection,
VariableSelectionMap,
} from '../../selectionTypes';
import {
reconcileWithOptions,
resolveDefaultSelection,
} from '../../utils/resolveVariableSelection';
import { useAutoSelect } from '../../hooks/useAutoSelect';
import ValueSelector from './ValueSelector';
import { useVariableOptions } from '../../hooks/useVariableOptions';
interface VariableValueControlProps {
variable: VariableFormModel;
/** All variables (Dynamic scopes its options by sibling selections). */
variables: VariableFormModel[];
/** All current selections (fed to the Query request payload). */
selections: VariableSelectionMap;
selection: VariableSelection;
onChange: (selection: VariableSelection) => void;
/** Batched auto-selection fill applied when options resolve. */
onAutoSelect: (selection: VariableSelection) => void;
}
/**
* The single value picker for QUERY / CUSTOM / DYNAMIC variables. Options + fetch
* state come from {@link useVariableOptions}; this component only reconciles the
* selection against the options and renders — the view is decoupled from how the
* options are sourced (Container/Presentational).
*/
function VariableValueControl({
variable,
variables,
selections,
selection,
onChange,
onAutoSelect,
}: VariableValueControlProps): JSX.Element {
const { options, loading, errorMessage, onRetry, isRetryable, dynamic } =
useVariableOptions(variable, variables, selections);
useAutoSelect(variable, options, selection, onAutoSelect);
// The selection to fall back to when the multi-select closes empty
const emptyFallback = useMemo<VariableSelection>(() => {
const seed = resolveDefaultSelection(variable);
return reconcileWithOptions(variable, seed, options) ?? seed;
}, [variable, options]);
return (
<ValueSelector
options={options}
variableType={VARIABLE_TYPE_EVENT_LABEL[variable.type]}
multiSelect={variable.multiSelect}
showAllOption={variable.showAllOption}
loading={loading}
errorMessage={errorMessage}
onRetry={onRetry}
isRetryable={isRetryable}
dynamic={dynamic}
selection={selection}
onChange={onChange}
emptyFallback={emptyFallback}
testId={`variable-select-${variable.name}`}
/>
);
}
export default VariableValueControl;