[Lens] fix passing 0 as static value (#118032)
* [Lens] fix passing 0 as static value * allow computed static_value to be passed * Update x-pack/plugins/lens/public/xy_visualization/reference_line_helpers.tsx Co-authored-by: Marco Liberati <dej611@users.noreply.github.com> * ci fix Co-authored-by: Marco Liberati <dej611@users.noreply.github.com>
This commit is contained in:
parent
f555c737d0
commit
b87852071b
|
@ -1696,7 +1696,7 @@ describe('IndexPattern Data Source', () => {
|
||||||
isBucketed: false,
|
isBucketed: false,
|
||||||
label: 'Static value: 0',
|
label: 'Static value: 0',
|
||||||
operationType: 'static_value',
|
operationType: 'static_value',
|
||||||
params: { value: 0 },
|
params: { value: '0' },
|
||||||
references: [],
|
references: [],
|
||||||
scale: 'ratio',
|
scale: 'ratio',
|
||||||
},
|
},
|
||||||
|
|
|
@ -338,6 +338,36 @@ describe('static_value', () => {
|
||||||
expect(input.prop('value')).toEqual('23');
|
expect(input.prop('value')).toEqual('23');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should allow 0 as initial value', () => {
|
||||||
|
const updateLayerSpy = jest.fn();
|
||||||
|
const zeroLayer = {
|
||||||
|
...layer,
|
||||||
|
columns: {
|
||||||
|
...layer.columns,
|
||||||
|
col2: {
|
||||||
|
...layer.columns.col2,
|
||||||
|
operationType: 'static_value',
|
||||||
|
references: [],
|
||||||
|
params: {
|
||||||
|
value: '0',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
} as IndexPatternLayer;
|
||||||
|
const instance = shallow(
|
||||||
|
<ParamEditor
|
||||||
|
{...defaultProps}
|
||||||
|
layer={zeroLayer}
|
||||||
|
updateLayer={updateLayerSpy}
|
||||||
|
columnId="col2"
|
||||||
|
currentColumn={zeroLayer.columns.col2 as StaticValueIndexPatternColumn}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
|
||||||
|
const input = instance.find('[data-test-subj="lns-indexPattern-static_value-input"]');
|
||||||
|
expect(input.prop('value')).toEqual('0');
|
||||||
|
});
|
||||||
|
|
||||||
it('should update state on change', async () => {
|
it('should update state on change', async () => {
|
||||||
const updateLayerSpy = jest.fn();
|
const updateLayerSpy = jest.fn();
|
||||||
const instance = mount(
|
const instance = mount(
|
||||||
|
|
|
@ -95,7 +95,7 @@ export const staticValueOperation: OperationDefinition<
|
||||||
arguments: {
|
arguments: {
|
||||||
id: [columnId],
|
id: [columnId],
|
||||||
name: [label || defaultLabel],
|
name: [label || defaultLabel],
|
||||||
expression: [isValidNumber(params.value) ? params.value! : String(defaultValue)],
|
expression: [String(isValidNumber(params.value) ? params.value! : defaultValue)],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
@ -118,7 +118,7 @@ export const staticValueOperation: OperationDefinition<
|
||||||
operationType: 'static_value',
|
operationType: 'static_value',
|
||||||
isBucketed: false,
|
isBucketed: false,
|
||||||
scale: 'ratio',
|
scale: 'ratio',
|
||||||
params: { ...previousParams, value: previousParams.value ?? String(defaultValue) },
|
params: { ...previousParams, value: String(previousParams.value ?? defaultValue) },
|
||||||
references: [],
|
references: [],
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
|
@ -120,6 +120,32 @@ describe('reference_line helpers', () => {
|
||||||
).toBe(100);
|
).toBe(100);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should return 0 as result of calculation', () => {
|
||||||
|
expect(
|
||||||
|
getStaticValue(
|
||||||
|
[
|
||||||
|
{
|
||||||
|
layerId: 'id-a',
|
||||||
|
seriesType: 'area',
|
||||||
|
layerType: 'data',
|
||||||
|
accessors: ['a'],
|
||||||
|
yConfig: [{ forAccessor: 'a', axisMode: 'right' }],
|
||||||
|
} as XYLayerConfig,
|
||||||
|
],
|
||||||
|
'yRight',
|
||||||
|
{
|
||||||
|
activeData: getActiveData([
|
||||||
|
{
|
||||||
|
id: 'id-a',
|
||||||
|
rows: [{ a: -30 }, { a: 10 }],
|
||||||
|
},
|
||||||
|
]),
|
||||||
|
},
|
||||||
|
hasAllNumberHistogram
|
||||||
|
)
|
||||||
|
).toBe(0);
|
||||||
|
});
|
||||||
|
|
||||||
it('should work for no yConfig defined and fallback to left axis', () => {
|
it('should work for no yConfig defined and fallback to left axis', () => {
|
||||||
expect(
|
expect(
|
||||||
getStaticValue(
|
getStaticValue(
|
||||||
|
|
|
@ -104,15 +104,14 @@ export function getStaticValue(
|
||||||
) {
|
) {
|
||||||
return fallbackValue;
|
return fallbackValue;
|
||||||
}
|
}
|
||||||
return (
|
const computedValue = computeStaticValueForGroup(
|
||||||
computeStaticValueForGroup(
|
filteredLayers,
|
||||||
filteredLayers,
|
accessors,
|
||||||
accessors,
|
activeData,
|
||||||
activeData,
|
groupId !== 'x', // histogram axis should compute the min based on the current data
|
||||||
groupId !== 'x', // histogram axis should compute the min based on the current data
|
groupId !== 'x'
|
||||||
groupId !== 'x'
|
|
||||||
) || fallbackValue
|
|
||||||
);
|
);
|
||||||
|
return computedValue ?? fallbackValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAccessorCriteriaForGroup(
|
function getAccessorCriteriaForGroup(
|
||||||
|
|
Loading…
Reference in a new issue