Skip to content

Commit

Permalink
Second iteration of fix, previous had race condition :gasp:
Browse files Browse the repository at this point in the history
  • Loading branch information
jloleysens committed Nov 13, 2019
1 parent 151a6f3 commit 1a1f687
Showing 1 changed file with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,21 +125,14 @@ export class JobCreateUi extends Component {
const { clearCloneJob, jobToClone } = this.props;
if (jobToClone) {
clearCloneJob();
this.requestIndexPatternValidation();
this.requestIndexPatternValidation(false);
}
}

componentDidUpdate(prevProps, prevState) {
const indexPattern = this.getIndexPattern();
if (indexPattern !== this.getIndexPattern(prevState)) {
const { indexPatternDateFields } = this.state;
// Whenever the index pattern changes we re-select the first date field.
this.onFieldsChange(
{
dateHistogramField: indexPatternDateFields.length ? indexPatternDateFields[0] : undefined,
},
STEP_DATE_HISTOGRAM
);


// If the user hasn't entered anything, then skip validation.
if (!indexPattern || !indexPattern.trim()) {
Expand Down Expand Up @@ -168,7 +161,7 @@ export class JobCreateUi extends Component {
this.props.clearCreateJobErrors();
}

requestIndexPatternValidation = debounce(() => {
requestIndexPatternValidation = debounce((resetDefaults = true) => {
const indexPattern = this.getIndexPattern();

const lastIndexPatternValidationTime = this.lastIndexPatternValidationTime = Date.now();
Expand Down Expand Up @@ -274,6 +267,17 @@ export class JobCreateUi extends Component {

indexPatternDateFields.sort();

if (resetDefaults) {
const { indexPatternDateFields } = this.state;
// Whenever the index pattern changes we default to the first date field if there is one.
this.onFieldsChange(
{
dateHistogramField: indexPatternDateFields.length ? indexPatternDateFields[0] : undefined,
},
STEP_DATE_HISTOGRAM
);
}

this.setState({
indexPatternAsyncErrors,
indexPatternDateFields,
Expand Down

0 comments on commit 1a1f687

Please sign in to comment.