From 8cde08bd833a8f5a1466fad66cc6475ffdc12475 Mon Sep 17 00:00:00 2001 From: Yuanhai He Date: Fri, 27 Jul 2018 08:47:41 +0800 Subject: [PATCH] improvement: allow viewing model when Try-It-Out is enabled (via #4723) --- src/core/components/model-example.jsx | 20 +++++++++++++------- src/style/_layout.scss | 4 ++-- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/core/components/model-example.jsx b/src/core/components/model-example.jsx index e7d13ada..499da2de 100644 --- a/src/core/components/model-example.jsx +++ b/src/core/components/model-example.jsx @@ -15,13 +15,13 @@ export default class ModelExample extends React.Component { constructor(props, context) { super(props, context) - let { getConfigs } = this.props + let { getConfigs, isExecute } = this.props let { defaultModelRendering } = getConfigs() if (defaultModelRendering !== "example" && defaultModelRendering !== "model") { defaultModelRendering = "example" } this.state = { - activeTab: defaultModelRendering + activeTab: isExecute ? "example" : defaultModelRendering } } @@ -33,6 +33,12 @@ export default class ModelExample extends React.Component { }) } + componentWillReceiveProps(props) { + if (props.isExecute && props.isExecute !== this.props.isExecute) { + this.setState({ activeTab: "example" }) + } + } + render() { let { getComponent, specSelectors, schema, example, isExecute, getConfigs, specPath } = this.props let { defaultModelExpandDepth } = getConfigs() @@ -40,19 +46,19 @@ export default class ModelExample extends React.Component { return
{ - (isExecute || this.state.activeTab === "example") && example + this.state.activeTab === "example" && example } { - !isExecute && this.state.activeTab === "model" &&