mirror of
https://github.com/grafana/grafana.git
synced 2025-02-10 07:35:45 -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' } });
|
fireEvent.change(input, { target: { value: 'very very long value' } });
|
||||||
expect(getComputedStyle(inputWrapper).width).toBe('304px');
|
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}
|
width={inputWidth}
|
||||||
onBlur={(event) => {
|
onBlur={(event) => {
|
||||||
if (onCommitChange) {
|
|
||||||
onCommitChange(event);
|
|
||||||
}
|
|
||||||
if (onBlur) {
|
if (onBlur) {
|
||||||
onBlur(event);
|
onBlur(event);
|
||||||
|
} else if (onCommitChange) {
|
||||||
|
onCommitChange(event);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
onKeyDown={(event) => {
|
onKeyDown={(event) => {
|
||||||
if (event.key === 'Enter' && onCommitChange) {
|
|
||||||
onCommitChange(event);
|
|
||||||
}
|
|
||||||
if (onKeyDown) {
|
if (onKeyDown) {
|
||||||
onKeyDown(event);
|
onKeyDown(event);
|
||||||
|
} else if (event.key === 'Enter' && onCommitChange) {
|
||||||
|
onCommitChange(event);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
data-testid={'autosize-input'}
|
data-testid={'autosize-input'}
|
||||||
|
@ -202,6 +202,7 @@ export function getOperationDefinitions(): QueryBuilderOperationDef[] {
|
|||||||
placeholder: 'Text to find',
|
placeholder: 'Text to find',
|
||||||
description: 'Find log lines that contains this text',
|
description: 'Find log lines that contains this text',
|
||||||
minWidth: 20,
|
minWidth: 20,
|
||||||
|
runQueryOnEnter: true,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
defaultParams: [''],
|
defaultParams: [''],
|
||||||
@ -223,6 +224,7 @@ export function getOperationDefinitions(): QueryBuilderOperationDef[] {
|
|||||||
placeholder: 'Text to exclude',
|
placeholder: 'Text to exclude',
|
||||||
description: 'Find log lines that does not contain this text',
|
description: 'Find log lines that does not contain this text',
|
||||||
minWidth: 26,
|
minWidth: 26,
|
||||||
|
runQueryOnEnter: true,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
defaultParams: [''],
|
defaultParams: [''],
|
||||||
@ -244,6 +246,7 @@ export function getOperationDefinitions(): QueryBuilderOperationDef[] {
|
|||||||
placeholder: 'Pattern to match',
|
placeholder: 'Pattern to match',
|
||||||
description: 'Find log lines that match this regex pattern',
|
description: 'Find log lines that match this regex pattern',
|
||||||
minWidth: 30,
|
minWidth: 30,
|
||||||
|
runQueryOnEnter: true,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
defaultParams: [''],
|
defaultParams: [''],
|
||||||
@ -265,6 +268,7 @@ export function getOperationDefinitions(): QueryBuilderOperationDef[] {
|
|||||||
placeholder: 'Pattern to exclude',
|
placeholder: 'Pattern to exclude',
|
||||||
description: 'Find log lines that does not match this regex pattern',
|
description: 'Find log lines that does not match this regex pattern',
|
||||||
minWidth: 30,
|
minWidth: 30,
|
||||||
|
runQueryOnEnter: true,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
defaultParams: [''],
|
defaultParams: [''],
|
||||||
|
@ -38,6 +38,9 @@ function SimpleInputParamEditor(props: QueryBuilderOperationParamEditorProps) {
|
|||||||
title={props.paramDef.description}
|
title={props.paramDef.description}
|
||||||
onCommitChange={(evt) => {
|
onCommitChange={(evt) => {
|
||||||
props.onChange(props.index, evt.currentTarget.value);
|
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;
|
description?: string;
|
||||||
minWidth?: number;
|
minWidth?: number;
|
||||||
editor?: ComponentType<QueryBuilderOperationParamEditorProps>;
|
editor?: ComponentType<QueryBuilderOperationParamEditorProps>;
|
||||||
|
runQueryOnEnter?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface QueryBuilderOperationEditorProps {
|
export interface QueryBuilderOperationEditorProps {
|
||||||
|
Loading…
Reference in New Issue
Block a user