@@ -2,7 +2,7 @@ import React from 'react';
22import { AsyncSelect , InlineField , Select } from '@grafana/ui' ;
33import { SelectableValue } from '@grafana/data' ;
44import { AutoCompleteEditorProps , EditorProps } from './types' ;
5- import { get , update } from 'lodash' ;
5+ import { get , update , isEmpty } from 'lodash' ;
66import { DataSource } from '../DataSource' ;
77import { combinedDesc } from 'graphspecs' ;
88
@@ -40,6 +40,19 @@ export const AsyncAutocomplete = ({
4040 if ( contextPath === 'params.metric' || contextPath === 'params.graph' ) {
4141 contextKey += contextPath ;
4242 }
43+ // recover graph_name
44+ if ( contextPath === 'params.graph_name' && typeof query . graph === 'number' && query . params . graphMode === 'template' ) {
45+ autocompleter ( '' ) . then ( ( res ) => {
46+ console . log ( 'auto qu' , res , query ) ;
47+ const graph_index = query . graph ;
48+ delete query . graph ;
49+ if ( res . length > graph_index ) {
50+ onSelection ( res [ graph_index ] ) ;
51+ const col = get ( query , 'params.selections.' + contextPath , { } ) ;
52+ console . log ( 'up' , col , isEmpty ( col ) ) ;
53+ }
54+ } ) ;
55+ }
4356
4457 return (
4558 < AsyncSelect
@@ -100,16 +113,13 @@ export const GraphSelect = (props: EditorProps) => {
100113 }
101114
102115 const label = titleCase ( graphMode ) ;
116+ const autocompleter = vsAutocomplete ( props . datasource , completionVS ) ;
103117
104118 return (
105119 < >
106120 < GraphType contextPath = "params.graphMode" { ...props } autocompleter = { ( _ ) => new Promise ( ( ) => ( { } ) ) } />
107121 < InlineField labelWidth = { 14 } label = { label } >
108- < AsyncAutocomplete
109- autocompleter = { vsAutocomplete ( props . datasource , completionVS ) }
110- contextPath = { 'params.graph_name' }
111- { ...props }
112- />
122+ < AsyncAutocomplete autocompleter = { autocompleter } contextPath = { 'params.graph_name' } { ...props } />
113123 </ InlineField >
114124 </ >
115125 ) ;
0 commit comments