From 53d41bfcbd904100af762176873be672692dd29f Mon Sep 17 00:00:00 2001 From: Clint Andrew Hall Date: Tue, 5 Mar 2019 21:50:41 -0600 Subject: [PATCH] [Canvas] Fix context elements issue with Element Stats (#32510) (#32540) ## Summary (closes #32512, closes #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 --- .../public/components/element_config/element_config.js | 2 +- .../plugins/canvas/public/state/reducers/resolved_args.js | 4 ++++ x-pack/plugins/canvas/public/state/selectors/workpad.js | 6 ++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/canvas/public/components/element_config/element_config.js b/x-pack/plugins/canvas/public/components/element_config/element_config.js index d0f68cb71b72d..e5ae933655802 100644 --- a/x-pack/plugins/canvas/public/components/element_config/element_config.js +++ b/x-pack/plugins/canvas/public/components/element_config/element_config.js @@ -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 ( diff --git a/x-pack/plugins/canvas/public/state/reducers/resolved_args.js b/x-pack/plugins/canvas/public/state/reducers/resolved_args.js index a87a363c2e6f7..371683d6fa84a 100644 --- a/x-pack/plugins/canvas/public/state/reducers/resolved_args.js +++ b/x-pack/plugins/canvas/public/state/reducers/resolved_args.js @@ -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 @@ -130,6 +131,9 @@ export const resolvedArgsReducer = handleActions( return state; }, transientState); }, + [setWorkpad]: (transientState, {}) => { + return set(transientState, 'resolvedArgs', {}); + }, }, {} ); diff --git a/x-pack/plugins/canvas/public/state/selectors/workpad.js b/x-pack/plugins/canvas/public/state/selectors/workpad.js index 857e748eb874a..66e82f0cbab86 100644 --- a/x-pack/plugins/canvas/public/state/selectors/workpad.js +++ b/x-pack/plugins/canvas/public/state/selectors/workpad.js @@ -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') {