mirror of https://github.com/grafana/grafana
Queries: Extract queries from dashboard (#29349)
* Moving query stuff out of dashboard folder * Moved more stuff * Moving more stuff * Update * WIP test page * Minor change * Before big changes * Fixed testpull/29420/head
parent
43bd492565
commit
2179aa0fa7
@ -0,0 +1,16 @@ |
||||
import React, { PureComponent } from 'react'; |
||||
import { QueriesTab } from 'app/features/query/components/QueriesTab'; |
||||
import { DashboardModel, PanelModel } from '../../state'; |
||||
|
||||
interface Props { |
||||
panel: PanelModel; |
||||
dashboard: DashboardModel; |
||||
} |
||||
|
||||
export class PanelEditorQueries extends PureComponent<Props> { |
||||
render() { |
||||
const { panel, dashboard } = this.props; |
||||
|
||||
return <QueriesTab panel={panel} dashboard={dashboard} />; |
||||
} |
||||
} |
||||
@ -1,7 +1,7 @@ |
||||
import { MetaAnalyticsEventName, reportMetaAnalytics } from '@grafana/runtime'; |
||||
import { CoreApp, DataQueryRequest, DataSourceApi, dateTime, LoadingState, PanelData } from '@grafana/data'; |
||||
import { emitDataRequestEvent } from './analyticsProcessor'; |
||||
import { DashboardModel } from './DashboardModel'; |
||||
import { emitDataRequestEvent } from './queryAnalytics'; |
||||
import { DashboardModel } from '../../dashboard/state/DashboardModel'; |
||||
|
||||
beforeEach(() => { |
||||
jest.clearAllMocks(); |
||||
@ -0,0 +1,56 @@ |
||||
import { getDashboardSrv } from '../../dashboard/services/DashboardSrv'; |
||||
import { PanelData, LoadingState, DataSourceApi, CoreApp, urlUtil } from '@grafana/data'; |
||||
import { reportMetaAnalytics, MetaAnalyticsEventName, DataRequestEventPayload } from '@grafana/runtime'; |
||||
|
||||
export function emitDataRequestEvent(datasource: DataSourceApi) { |
||||
let done = false; |
||||
|
||||
return (data: PanelData) => { |
||||
if (!data.request || done || data.request.app === CoreApp.Explore) { |
||||
return; |
||||
} |
||||
|
||||
const params = urlUtil.getUrlSearchParams(); |
||||
if (params.editPanel != null) { |
||||
return; |
||||
} |
||||
|
||||
if (data.state !== LoadingState.Done && data.state !== LoadingState.Error) { |
||||
return; |
||||
} |
||||
|
||||
const eventData: DataRequestEventPayload = { |
||||
eventName: MetaAnalyticsEventName.DataRequest, |
||||
datasourceName: datasource.name, |
||||
datasourceId: datasource.id, |
||||
panelId: data.request.panelId, |
||||
dashboardId: data.request.dashboardId, |
||||
dataSize: 0, |
||||
duration: data.request.endTime! - data.request.startTime, |
||||
}; |
||||
|
||||
// enrich with dashboard info
|
||||
const dashboard = getDashboardSrv().getCurrent(); |
||||
if (dashboard) { |
||||
eventData.dashboardId = dashboard.id; |
||||
eventData.dashboardName = dashboard.title; |
||||
eventData.dashboardUid = dashboard.uid; |
||||
eventData.folderName = dashboard.meta.folderTitle; |
||||
} |
||||
|
||||
if (data.series && data.series.length > 0) { |
||||
// estimate size
|
||||
eventData.dataSize = data.series.length; |
||||
} |
||||
|
||||
if (data.error) { |
||||
eventData.error = data.error.message; |
||||
} |
||||
|
||||
reportMetaAnalytics(eventData); |
||||
|
||||
// this done check is to make sure we do not double emit events in case
|
||||
// there are multiple responses with done state
|
||||
done = true; |
||||
}; |
||||
} |
||||
@ -0,0 +1,33 @@ |
||||
import React, { FC, useState } from 'react'; |
||||
import { PanelModel } from '../dashboard/state'; |
||||
import { QueriesTab } from '../query/components/QueriesTab'; |
||||
|
||||
interface State { |
||||
panel: PanelModel; |
||||
} |
||||
|
||||
export const TestStuffPage: FC = () => { |
||||
const [state] = useState<State>(getDefaultState()); |
||||
|
||||
return ( |
||||
<div style={{ padding: '50px', height: '100%', flexGrow: 1 }} className="page-scrollbar-wrapper"> |
||||
<h2>Hello</h2> |
||||
|
||||
<QueriesTab panel={state.panel} /> |
||||
</div> |
||||
); |
||||
}; |
||||
|
||||
export function getDefaultState(): State { |
||||
const panel = new PanelModel({ |
||||
datasource: 'gdev-testdata', |
||||
id: 10, |
||||
targets: [], |
||||
}); |
||||
|
||||
return { |
||||
panel, |
||||
}; |
||||
} |
||||
|
||||
export default TestStuffPage; |
||||
Loading…
Reference in new issue