Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refresh query when parameters update #3737

Merged
merged 24 commits into from
May 15, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
bd50110
Add touch state to parameters and autoupdate query
gabrieldutra Apr 24, 2019
5c2bc12
Use values change event instead of $watch
gabrieldutra Apr 28, 2019
e16bc91
Remove getQueryResultDebounced
gabrieldutra Apr 28, 2019
dd730e5
Add Apply button
gabrieldutra Apr 29, 2019
134334e
Remove Input Number spinners for Parameters
gabrieldutra Apr 29, 2019
d800e39
Make Apply Button optional
gabrieldutra Apr 30, 2019
5955360
Merge branch 'master' into parameters-apply-button
gabrieldutra May 2, 2019
043cf67
Update share_embed_spec
gabrieldutra May 5, 2019
523da04
Change debounce to the Parameters component
gabrieldutra May 5, 2019
3cf9274
Merge branch 'master' into parameters-apply-button
gabrieldutra May 5, 2019
c43e19b
Remove unnecessary click on Execute query
gabrieldutra May 5, 2019
daa1f29
Add apply button to the remaining places
gabrieldutra May 5, 2019
bf123bd
Update dashboard_spec
gabrieldutra May 6, 2019
1ca6457
Use onKeyUp for InputNumber
gabrieldutra May 6, 2019
61d4fb4
Simplify onParametersValuesChanged
gabrieldutra May 6, 2019
ea41602
Update DateTime onChange function
gabrieldutra May 6, 2019
9a292aa
Don't apply when modifier key is pressed
gabrieldutra May 6, 2019
1359e7b
Merge branch 'master' into parameters-apply-button
gabrieldutra May 6, 2019
999ca5c
Remove refresh Button from Parameters
gabrieldutra May 6, 2019
4386e46
Update apply button styling
gabrieldutra May 10, 2019
4c6f7f5
Update apply right distance
gabrieldutra May 10, 2019
bc0f418
Remove debounce for testing
gabrieldutra May 10, 2019
a55edb8
Use data-dirty instead of classNames for styling
gabrieldutra May 13, 2019
96624d4
Make sure $apply runs before calling onChange
gabrieldutra May 13, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions client/app/pages/queries/view.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { pick, some, find, minBy, map, intersection, isArray, isObject } from 'lodash';
import { debounce, pick, some, isEmpty, find, filter, minBy, map, intersection, isArray, isObject } from 'lodash';
import { SCHEMA_NOT_SUPPORTED, SCHEMA_LOAD_ERROR } from '@/services/data-source';
import getTags from '@/services/getTags';
import { policy } from '@/services/policy';
Expand Down Expand Up @@ -27,7 +27,7 @@ function QueryViewCtrl(
DataSource,
Visualization,
) {
function getQueryResult(maxAge, selectedQueryText) {
function getQueryResult(maxAge, selectedQueryText, parameters) {
if (maxAge === undefined) {
maxAge = $location.search().maxAge;
}
Expand All @@ -38,12 +38,13 @@ function QueryViewCtrl(

$scope.showLog = false;
if ($scope.isDirty) {
$scope.queryResult = $scope.query.getQueryResultByText(maxAge, selectedQueryText);
$scope.queryResult = $scope.query.getQueryResultByText(maxAge, selectedQueryText, parameters);
} else {
$scope.queryResult = $scope.query.getQueryResult(maxAge);
$scope.queryResult = $scope.query.getQueryResult(maxAge, parameters);
}
}

const getQueryResultDebounced = debounce(getQueryResult, 1000);

function getDataSourceId() {
// Try to get the query's data source id
Expand Down Expand Up @@ -124,6 +125,7 @@ function QueryViewCtrl(
return;
}

getQueryResultDebounced.cancel();
getQueryResult(0, $scope.selectedQueryText);
$scope.lockButton(true);
$scope.cancelling = false;
Expand Down Expand Up @@ -422,6 +424,16 @@ function QueryViewCtrl(
}
});

$scope.$watch('query.getParametersDefs()', (parameters) => {
const touchedParameters = filter(parameters, { touched: true });

if (!isEmpty(touchedParameters)) {
getQueryResultDebounced(0, $scope.selectedQueryText);
} else {
getQueryResultDebounced.cancel();
}
}, true);

function getVisualization(visId) {
// eslint-disable-next-line eqeqeq
return find($scope.query.visualizations, item => item.id == visId);
Expand Down
27 changes: 23 additions & 4 deletions client/app/services/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ export class Parameter {
// validate value and init internal state
this.setValue(parameter.value);

// define touch state based on last query result value
this.lastQueryResultValue = parameter.value;
Object.defineProperty(this, 'touched', { get: () => this.value !== this.lastQueryResultValue });

// Used for URL serialization
Object.defineProperty(this, 'urlPrefix', {
configurable: true,
Expand Down Expand Up @@ -527,14 +531,29 @@ function QueryResource(
return this.queryResult;
};

QueryService.prototype.getQueryResult = function getQueryResult(maxAge) {
const execute = () => QueryResult.getByQueryId(this.id, this.getParameters().getValues(), maxAge);
QueryService.prototype.getQueryResult = function getQueryResult(maxAge, parameters) {
if (parameters === undefined) {
parameters = this.getParameters().getValues();
}

this.getParametersDefs().forEach((param) => {
param.lastQueryResultValue = parameters[param.name];
});

const execute = () => QueryResult.getByQueryId(this.id, parameters, maxAge);
return this.prepareQueryResultExecution(execute, maxAge);
};

QueryService.prototype.getQueryResultByText = function getQueryResultByText(maxAge, selectedQueryText) {
QueryService.prototype.getQueryResultByText = function getQueryResultByText(maxAge, selectedQueryText, parameters) {
if (parameters === undefined) {
parameters = this.getParameters().getValues();
}

this.getParametersDefs().forEach((param) => {
param.lastQueryResultValue = parameters[param.name];
});

const queryText = selectedQueryText || this.query;
const parameters = this.getParameters().getValues();
const execute = () => QueryResult.get(this.data_source_id, queryText, parameters, maxAge, this.id);
return this.prepareQueryResultExecution(execute, maxAge);
};
Expand Down