Skip to content

Commit

Permalink
Fix Apply Changes is lost when query is edited (getredash#4010)
Browse files Browse the repository at this point in the history
Co-Authored-By: Ran Byron <[email protected]>
  • Loading branch information
2 people authored and harveyrendell committed Nov 14, 2019
1 parent 01336b8 commit dc08ba2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
13 changes: 8 additions & 5 deletions client/app/components/ParameterValueInput.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,19 @@ export class ParameterValueInput extends React.Component {
constructor(props) {
super(props);
this.state = {
value: props.value,
isDirty: false,
value: props.parameter.hasPendingValue ? props.parameter.pendingValue : props.value,
isDirty: props.parameter.hasPendingValue,
};
}

componentDidUpdate = (prevProps) => {
const { value } = this.props;
const { value, parameter } = this.props;
// if value prop updated, reset dirty state
if (prevProps.value !== value) {
this.setState({ value, isDirty: false });
if (prevProps.value !== value || prevProps.parameter !== parameter) {
this.setState({
value: parameter.hasPendingValue ? parameter.pendingValue : value,
isDirty: parameter.hasPendingValue,
});
}
}

Expand Down
10 changes: 9 additions & 1 deletion 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 } from 'lodash';
import { pick, some, find, minBy, map, intersection, isArray, omit } 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 @@ -253,6 +253,14 @@ function QueryViewCtrl(
delete request.version;
}

// omit pendingValue before saving
if (request.options && request.options.parameters) {
request.options = {
...request.options,
parameters: map(request.options.parameters, p => omit(p, 'pendingValue')),
};
}

function overwrite() {
options.force = true;
$scope.saveQuery(options, data);
Expand Down
3 changes: 2 additions & 1 deletion client/app/services/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,8 @@ class Parameters {

const parameterExists = p => includes(parameterNames, p.name);
const parameters = this.query.options.parameters;
this.query.options.parameters = parameters.filter(parameterExists).map(p => new Parameter(p, this.query.id));
this.query.options.parameters = parameters.filter(parameterExists)
.map(p => (p instanceof Parameter ? p : new Parameter(p, this.query.id)));
}

initFromQueryString(query) {
Expand Down

0 comments on commit dc08ba2

Please sign in to comment.