2020-06-18 07:31:30 -05:00
|
|
|
import React, { useCallback, useState } from 'react';
|
|
|
|
import { connect, MapStateToProps, useDispatch } from 'react-redux';
|
2020-02-14 07:14:38 -06:00
|
|
|
|
2019-11-04 13:53:44 -06:00
|
|
|
import { DashboardModel, PanelModel } from 'app/features/dashboard/state';
|
2020-06-18 07:31:30 -05:00
|
|
|
|
|
|
|
import { PanelPlugin } from '@grafana/data';
|
2020-04-15 09:51:51 -05:00
|
|
|
import { StoreState } from 'app/types';
|
2020-05-13 06:03:34 -05:00
|
|
|
import { GetDataOptions } from '../../state/PanelQueryRunner';
|
2020-06-18 07:31:30 -05: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-04 13:53:44 -06:00
|
|
|
|
2020-04-15 09:51:51 -05:00
|
|
|
interface OwnProps {
|
2019-11-04 13:53:44 -06:00
|
|
|
dashboard: DashboardModel;
|
|
|
|
panel: PanelModel;
|
2020-07-09 08:16:35 -05:00
|
|
|
defaultTab?: InspectTab;
|
2020-04-15 09:51:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface ConnectedProps {
|
|
|
|
plugin?: PanelPlugin | null;
|
2019-11-04 13:53:44 -06:00
|
|
|
}
|
|
|
|
|
2020-04-15 09:51:51 -05:00
|
|
|
export type Props = OwnProps & ConnectedProps;
|
|
|
|
|
2020-06-18 07:31:30 -05: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 05:46:59 -05:00
|
|
|
if (!plugin) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-06-18 07:31:30 -05: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 08:41:25 -06:00
|
|
|
);
|
2020-06-18 07:31:30 -05:00
|
|
|
}, [updateLocation]);
|
2020-04-15 09:51:51 -05:00
|
|
|
|
2020-06-18 07:31:30 -05: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 07:00:14 -05:00
|
|
|
|
2020-04-15 09:51:51 -05: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 07:39:44 -06:00
|
|
|
return {
|
2020-04-15 09:51:51 -05:00
|
|
|
plugin: panelState.plugin,
|
2020-02-19 07:39:44 -06:00
|
|
|
};
|
2020-04-15 09:51:51 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
export const PanelInspector = connect(mapStateToProps)(PanelInspectorUnconnected);
|