Skip to content

Commit

Permalink
Toggle for query editor autocomplete (re #282)
Browse files Browse the repository at this point in the history
  • Loading branch information
Allen Short committed Jan 18, 2018
1 parent 2868053 commit 08af871
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
13 changes: 9 additions & 4 deletions client/app/components/queries/query-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,11 @@ function queryEditor(QuerySnippet) {
if (newSchema === undefined) {
return;
}
const tokensCount = newSchema.reduce((totalLength, table) => totalLength + table.columns.length, 0);
// If there are too many tokens we disable live autocomplete,
// as it makes typing slower.
if (tokensCount > 5000) {
const tokensCount =
newSchema.reduce((totalLength, table) => totalLength + table.columns.length, 0);
// If there are too many tokens or if it's requested via the UI
// we disable live autocomplete, as it makes typing slower.
if (tokensCount > 5000 || !$scope.$parent.autocompleteQuery) {
editor.setOption('enableLiveAutocompletion', false);
editor.setOption('enableBasicAutocompletion', false);
} else {
Expand All @@ -134,6 +135,10 @@ function queryEditor(QuerySnippet) {
$scope.$parent.$on('angular-resizable.resizing', () => {
editor.resize();
});
$scope.$parent.$watch('autocompleteQuery', () => {
editor.setOption('enableLiveAutocompletion', $scope.$parent.autocompleteQuery);
editor.setOption('enableBasicAutocompletion', $scope.$parent.autocompleteQuery);
});

editor.focus();
},
Expand Down
16 changes: 16 additions & 0 deletions client/app/pages/queries/query.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,22 @@ <h3>
</schema-browser>
</div>

<div class="pull-right">
<div class="btn-group hidden-print visible-sm-inline-block visible-xs-inline-block visible-md-inline-block" role="group" uib-dropdown>
<button class="btn btn-default btn-sm dropdown-toggle" uib-dropdown-toggle>
<span class="zmdi zmdi-format-indent-increase"></span>
</button>
<ul class="dropdown-menu pull-right" uib-dropdown-menu>
<li ng-if="!autocompleteQuery"><a ng-click="toggleAutocompleteQuery()">Enable Autocomplete</a></li>
<li ng-if="autocompleteQuery"><a ng-click="toggleAutocompleteQuery()">Disable Autocomplete</a></li>
<li><a ng-click="formatQuery()">Format query</a></li>
</ul>
</div>
<label class="visible-lg-inline-block">
<input type="checkbox" ng-model="autocompleteQuery">
<span class="fa fa-magic"></span> Autocomplete
</label>
<button type="button" class="btn btn-default btn-s visible-lg-inline-block" ng-click="formatQuery()">
<div class="col-md-9 p-r-0" style="height:100%;">
<div class="editor__control">
<div class="form-inline">
Expand Down
5 changes: 5 additions & 0 deletions client/app/pages/queries/source-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ function QuerySourceCtrl(
.catch(error => toastr.error(error));
};

$scope.autocompleteQuery = true;
$scope.toggleAutocompleteQuery = () => {
$scope.autocompleteQuery = !$scope.autocompleteQuery;
};

$scope.duplicateQuery = () => {
Query.fork({ id: $scope.query.id }, (newQuery) => {
$location.url(newQuery.getSourceLink()).replace();
Expand Down

0 comments on commit 08af871

Please sign in to comment.