| 
									
										
										
										
											2020-06-18 20:31:30 +08:00
										 |  |  | import React, { useCallback, useState } from 'react'; | 
					
						
							|  |  |  | import { connect, MapStateToProps, useDispatch } from 'react-redux'; | 
					
						
							| 
									
										
										
										
											2020-02-14 21:14:38 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-05 03:53:44 +08:00
										 |  |  | import { DashboardModel, PanelModel } from 'app/features/dashboard/state'; | 
					
						
							| 
									
										
										
										
											2020-06-18 20:31:30 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | import { PanelPlugin } from '@grafana/data'; | 
					
						
							| 
									
										
										
										
											2020-04-15 22:51:51 +08:00
										 |  |  | import { StoreState } from 'app/types'; | 
					
						
							| 
									
										
										
										
											2020-05-13 19:03:34 +08:00
										 |  |  | import { GetDataOptions } from '../../state/PanelQueryRunner'; | 
					
						
							| 
									
										
										
										
											2020-06-18 20:31:30 +08:00
										 |  |  | import { usePanelLatestData } from '../PanelEditor/usePanelLatestData'; | 
					
						
							|  |  |  | import { InspectContent } from './InspectContent'; | 
					
						
							|  |  |  | import { useDatasourceMetadata, useInspectTabs } from './hooks'; | 
					
						
							|  |  |  | import { InspectTab } from './types'; | 
					
						
							|  |  |  | import { updateLocation } from 'app/core/actions'; | 
					
						
							| 
									
										
										
										
											2019-11-05 03:53:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-15 22:51:51 +08:00
										 |  |  | interface OwnProps { | 
					
						
							| 
									
										
										
										
											2019-11-05 03:53:44 +08:00
										 |  |  |   dashboard: DashboardModel; | 
					
						
							|  |  |  |   panel: PanelModel; | 
					
						
							| 
									
										
										
										
											2020-07-09 21:16:35 +08:00
										 |  |  |   defaultTab?: InspectTab; | 
					
						
							| 
									
										
										
										
											2020-04-15 22:51:51 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export interface ConnectedProps { | 
					
						
							|  |  |  |   plugin?: PanelPlugin | null; | 
					
						
							| 
									
										
										
										
											2019-11-05 03:53:44 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-15 22:51:51 +08:00
										 |  |  | export type Props = OwnProps & ConnectedProps; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-18 20:31:30 +08:00
										 |  |  | const PanelInspectorUnconnected: React.FC<Props> = ({ panel, dashboard, defaultTab, plugin }) => { | 
					
						
							| 
									
										
										
											
												Chore: Fix all Typescript strict null errors  (#26204)
* Chore: Fix typescript strict null errors
* Added new limit
* Fixed ts issue
* fixed tests
* trying to fix type inference
* Fixing more ts errors
* Revert tsconfig option
* Fix
* Fixed code
* More fixes
* fix tests
* Updated snapshot
* Chore: More ts strict null fixes
* More fixes in some really messed up azure config components
* More fixes, current count: 441
* 419
* More fixes
* Fixed invalid initial state in explore
* Fixing tests
* Fixed tests
* Explore fix
* More fixes
* Progress
* Sub 300
* Now at 218
* Progress
* Update
* Progress
* Updated tests
* at 159
* fixed tests
* Progress
* YAy blow 100! at 94
* 10,9,8,7,6,5,4,3,2,1... lift off
* Fixed tests
* Fixed more type errors
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
											
										 
											2020-07-10 18:46:59 +08:00
										 |  |  |   if (!plugin) { | 
					
						
							|  |  |  |     return null; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-18 20:31:30 +08:00
										 |  |  |   const dispatch = useDispatch(); | 
					
						
							|  |  |  |   const [dataOptions, setDataOptions] = useState<GetDataOptions>({ | 
					
						
							|  |  |  |     withTransforms: false, | 
					
						
							|  |  |  |     withFieldConfig: false, | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  |   const { data, isLoading, error } = usePanelLatestData(panel, dataOptions); | 
					
						
							|  |  |  |   const metaDs = useDatasourceMetadata(data); | 
					
						
							|  |  |  |   const tabs = useInspectTabs(plugin, dashboard, error, metaDs); | 
					
						
							|  |  |  |   const onClose = useCallback(() => { | 
					
						
							|  |  |  |     dispatch( | 
					
						
							|  |  |  |       updateLocation({ | 
					
						
							|  |  |  |         query: { inspect: null, inspectTab: null }, | 
					
						
							|  |  |  |         partial: true, | 
					
						
							|  |  |  |       }) | 
					
						
							| 
									
										
										
										
											2020-01-29 22:41:25 +08:00
										 |  |  |     ); | 
					
						
							| 
									
										
										
										
											2020-06-18 20:31:30 +08:00
										 |  |  |   }, [updateLocation]); | 
					
						
							| 
									
										
										
										
											2020-04-15 22:51:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-18 20:31:30 +08:00
										 |  |  |   return ( | 
					
						
							|  |  |  |     <InspectContent | 
					
						
							|  |  |  |       dashboard={dashboard} | 
					
						
							|  |  |  |       panel={panel} | 
					
						
							|  |  |  |       plugin={plugin} | 
					
						
							|  |  |  |       defaultTab={defaultTab} | 
					
						
							|  |  |  |       tabs={tabs} | 
					
						
							|  |  |  |       data={data} | 
					
						
							|  |  |  |       isDataLoading={isLoading} | 
					
						
							|  |  |  |       dataOptions={dataOptions} | 
					
						
							|  |  |  |       onDataOptionsChange={setDataOptions} | 
					
						
							|  |  |  |       metadataDatasource={metaDs} | 
					
						
							|  |  |  |       onClose={onClose} | 
					
						
							|  |  |  |     /> | 
					
						
							|  |  |  |   ); | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2020-03-18 20:00:14 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-15 22:51:51 +08:00
										 |  |  | const mapStateToProps: MapStateToProps<ConnectedProps, OwnProps, StoreState> = (state, props) => { | 
					
						
							|  |  |  |   const panelState = state.dashboard.panels[props.panel.id]; | 
					
						
							|  |  |  |   if (!panelState) { | 
					
						
							|  |  |  |     return { plugin: null }; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-19 21:39:44 +08:00
										 |  |  |   return { | 
					
						
							| 
									
										
										
										
											2020-04-15 22:51:51 +08:00
										 |  |  |     plugin: panelState.plugin, | 
					
						
							| 
									
										
										
										
											2020-02-19 21:39:44 +08:00
										 |  |  |   }; | 
					
						
							| 
									
										
										
										
											2020-04-15 22:51:51 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const PanelInspector = connect(mapStateToProps)(PanelInspectorUnconnected); |