Loki: Adds more options to make line filter UX better (#46324)

* Loki: Adds more options to make line filter UX better

* Sync wording

* Tweak width

* More tweaks

* Added descriptions as well
This commit is contained in:
Torkel Ödegaard 2022-03-10 10:12:54 +01:00 committed by GitHub
parent 806b0e3b23
commit c952c9c90a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 58 additions and 10 deletions

View File

@ -48,7 +48,16 @@ export function getOperationDefintions(): QueryBuilderOperationDef[] {
{ {
id: LokiOperationId.LineContains, id: LokiOperationId.LineContains,
name: 'Line contains', name: 'Line contains',
params: [{ name: 'String', type: 'string' }], params: [
{
name: 'String',
type: 'string',
hideName: true,
placeholder: 'Text to find',
description: 'Find log lines that contains this text',
minWidth: 20,
},
],
defaultParams: [''], defaultParams: [''],
alternativesKey: 'line filter', alternativesKey: 'line filter',
category: LokiVisualQueryOperationCategory.LineFilters, category: LokiVisualQueryOperationCategory.LineFilters,
@ -59,7 +68,16 @@ export function getOperationDefintions(): QueryBuilderOperationDef[] {
{ {
id: LokiOperationId.LineContainsNot, id: LokiOperationId.LineContainsNot,
name: 'Line does not contain', name: 'Line does not contain',
params: [{ name: 'String', type: 'string' }], params: [
{
name: 'String',
type: 'string',
hideName: true,
placeholder: 'Text to exclude',
description: 'Find log lines that does not contain this text',
minWidth: 26,
},
],
defaultParams: [''], defaultParams: [''],
alternativesKey: 'line filter', alternativesKey: 'line filter',
category: LokiVisualQueryOperationCategory.LineFilters, category: LokiVisualQueryOperationCategory.LineFilters,
@ -70,7 +88,16 @@ export function getOperationDefintions(): QueryBuilderOperationDef[] {
{ {
id: LokiOperationId.LineMatchesRegex, id: LokiOperationId.LineMatchesRegex,
name: 'Line contains regex match', name: 'Line contains regex match',
params: [{ name: 'Regex', type: 'string' }], params: [
{
name: 'Regex',
type: 'string',
hideName: true,
placeholder: 'Pattern to match',
description: 'Find log lines that match this regex pattern',
minWidth: 30,
},
],
defaultParams: [''], defaultParams: [''],
alternativesKey: 'line filter', alternativesKey: 'line filter',
category: LokiVisualQueryOperationCategory.LineFilters, category: LokiVisualQueryOperationCategory.LineFilters,
@ -81,7 +108,16 @@ export function getOperationDefintions(): QueryBuilderOperationDef[] {
{ {
id: LokiOperationId.LineMatchesRegexNot, id: LokiOperationId.LineMatchesRegexNot,
name: 'Line does not match regex', name: 'Line does not match regex',
params: [{ name: 'Regex', type: 'string' }], params: [
{
name: 'Regex',
type: 'string',
hideName: true,
placeholder: 'Pattern to exclude',
description: 'Find log lines that does not match this regex pattern',
minWidth: 30,
},
],
defaultParams: [''], defaultParams: [''],
alternativesKey: 'line filter', alternativesKey: 'line filter',
category: LokiVisualQueryOperationCategory.LineFilters, category: LokiVisualQueryOperationCategory.LineFilters,
@ -116,13 +152,15 @@ export function getOperationDefintions(): QueryBuilderOperationDef[] {
{ {
id: LokiOperationId.Unwrap, id: LokiOperationId.Unwrap,
name: 'Unwrap', name: 'Unwrap',
params: [{ name: 'Identifier', type: 'string' }], params: [{ name: 'Identifier', type: 'string', hideName: true, minWidth: 16, placeholder: 'Label key' }],
defaultParams: [''], defaultParams: [''],
category: LokiVisualQueryOperationCategory.Formats, category: LokiVisualQueryOperationCategory.Formats,
renderer: (op, def, innerExpr) => `${innerExpr} | unwrap ${op.params[0]}`, renderer: (op, def, innerExpr) => `${innerExpr} | unwrap ${op.params[0]}`,
addOperationHandler: addLokiOperation, addOperationHandler: addLokiOperation,
explainHandler: (op) => explainHandler: (op) => {
`Use the extracted label \`${op.params[0]}\` as sample values instead of log lines for the subsequent range aggregation.`, let label = String(op.params[0]).length > 0 ? op.params[0] : '<label>';
return `Use the extracted label \`${label}\` as sample values instead of log lines for the subsequent range aggregation.`;
},
}, },
]; ];

View File

@ -69,9 +69,11 @@ export function OperationEditor({
operationElements.push( operationElements.push(
<div className={styles.paramRow} key={`${paramIndex}-1`}> <div className={styles.paramRow} key={`${paramIndex}-1`}>
<label className={styles.paramName} htmlFor={getOperationParamId(index, paramIndex)}> {!paramDef.hideName && (
{paramDef.name} <label className={styles.paramName} htmlFor={getOperationParamId(index, paramIndex)}>
</label> {paramDef.name}
</label>
)}
<div className={styles.paramValue}> <div className={styles.paramValue}>
<Stack gap={0.5} direction="row" alignItems="center" wrap={false}> <Stack gap={0.5} direction="row" alignItems="center" wrap={false}>
<Editor <Editor

View File

@ -24,6 +24,9 @@ function SimpleInputParamEditor(props: QueryBuilderOperationParamEditorProps) {
<AutoSizeInput <AutoSizeInput
id={getOperationParamId(props.operationIndex, props.index)} id={getOperationParamId(props.operationIndex, props.index)}
defaultValue={props.value} defaultValue={props.value}
minWidth={props.paramDef.minWidth}
placeholder={props.paramDef.placeholder}
title={props.paramDef.description}
onCommitChange={(evt) => { onCommitChange={(evt) => {
props.onChange(props.index, evt.currentTarget.value); props.onChange(props.index, evt.currentTarget.value);
}} }}
@ -55,6 +58,7 @@ function SelectInputParamEditor({
menuShouldPortal menuShouldPortal
value={valueOption} value={valueOption}
options={selectOptions} options={selectOptions}
placeholder={paramDef.placeholder}
onChange={(value) => onChange(index, value.value!)} onChange={(value) => onChange(index, value.value!)}
/> />
); );

View File

@ -58,8 +58,12 @@ export interface QueryBuilderOperationParamDef {
name: string; name: string;
type: string; type: string;
options?: string[] | number[] | Array<SelectableValue<string>>; options?: string[] | number[] | Array<SelectableValue<string>>;
hideName?: boolean;
restParam?: boolean; restParam?: boolean;
optional?: boolean; optional?: boolean;
placeholder?: string;
description?: string;
minWidth?: number;
editor?: ComponentType<QueryBuilderOperationParamEditorProps>; editor?: ComponentType<QueryBuilderOperationParamEditorProps>;
} }