mirror of https://github.com/grafana/grafana
QueryEditors: Refactoring & rewriting out dependency on PanelModel (#29419)
* Removing PanelModel usage from query rows * More work removing dependency on panel model * Before big change to query options * Query options now have no dependency on panel model * Test page is working * Shared query now works again * Rename component * fix after merge * Fixed issue with old angular editorspull/29516/head
parent
b8fec209a9
commit
068fef8c7c
@ -1,16 +1,96 @@ |
||||
import React, { PureComponent } from 'react'; |
||||
import { QueriesTab } from 'app/features/query/components/QueriesTab'; |
||||
import { DashboardModel, PanelModel } from '../../state'; |
||||
import { QueryGroup } from 'app/features/query/components/QueryGroup'; |
||||
import { QueryGroupOptions } from 'app/features/query/components/QueryGroupOptions'; |
||||
import { PanelModel } from '../../state'; |
||||
import { DataQuery, DataSourceSelectItem } from '@grafana/data'; |
||||
import { getLocationSrv } from '@grafana/runtime'; |
||||
|
||||
interface Props { |
||||
panel: PanelModel; |
||||
dashboard: DashboardModel; |
||||
} |
||||
|
||||
export class PanelEditorQueries extends PureComponent<Props> { |
||||
interface State { |
||||
options: QueryGroupOptions; |
||||
} |
||||
|
||||
export class PanelEditorQueries extends PureComponent<Props, State> { |
||||
constructor(props: Props) { |
||||
super(props); |
||||
|
||||
this.state = { options: this.buildQueryOptions(props) }; |
||||
} |
||||
|
||||
buildQueryOptions({ panel }: Props): QueryGroupOptions { |
||||
return { |
||||
maxDataPoints: panel.maxDataPoints, |
||||
minInterval: panel.interval, |
||||
timeRange: { |
||||
from: panel.timeFrom, |
||||
shift: panel.timeShift, |
||||
hide: panel.hideTimeOverride, |
||||
}, |
||||
}; |
||||
} |
||||
|
||||
onDataSourceChange = (ds: DataSourceSelectItem, queries: DataQuery[]) => { |
||||
const { panel } = this.props; |
||||
|
||||
panel.datasource = ds.value; |
||||
panel.targets = queries; |
||||
panel.refresh(); |
||||
|
||||
this.forceUpdate(); |
||||
}; |
||||
|
||||
onRunQueries = () => { |
||||
this.props.panel.refresh(); |
||||
}; |
||||
|
||||
onQueriesChange = (queries: DataQuery[]) => { |
||||
const { panel } = this.props; |
||||
|
||||
panel.targets = queries; |
||||
panel.refresh(); |
||||
|
||||
this.forceUpdate(); |
||||
}; |
||||
|
||||
onOpenQueryInspector = () => { |
||||
getLocationSrv().update({ |
||||
query: { inspect: this.props.panel.id, inspectTab: 'query' }, |
||||
partial: true, |
||||
}); |
||||
}; |
||||
|
||||
onQueryOptionsChange = (options: QueryGroupOptions) => { |
||||
const { panel } = this.props; |
||||
|
||||
panel.timeFrom = options.timeRange?.from; |
||||
panel.timeShift = options.timeRange?.shift; |
||||
panel.hideTimeOverride = options.timeRange?.hide; |
||||
panel.interval = options.minInterval; |
||||
panel.maxDataPoints = options.maxDataPoints; |
||||
panel.refresh(); |
||||
|
||||
this.setState({ options: options }); |
||||
}; |
||||
|
||||
render() { |
||||
const { panel, dashboard } = this.props; |
||||
const { panel } = this.props; |
||||
const { options } = this.state; |
||||
|
||||
return <QueriesTab panel={panel} dashboard={dashboard} />; |
||||
return ( |
||||
<QueryGroup |
||||
dataSourceName={panel.datasource} |
||||
options={options} |
||||
queryRunner={panel.getQueryRunner()} |
||||
queries={panel.targets} |
||||
onQueriesChange={this.onQueriesChange} |
||||
onDataSourceChange={this.onDataSourceChange} |
||||
onRunQueries={this.onRunQueries} |
||||
onOpenQueryInspector={this.onOpenQueryInspector} |
||||
onOptionsChange={this.onQueryOptionsChange} |
||||
/> |
||||
); |
||||
} |
||||
} |
||||
|
||||
@ -0,0 +1,5 @@ |
||||
import { EventBusExtended } from '@grafana/data'; |
||||
|
||||
export interface PanelModelForLegacyQueryEditors { |
||||
events: EventBusExtended; |
||||
} |
||||
Loading…
Reference in new issue