From 305e6ee893c28d02e7189dfdc3afebf4725c31d4 Mon Sep 17 00:00:00 2001 From: Timothy Lai Date: Fri, 13 Mar 2020 10:41:38 -0700 Subject: [PATCH] prevent log warning for missing getComponent in production --- src/core/json-schema-components.jsx | 9 +++++++-- src/core/plugins/view/root-injects.jsx | 10 +++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/core/json-schema-components.jsx b/src/core/json-schema-components.jsx index c5f1181dad3..e3e2ecdcbdf 100644 --- a/src/core/json-schema-components.jsx +++ b/src/core/json-schema-components.jsx @@ -50,8 +50,13 @@ export class JsonSchemaForm extends Component { schema = schema.toJS() let { type, format="" } = schema - - let Comp = (format ? getComponent(`JsonSchema_${type}_${format}`) : getComponent(`JsonSchema_${type}`)) || getComponent("JsonSchema_string") + // In the json schema rendering code, we optimistically query our system for a number of components. + // If the component doesn't exist, we optionally suppress these warnings. + let getComponentSilently = (name) => getComponent(name, false, { failSilently: true }) + let Comp = (format ? + getComponentSilently(`JsonSchema_${type}_${format}`) : + getComponentSilently(`JsonSchema_${type}`)) || + getComponentSilently("JsonSchema_string") return } diff --git a/src/core/plugins/view/root-injects.jsx b/src/core/plugins/view/root-injects.jsx index d977400ddee..a25c479b55b 100644 --- a/src/core/plugins/view/root-injects.jsx +++ b/src/core/plugins/view/root-injects.jsx @@ -100,16 +100,20 @@ const wrapRender = (component) => { return target } - -export const getComponent = (getSystem, getStore, getComponents, componentName, container) => { +export const getComponent = (getSystem, getStore, getComponents, componentName, container, config = {}) => { if(typeof componentName !== "string") throw new TypeError("Need a string, to fetch a component. Was given a " + typeof componentName) + // getComponent has a config object as a third, optional parameter + // using the config object requires the presence of the second parameter, container + // e.g. getComponent("JsonSchema_string_whatever", false, { failSilently: true }) let component = getComponents(componentName) if(!component) { - getSystem().log.warn("Could not find component", componentName) + if (!config.failSilently) { + getSystem().log.warn("Could not find component:", componentName) + } return null }