fix: sql lab ctrl t behaved differently from clicking (#19420)

* initial approach

To have consistent behaviour when creating a new tab with ctrl+t

* consistent behaviour when creating tabs

* fixed bug and added tests

* updates to pass checks
This commit is contained in:
Luis Casillas
2022-04-15 13:28:40 -05:00
committed by GitHub
parent b8e595413f
commit 56381f4ee8
4 changed files with 102 additions and 18 deletions

View File

@@ -75,6 +75,7 @@ import ShareSqlLabQuery from '../ShareSqlLabQuery';
import SqlEditorLeftBar from '../SqlEditorLeftBar';
import AceEditorWrapper from '../AceEditorWrapper';
import RunQueryActionButton from '../RunQueryActionButton';
import { newQueryTabName } from '../../utils/newQueryTabName';
const LIMIT_DROPDOWN = [10, 100, 1000, 10000, 100000];
const SQL_EDITOR_PADDING = 10;
@@ -333,10 +334,10 @@ class SqlEditor extends React.PureComponent {
key: userOS === 'Windows' ? 'ctrl+q' : 'ctrl+t',
descr: t('New tab'),
func: () => {
const title = newQueryTabName(this.props.queryEditors || []);
this.props.addQueryEditor({
...this.props.queryEditor,
title: t('Untitled query'),
sql: '',
title,
});
},
},
@@ -804,13 +805,12 @@ class SqlEditor extends React.PureComponent {
SqlEditor.defaultProps = defaultProps;
SqlEditor.propTypes = propTypes;
function mapStateToProps(state, props) {
const { sqlLab } = state;
function mapStateToProps({ sqlLab }, props) {
const queryEditor = sqlLab.queryEditors.find(
editor => editor.id === props.queryEditorId,
);
return { sqlLab, ...props, queryEditor };
return { sqlLab, ...props, queryEditor, queryEditors: sqlLab.queryEditors };
}
function mapDispatchToProps(dispatch) {