mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Make sure commit hook in FieldPropertiesEditor is invalidated when value changes (#22673)
This commit is contained in:
parent
17a14a8a48
commit
805abdfa2a
@ -0,0 +1,32 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { FieldPropertiesEditor } from './FieldPropertiesEditor';
|
||||||
|
import { FieldConfig } from '@grafana/data';
|
||||||
|
import { mount } from 'enzyme';
|
||||||
|
|
||||||
|
describe('FieldPropertiesEditor', () => {
|
||||||
|
describe('when bluring min/max field', () => {
|
||||||
|
it("when title was modified it should persist it's value", () => {
|
||||||
|
const onChangeHandler = jest.fn();
|
||||||
|
const value: FieldConfig = {
|
||||||
|
title: 'Title set',
|
||||||
|
};
|
||||||
|
const container = mount(<FieldPropertiesEditor value={value} onChange={onChangeHandler} showTitle showMinMax />);
|
||||||
|
const minInput = container.find('input[aria-label="Field properties editor min input"]');
|
||||||
|
const maxInput = container.find('input[aria-label="Field properties editor max input"]');
|
||||||
|
|
||||||
|
// Simulating title update provided from PanelModel options
|
||||||
|
container.setProps({ value: { title: 'Title updated' } });
|
||||||
|
|
||||||
|
minInput.simulate('blur');
|
||||||
|
maxInput.simulate('blur');
|
||||||
|
|
||||||
|
expect(onChangeHandler).toHaveBeenLastCalledWith({
|
||||||
|
title: 'Title updated',
|
||||||
|
min: undefined,
|
||||||
|
max: undefined,
|
||||||
|
decimals: undefined,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
//
|
@ -72,7 +72,7 @@ export const FieldPropertiesEditor: React.FC<Props> = ({ value, onChange, showMi
|
|||||||
min: toFloatOrUndefined(min),
|
min: toFloatOrUndefined(min),
|
||||||
max: toFloatOrUndefined(max),
|
max: toFloatOrUndefined(max),
|
||||||
});
|
});
|
||||||
}, [min, max, decimals]);
|
}, [min, max, decimals, value]);
|
||||||
|
|
||||||
const titleTooltip = (
|
const titleTooltip = (
|
||||||
<div>
|
<div>
|
||||||
@ -96,6 +96,7 @@ export const FieldPropertiesEditor: React.FC<Props> = ({ value, onChange, showMi
|
|||||||
value={title}
|
value={title}
|
||||||
tooltip={titleTooltip}
|
tooltip={titleTooltip}
|
||||||
placeholder="Auto"
|
placeholder="Auto"
|
||||||
|
aria-label="Field properties editor title input"
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
@ -113,6 +114,7 @@ export const FieldPropertiesEditor: React.FC<Props> = ({ value, onChange, showMi
|
|||||||
value={min}
|
value={min}
|
||||||
placeholder="Auto"
|
placeholder="Auto"
|
||||||
type="number"
|
type="number"
|
||||||
|
aria-label="Field properties editor min input"
|
||||||
/>
|
/>
|
||||||
<FormField
|
<FormField
|
||||||
label="Max"
|
label="Max"
|
||||||
@ -122,6 +124,7 @@ export const FieldPropertiesEditor: React.FC<Props> = ({ value, onChange, showMi
|
|||||||
value={max}
|
value={max}
|
||||||
type="number"
|
type="number"
|
||||||
placeholder="Auto"
|
placeholder="Auto"
|
||||||
|
aria-label="Field properties editor max input"
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
Loading…
Reference in New Issue
Block a user