mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Prometheus: bool bin op improvements (#47198)
* Change param order * Align tooltip icon styling
This commit is contained in:
parent
07bb5b37a5
commit
ba2332eb96
@ -317,4 +317,19 @@ describe('PromQueryModeller', () => {
|
|||||||
})
|
})
|
||||||
).toBe('metric_a / on(le, foo) metric_b');
|
).toBe('metric_a / on(le, foo) metric_b');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('can render bool in binary ops', () => {
|
||||||
|
expect(
|
||||||
|
modeller.renderQuery({
|
||||||
|
metric: 'cluster_namespace_slug_dialer_name',
|
||||||
|
labels: [],
|
||||||
|
operations: [
|
||||||
|
{
|
||||||
|
id: '__less_or_equal',
|
||||||
|
params: [2, true],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
).toBe('cluster_namespace_slug_dialer_name <= bool 2');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -77,12 +77,12 @@ export const binaryScalarOperations: QueryBuilderOperationDef[] = binaryScalarDe
|
|||||||
const params: QueryBuilderOperationParamDef[] = [{ name: 'Value', type: 'number' }];
|
const params: QueryBuilderOperationParamDef[] = [{ name: 'Value', type: 'number' }];
|
||||||
const defaultParams: any[] = [2];
|
const defaultParams: any[] = [2];
|
||||||
if (opDef.comparison) {
|
if (opDef.comparison) {
|
||||||
params.unshift({
|
params.push({
|
||||||
name: 'Bool',
|
name: 'Bool',
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
description: 'If checked comparison will return 0 or 1 for the value rather than filtering.',
|
description: 'If checked comparison will return 0 or 1 for the value rather than filtering.',
|
||||||
});
|
});
|
||||||
defaultParams.unshift(false);
|
defaultParams.push(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -102,8 +102,7 @@ function getSimpleBinaryRenderer(operator: string) {
|
|||||||
let param = model.params[0];
|
let param = model.params[0];
|
||||||
let bool = '';
|
let bool = '';
|
||||||
if (model.params.length === 2) {
|
if (model.params.length === 2) {
|
||||||
param = model.params[1];
|
bool = model.params[1] ? ' bool' : '';
|
||||||
bool = model.params[0] ? ' bool' : '';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return `${innerExpr} ${operator}${bool} ${param}`;
|
return `${innerExpr} ${operator}${bool} ${param}`;
|
||||||
|
@ -422,7 +422,7 @@ describe('buildVisualQueryFromString', () => {
|
|||||||
operations: [
|
operations: [
|
||||||
{
|
{
|
||||||
id: '__less_or_equal',
|
id: '__less_or_equal',
|
||||||
params: [false, 2.5],
|
params: [2.5, false],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
@ -438,7 +438,7 @@ describe('buildVisualQueryFromString', () => {
|
|||||||
operations: [
|
operations: [
|
||||||
{
|
{
|
||||||
id: '__less_or_equal',
|
id: '__less_or_equal',
|
||||||
params: [true, 2],
|
params: [2, true],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
@ -438,7 +438,7 @@ function makeBinOp(
|
|||||||
) {
|
) {
|
||||||
const params: any[] = [parseFloat(getString(expr, numberNode))];
|
const params: any[] = [parseFloat(getString(expr, numberNode))];
|
||||||
if (opDef.comparison) {
|
if (opDef.comparison) {
|
||||||
params.unshift(hasBool);
|
params.push(hasBool);
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
id: opDef.id,
|
id: opDef.id,
|
||||||
|
@ -201,6 +201,10 @@ const getStyles = (theme: GrafanaTheme2) => {
|
|||||||
}),
|
}),
|
||||||
infoIcon: css({
|
infoIcon: css({
|
||||||
marginLeft: theme.spacing(0.5),
|
marginLeft: theme.spacing(0.5),
|
||||||
|
color: theme.colors.text.secondary,
|
||||||
|
':hover': {
|
||||||
|
color: theme.colors.text.primary,
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
body: css({
|
body: css({
|
||||||
margin: theme.spacing(1, 1, 0.5, 1),
|
margin: theme.spacing(1, 1, 0.5, 1),
|
||||||
|
Loading…
Reference in New Issue
Block a user