/usr/share/grafana/public/app/plugins/datasource/graphite/components
import { debounce } from 'lodash'; import { useCallback, useMemo } from 'react'; import { SelectableValue } from '@grafana/data'; import { SegmentAsync } from '@grafana/ui'; import { actions } from '../state/actions'; import { useDispatch } from '../state/context'; import { getAltSegmentsSelectables } from '../state/providers'; import { GraphiteQueryEditorState } from '../state/store'; import { GraphiteSegment } from '../types'; type Props = { segment: GraphiteSegment; metricIndex: number; state: GraphiteQueryEditorState; }; /** * Represents a single metric node in the metric path at the given index. Allows to change the metric name to one of the * provided options or a custom value. * * Options for tag names and metric names are reloaded while user is typing with backend taking care of auto-complete * (auto-complete cannot be implemented in front-end because backend returns only limited number of entries) * * getAltSegmentsSelectables() also returns list of tags for segment with index=0. Once a tag is selected the editor * enters tag-adding mode (see SeriesSection and GraphiteQueryModel.seriesByTagUsed). */ export function MetricSegment({ metricIndex, segment, state }: Props) { const dispatch = useDispatch(); const loadOptions = useCallback( (value: string | undefined) => { return getAltSegmentsSelectables(state, metricIndex, value || ''); }, [state, metricIndex] ); const debouncedLoadOptions = useMemo(() => debounce(loadOptions, 200, { leading: true }), [loadOptions]); const onSegmentChanged = useCallback( (selectableValue: SelectableValue<GraphiteSegment | string>) => { // selectableValue.value is always defined because emptyValues are not allowed in SegmentAsync by default dispatch(actions.segmentValueChanged({ segment: selectableValue.value!, index: metricIndex })); }, [dispatch, metricIndex] ); // segmentValueChanged action will destroy SegmentAsync immediately if a tag is selected. To give time // for the clean up the action is debounced. const onSegmentChangedDebounced = useMemo(() => debounce(onSegmentChanged, 100), [onSegmentChanged]); return ( <SegmentAsync<GraphiteSegment | string> value={segment.value} inputMinWidth={150} allowCustomValue={true} loadOptions={debouncedLoadOptions} reloadOptionsOnChange={true} onChange={onSegmentChangedDebounced} /> ); }
.
Edit
..
Edit
AddGraphiteFunction.tsx
Edit
AnnotationsEditor.tsx
Edit
FunctionEditor.test.tsx
Edit
FunctionEditor.tsx
Edit
FunctionEditorControls.tsx
Edit
FunctionParamEditor.tsx
Edit
FunctionsSection.tsx
Edit
GraphiteFunctionEditor.tsx
Edit
GraphiteQueryEditor.tsx
Edit
GraphiteTextEditor.tsx
Edit
GraphiteVariableEditor.tsx
Edit
MetricSegment.tsx
Edit
MetricTankMetaInspector.tsx
Edit
MetricsSection.tsx
Edit
PlayButton.tsx
Edit
SeriesSection.tsx
Edit
TagEditor.tsx
Edit
TagsSection.tsx
Edit
helpers.test.ts
Edit
helpers.ts
Edit