mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
transform: add expressions to query editor (w/ feature flag) (#20072)
for use with gel which is not released yet.
This commit is contained in:
committed by
Kyle Brandt
parent
2bb4684741
commit
861eb72113
@@ -29,6 +29,7 @@ import { PluginHelp } from 'app/core/components/PluginHelp/PluginHelp';
|
||||
import { addQuery } from 'app/core/utils/query';
|
||||
import { Unsubscribable } from 'rxjs';
|
||||
import { isSharedDashboardQuery, DashboardQueryEditor } from 'app/plugins/datasource/dashboard';
|
||||
import { expressionDatasource, ExpressionDatasourceID } from 'app/features/expressions/ExpressionDatasource';
|
||||
|
||||
interface Props {
|
||||
panel: PanelModel;
|
||||
@@ -97,9 +98,11 @@ export class QueriesTab extends PureComponent<Props, State> {
|
||||
if (datasource.meta.mixed) {
|
||||
// Set the datasource on all targets
|
||||
panel.targets.forEach(target => {
|
||||
target.datasource = panel.datasource;
|
||||
if (!target.datasource) {
|
||||
target.datasource = config.defaultDatasource;
|
||||
if (target.datasource !== ExpressionDatasourceID) {
|
||||
target.datasource = panel.datasource;
|
||||
if (!target.datasource) {
|
||||
target.datasource = config.defaultDatasource;
|
||||
}
|
||||
}
|
||||
});
|
||||
} else if (currentDS) {
|
||||
@@ -107,7 +110,9 @@ export class QueriesTab extends PureComponent<Props, State> {
|
||||
if (currentDS.meta.mixed) {
|
||||
// Remove the explicit datasource
|
||||
for (const target of panel.targets) {
|
||||
delete target.datasource;
|
||||
if (target.datasource !== ExpressionDatasourceID) {
|
||||
delete target.datasource;
|
||||
}
|
||||
}
|
||||
} else if (currentDS.meta.id !== datasource.meta.id) {
|
||||
// we are changing data source type, clear queries
|
||||
@@ -150,6 +155,11 @@ export class QueriesTab extends PureComponent<Props, State> {
|
||||
this.onScrollBottom();
|
||||
};
|
||||
|
||||
onAddExpressionClick = () => {
|
||||
this.onUpdateQueries(addQuery(this.props.panel.targets, expressionDatasource.newQuery()));
|
||||
this.onScrollBottom();
|
||||
};
|
||||
|
||||
onScrollBottom = () => {
|
||||
this.setState({ scrollTop: this.state.scrollTop + 10000 });
|
||||
};
|
||||
@@ -168,6 +178,11 @@ export class QueriesTab extends PureComponent<Props, State> {
|
||||
</button>
|
||||
)}
|
||||
{isAddingMixed && this.renderMixedPicker()}
|
||||
{config.featureToggles.expressions && (
|
||||
<button className="btn navbar-button" onClick={this.onAddExpressionClick}>
|
||||
Add Expression
|
||||
</button>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user