| 
									
										
										
										
											2019-03-15 00:20:33 +08:00
										 |  |  | import _ from 'lodash'; | 
					
						
							| 
									
										
										
										
											2019-10-31 17:48:05 +08:00
										 |  |  | import { DataQuery } from '@grafana/data'; | 
					
						
							| 
									
										
										
										
											2019-03-15 00:20:33 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-25 19:25:39 +08:00
										 |  |  | export const getNextRefIdChar = (queries: DataQuery[]): string | undefined => { | 
					
						
							| 
									
										
										
										
											2019-03-15 00:20:33 +08:00
										 |  |  |   const letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return _.find(letters, refId => { | 
					
						
							|  |  |  |     return _.every(queries, other => { | 
					
						
							|  |  |  |       return other.refId !== refId; | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2019-10-18 19:09:55 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | export function addQuery(queries: DataQuery[], query?: Partial<DataQuery>): DataQuery[] { | 
					
						
							|  |  |  |   const q = query || {}; | 
					
						
							|  |  |  |   q.refId = getNextRefIdChar(queries); | 
					
						
							|  |  |  |   return [...queries, q as DataQuery]; | 
					
						
							|  |  |  | } |