Skip to content

Commit

Permalink
[Canvas] Fix context elements issue with Element Stats (elastic#32510) (
Browse files Browse the repository at this point in the history
elastic#32540)

## Summary

(closes elastic#32512, closes elastic#32508)

This fixes a bug where element stats was causing a failure due to not every element being an `expressionRenderable` all the time... when first added, `TimeFilter` is `expressionContext` and should be considered `pending`.

This PR also fixes an issue where `resolvedArgs` was not being reset between workpad loads, causing element stats to be compounded.

Co-authored-by: Spencer <[email protected]>
  • Loading branch information
clintandrewhall and Spencer authored Mar 6, 2019
1 parent da4d464 commit 53d41bf
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const ElementConfig = ({ elementStats }) => {
}

const { total, ready, error } = elementStats;
const progress = Math.round(((ready + error) / total) * 100);
const progress = total > 0 ? Math.round(((ready + error) / total) * 100) : 100;

return (
<Fragment>
Expand Down
4 changes: 4 additions & 0 deletions x-pack/plugins/canvas/public/state/reducers/resolved_args.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { get } from 'lodash';
import { prepend } from '../../lib/modify_path';
import * as actions from '../actions/resolved_args';
import { flushContext, flushContextAfterIndex } from '../actions/elements';
import { setWorkpad } from '../actions/workpad';

/*
Resolved args are a way to handle async values. They track the status, value, and error
Expand Down Expand Up @@ -130,6 +131,9 @@ export const resolvedArgsReducer = handleActions(
return state;
}, transientState);
},
[setWorkpad]: (transientState, {}) => {
return set(transientState, 'resolvedArgs', {});
},
},
{}
);
6 changes: 6 additions & 0 deletions x-pack/plugins/canvas/public/state/selectors/workpad.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ export function getElementCounts(state) {
Object.keys(resolvedArgs).forEach(resolvedArg => {
const arg = resolvedArgs[resolvedArg];
const { expressionRenderable } = arg;

if (!expressionRenderable) {
results.pending++;
return;
}

const { value, state } = expressionRenderable;

if (value && value.as === 'error') {
Expand Down

0 comments on commit 53d41bf

Please sign in to comment.