Skip to content

Commit 0426eb2

Browse files
tim-laishockey
andcommitted
housekeeping: prevent log warning for missing getComponent in production
This is a force-pushed squash of two PR merges (#5919, #5940) that were formerly present on master as individual commits. Co-Authored-By: kyle shockey <[email protected]>
1 parent 12e86da commit 0426eb2

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/core/json-schema-components.jsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,15 @@ export class JsonSchemaForm extends Component {
5050
schema = schema.toJS()
5151

5252
let { type, format="" } = schema
53+
// In the json schema rendering code, we optimistically query our system for a number of components.
54+
// If the component doesn't exist, we optionally suppress these warnings.
55+
let getComponentSilently = (name) => getComponent(name, false, { failSilently: true })
56+
57+
let Comp = (format ?
58+
getComponentSilently(`JsonSchema_${type}_${format}`) :
59+
getComponentSilently(`JsonSchema_${type}`)) ||
60+
getComponentSilently("JsonSchema_string")
5361

54-
let Comp = (format ? getComponent(`JsonSchema_${type}_${format}`) : getComponent(`JsonSchema_${type}`)) || getComponent("JsonSchema_string")
5562
return <Comp { ...this.props } errors={errors} fn={fn} getComponent={getComponent} value={value} onChange={onChange} schema={schema} disabled={disabled}/>
5663
}
5764

src/core/plugins/view/root-injects.jsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,20 @@ const wrapRender = (component) => {
101101
}
102102

103103

104-
export const getComponent = (getSystem, getStore, getComponents, componentName, container) => {
104+
export const getComponent = (getSystem, getStore, getComponents, componentName, container, config = {}) => {
105105

106106
if(typeof componentName !== "string")
107107
throw new TypeError("Need a string, to fetch a component. Was given a " + typeof componentName)
108108

109+
// getComponent has a config object as a third, optional parameter
110+
// using the config object requires the presence of the second parameter, container
111+
// e.g. getComponent("JsonSchema_string_whatever", false, { failSilently: true })
109112
let component = getComponents(componentName)
110113

111114
if(!component) {
112-
getSystem().log.warn("Could not find component", componentName)
115+
if (!config.failSilently) {
116+
getSystem().log.warn("Could not find component:", componentName)
117+
}
113118
return null
114119
}
115120

0 commit comments

Comments
 (0)