Explore: fix undo in query editor (#24797)

* Explore: fix undo in query editor

* Add e2e test for regression
This commit is contained in:
Zoltán Bedi 2020-05-19 15:41:52 +02:00 committed by GitHub
parent c62591e77b
commit 29afc2feb8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 64 additions and 20 deletions

View File

@ -0,0 +1,36 @@
import { e2e } from '@grafana/e2e';
e2e.scenario({
describeName: 'Query editor',
itName: 'Undo should work in query editor for prometheus.',
addScenarioDataSource: false,
addScenarioDashBoard: false,
skipScenario: false,
scenario: () => {
e2e.pages.Explore.visit();
e2e.components.DataSourcePicker.container()
.should('be.visible')
.within(() => {
e2e.components.Select.input()
.should('be.visible')
.click();
cy.contains('gdev-prometheus')
.scrollIntoView()
.should('be.visible')
.click();
});
const queryText = 'http_requests_total';
e2e.components.QueryField.container()
.should('be.visible')
.type(queryText)
.type('{backspace}');
cy.contains(queryText.slice(0, -1)).should('be.visible');
e2e.components.QueryField.container().type('{ctrl}z');
cy.contains(queryText).should('be.visible');
},
});

View File

@ -125,7 +125,11 @@ export const Components = {
FolderPicker: {
container: 'Folder picker select container',
},
DataSourcePicker: {
container: 'Data source picker select container',
},
TimeZonePicker: {
container: 'Time zone picker select container',
},
QueryField: { container: 'Query field' },
};

View File

@ -17,6 +17,7 @@ import {
} from '../../slate-plugins';
import { makeValue, SCHEMA, CompletionItemGroup, TypeaheadOutput, TypeaheadInput, SuggestionsState } from '../..';
import { selectors } from '@grafana/e2e-selectors';
export interface QueryFieldProps {
additionalPlugins?: Plugin[];
@ -197,7 +198,7 @@ export class QueryField extends React.PureComponent<QueryFieldProps, QueryFieldS
return (
<div className={wrapperClassName}>
<div className="slate-query-field">
<div className="slate-query-field" aria-label={selectors.components.QueryField.container}>
<Editor
ref={editor => (this.editor = editor!)}
schema={SCHEMA}

View File

@ -43,8 +43,8 @@ export function SlatePrism(optsParam: OptionsFormat = {}): Plugin {
const tokens = Prism.tokenize(blockText, grammar);
const flattened = flattenTokens(tokens);
// @ts-ignore
editor.setData({ tokens: flattened });
const newData = editor.value.data.set('tokens', flattened);
editor.setData(newData);
return decorateNode(opts, tokens, block);
},

View File

@ -4,6 +4,7 @@ import React, { PureComponent } from 'react';
// Components
import { Select } from '@grafana/ui';
import { SelectableValue, DataSourceSelectItem } from '@grafana/data';
import { selectors } from '@grafana/e2e-selectors';
export interface Props {
onChange: (ds: DataSourceSelectItem) => void;
@ -67,23 +68,25 @@ export class DataSourcePicker extends PureComponent<Props> {
};
return (
<Select
className="ds-picker select-container"
isMulti={false}
isClearable={false}
backspaceRemovesValue={false}
onChange={this.onChange}
options={options}
autoFocus={autoFocus}
onBlur={onBlur}
openMenuOnFocus={openMenuOnFocus}
maxMenuHeight={500}
menuPlacement="bottom"
placeholder={placeholder}
noOptionsMessage="No datasources found"
value={value}
invalid={invalid}
/>
<div aria-label={selectors.components.DataSourcePicker.container}>
<Select
className="ds-picker select-container"
isMulti={false}
isClearable={false}
backspaceRemovesValue={false}
onChange={this.onChange}
options={options}
autoFocus={autoFocus}
onBlur={onBlur}
openMenuOnFocus={openMenuOnFocus}
maxMenuHeight={500}
menuPlacement="bottom"
placeholder={placeholder}
noOptionsMessage="No datasources found"
value={value}
invalid={invalid}
/>
</div>
);
}
}