mirror of
https://github.com/grafana/grafana.git
synced 2025-02-09 23:16:16 -06:00
Loki: Run query when pressing Enter on line-filters (#49913)
* changed `onBlur` and `onKeyDown` handling - `onCommitChange` is only called if `onBlur` or `onKeyDown` are not set * added `runQueryOnEnter` flag to OperationParamDef * only run query if `runQueryOnEnter` is configured * changed `evt.type` check to `keydown`
This commit is contained in:
parent
9562fb389f
commit
b355adac6f
@ -46,4 +46,52 @@ describe('AutoSizeInput', () => {
|
||||
fireEvent.change(input, { target: { value: 'very very long value' } });
|
||||
expect(getComputedStyle(inputWrapper).width).toBe('304px');
|
||||
});
|
||||
|
||||
it('should call onBlur if set when blurring', () => {
|
||||
const onBlur = jest.fn();
|
||||
const onCommitChange = jest.fn();
|
||||
render(<AutoSizeInput onBlur={onBlur} onCommitChange={onCommitChange} />);
|
||||
|
||||
const input: HTMLInputElement = screen.getByTestId('autosize-input');
|
||||
|
||||
fireEvent.blur(input);
|
||||
|
||||
expect(onBlur).toHaveBeenCalled();
|
||||
expect(onCommitChange).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should call onCommitChange if not set when blurring', () => {
|
||||
const onCommitChange = jest.fn();
|
||||
render(<AutoSizeInput onCommitChange={onCommitChange} />);
|
||||
|
||||
const input: HTMLInputElement = screen.getByTestId('autosize-input');
|
||||
|
||||
fireEvent.blur(input);
|
||||
|
||||
expect(onCommitChange).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should call onKeyDown if set when keydown', () => {
|
||||
const onKeyDown = jest.fn();
|
||||
const onCommitChange = jest.fn();
|
||||
render(<AutoSizeInput onKeyDown={onKeyDown} onCommitChange={onCommitChange} />);
|
||||
|
||||
const input: HTMLInputElement = screen.getByTestId('autosize-input');
|
||||
|
||||
fireEvent.keyDown(input, { key: 'Enter' });
|
||||
|
||||
expect(onKeyDown).toHaveBeenCalled();
|
||||
expect(onCommitChange).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should call onCommitChange if not set when keydown', () => {
|
||||
const onCommitChange = jest.fn();
|
||||
render(<AutoSizeInput onCommitChange={onCommitChange} />);
|
||||
|
||||
const input: HTMLInputElement = screen.getByTestId('autosize-input');
|
||||
|
||||
fireEvent.keyDown(input, { key: 'Enter' });
|
||||
|
||||
expect(onCommitChange).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
@ -32,19 +32,17 @@ export const AutoSizeInput = React.forwardRef<HTMLInputElement, Props>((props, r
|
||||
}}
|
||||
width={inputWidth}
|
||||
onBlur={(event) => {
|
||||
if (onCommitChange) {
|
||||
onCommitChange(event);
|
||||
}
|
||||
if (onBlur) {
|
||||
onBlur(event);
|
||||
} else if (onCommitChange) {
|
||||
onCommitChange(event);
|
||||
}
|
||||
}}
|
||||
onKeyDown={(event) => {
|
||||
if (event.key === 'Enter' && onCommitChange) {
|
||||
onCommitChange(event);
|
||||
}
|
||||
if (onKeyDown) {
|
||||
onKeyDown(event);
|
||||
} else if (event.key === 'Enter' && onCommitChange) {
|
||||
onCommitChange(event);
|
||||
}
|
||||
}}
|
||||
data-testid={'autosize-input'}
|
||||
|
@ -202,6 +202,7 @@ export function getOperationDefinitions(): QueryBuilderOperationDef[] {
|
||||
placeholder: 'Text to find',
|
||||
description: 'Find log lines that contains this text',
|
||||
minWidth: 20,
|
||||
runQueryOnEnter: true,
|
||||
},
|
||||
],
|
||||
defaultParams: [''],
|
||||
@ -223,6 +224,7 @@ export function getOperationDefinitions(): QueryBuilderOperationDef[] {
|
||||
placeholder: 'Text to exclude',
|
||||
description: 'Find log lines that does not contain this text',
|
||||
minWidth: 26,
|
||||
runQueryOnEnter: true,
|
||||
},
|
||||
],
|
||||
defaultParams: [''],
|
||||
@ -244,6 +246,7 @@ export function getOperationDefinitions(): QueryBuilderOperationDef[] {
|
||||
placeholder: 'Pattern to match',
|
||||
description: 'Find log lines that match this regex pattern',
|
||||
minWidth: 30,
|
||||
runQueryOnEnter: true,
|
||||
},
|
||||
],
|
||||
defaultParams: [''],
|
||||
@ -265,6 +268,7 @@ export function getOperationDefinitions(): QueryBuilderOperationDef[] {
|
||||
placeholder: 'Pattern to exclude',
|
||||
description: 'Find log lines that does not match this regex pattern',
|
||||
minWidth: 30,
|
||||
runQueryOnEnter: true,
|
||||
},
|
||||
],
|
||||
defaultParams: [''],
|
||||
|
@ -38,6 +38,9 @@ function SimpleInputParamEditor(props: QueryBuilderOperationParamEditorProps) {
|
||||
title={props.paramDef.description}
|
||||
onCommitChange={(evt) => {
|
||||
props.onChange(props.index, evt.currentTarget.value);
|
||||
if (props.paramDef.runQueryOnEnter && evt.type === 'keydown') {
|
||||
props.onRunQuery();
|
||||
}
|
||||
}}
|
||||
/>
|
||||
);
|
||||
|
@ -70,6 +70,7 @@ export interface QueryBuilderOperationParamDef {
|
||||
description?: string;
|
||||
minWidth?: number;
|
||||
editor?: ComponentType<QueryBuilderOperationParamEditorProps>;
|
||||
runQueryOnEnter?: boolean;
|
||||
}
|
||||
|
||||
export interface QueryBuilderOperationEditorProps {
|
||||
|
Loading…
Reference in New Issue
Block a user