Skip to content

Commit

Permalink
housekeeping: prevent log warning for missing getComponent in production
Browse files Browse the repository at this point in the history
This is a force-pushed squash of two PR merges (swagger-api#5919, swagger-api#5940) that were
formerly present on master as individual commits.

Co-Authored-By: kyle shockey <kyleshockey@gmail.com>
  • Loading branch information
2 people authored and mattyb678 committed Jun 24, 2020
1 parent 5b3c799 commit 8e73d27
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/core/json-schema-components.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,15 @@ export class JsonSchemaForm extends Component {
schema = schema.toJS()

let { type, format="" } = schema
// 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")

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

Expand Down
9 changes: 7 additions & 2 deletions src/core/plugins/view/root-injects.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,20 @@ const wrapRender = (component) => {
}


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
}

Expand Down

0 comments on commit 8e73d27

Please sign in to comment.