diff --git a/src/core/components/execute.jsx b/src/core/components/execute.jsx index 8d114b14..23546ad6 100644 --- a/src/core/components/execute.jsx +++ b/src/core/components/execute.jsx @@ -8,7 +8,6 @@ export default class Execute extends Component { specActions: PropTypes.object.isRequired, operation: PropTypes.object.isRequired, path: PropTypes.string.isRequired, - getComponent: PropTypes.func.isRequired, method: PropTypes.string.isRequired, onExecute: PropTypes.func } diff --git a/src/core/components/operation.jsx b/src/core/components/operation.jsx index fbf8ca60..be255b65 100644 --- a/src/core/components/operation.jsx +++ b/src/core/components/operation.jsx @@ -1,29 +1,19 @@ import React, { PureComponent } from "react" import PropTypes from "prop-types" import { getList } from "core/utils" -import * as CustomPropTypes from "core/proptypes" - -//import "less/opblock" +import { Iterable } from "immutable" export default class Operation extends PureComponent { static propTypes = { - path: PropTypes.string.isRequired, - method: PropTypes.string.isRequired, - operation: PropTypes.object.isRequired, - showSummary: PropTypes.bool, + operation: PropTypes.instanceOf(Iterable).isRequired, - isShownKey: CustomPropTypes.arrayOrString.isRequired, - jumpToKey: CustomPropTypes.arrayOrString.isRequired, - - allowTryItOut: PropTypes.bool, - - displayOperationId: PropTypes.bool, - displayRequestDuration: PropTypes.bool, - - response: PropTypes.object, - request: PropTypes.object, + toggleShown: PropTypes.func.isRequired, + onTryoutClick: PropTypes.func.isRequired, + onCancelClick: PropTypes.func.isRequired, + onExecute: PropTypes.func.isRequired, getComponent: PropTypes.func.isRequired, + getConfigs: PropTypes.func.isRequired, authActions: PropTypes.object, authSelectors: PropTypes.object, specActions: PropTypes.object.isRequired, @@ -31,8 +21,7 @@ export default class Operation extends PureComponent { oas3Actions: PropTypes.object.isRequired, layoutActions: PropTypes.object.isRequired, layoutSelectors: PropTypes.object.isRequired, - fn: PropTypes.object.isRequired, - getConfigs: PropTypes.func.isRequired + fn: PropTypes.object.isRequired } static defaultProps = { @@ -43,95 +32,59 @@ export default class Operation extends PureComponent { displayRequestDuration: false } - constructor(props, context) { - super(props, context) - this.state = { - tryItOutEnabled: false - } - } - - componentWillReceiveProps(nextProps) { - const defaultContentType = "application/json" - let { specActions, path, method, operation } = nextProps - let producesValue = operation.get("produces_value") - let produces = operation.get("produces") - let consumes = operation.get("consumes") - let consumesValue = operation.get("consumes_value") - - if(nextProps.response !== this.props.response) { - this.setState({ executeInProgress: false }) - } - - if (producesValue === undefined) { - producesValue = produces && produces.size ? produces.first() : defaultContentType - specActions.changeProducesValue([path, method], producesValue) - } - - if (consumesValue === undefined) { - consumesValue = consumes && consumes.size ? consumes.first() : defaultContentType - specActions.changeConsumesValue([path, method], consumesValue) - } - } - - toggleShown =() => { - let { layoutActions, isShownKey } = this.props - layoutActions.show(isShownKey, !this.isShown()) - } - - isShown =() => { - let { layoutSelectors, isShownKey, getConfigs } = this.props - let { docExpansion } = getConfigs() - - return layoutSelectors.isShown(isShownKey, docExpansion === "full" ) // Here is where we set the default - } - - onTryoutClick =() => { - this.setState({tryItOutEnabled: !this.state.tryItOutEnabled}) - } - - onCancelClick =() => { - let { specActions, path, method } = this.props - this.setState({tryItOutEnabled: !this.state.tryItOutEnabled}) - specActions.clearValidateParams([path, method]) - } - - onExecute = () => { - this.setState({ executeInProgress: true }) + shouldComponentUpdate(nextProps) { + return this.props.operation !== nextProps.operation } render() { let { - isShownKey, - jumpToKey, - path, - method, - operation, - showSummary, - response, - request, - allowTryItOut, - displayOperationId, - displayRequestDuration, + toggleShown, + onTryoutClick, + onCancelClick, + onExecute, fn, getComponent, + getConfigs, specActions, specSelectors, authActions, authSelectors, - getConfigs, oas3Actions } = this.props + let operationProps = this.props.operation - let summary = operation.get("summary") - let description = operation.get("description") - let deprecated = operation.get("deprecated") - let externalDocs = operation.get("externalDocs") + let { + isShown, + isShownKey, + jumpToKey, + path, + method, + op, + showSummary, + operationId, + allowTryItOut, + displayOperationId, + displayRequestDuration, + isDeepLinkingEnabled, + tryItOutEnabled, + executeInProgress + } = operationProps.toJS() + let response = operationProps.get("response") + let request = operationProps.get("request") + + let { + summary, + description, + deprecated, + externalDocs, + schemes + } = op.operation + + let operation = operationProps.getIn(["op", "operation"]) let responses = operation.get("responses") - let security = operation.get("security") || specSelectors.security() let produces = operation.get("produces") - let schemes = operation.get("schemes") + let security = operation.get("security") || specSelectors.security() let parameters = getList(operation, ["parameters"]) - let operationId = operation.get("__originalOperationId") let operationScheme = specSelectors.operationScheme(path, method) const Responses = getComponent("responses") @@ -144,23 +97,17 @@ export default class Operation extends PureComponent { const Markdown = getComponent( "Markdown" ) const Schemes = getComponent( "schemes" ) - const { deepLinking } = getConfigs() - - const isDeepLinkingEnabled = deepLinking && deepLinking !== "false" - // Merge in Live Response - if(response && response.size > 0) { + if(responses && response && response.size > 0) { let notDocumented = !responses.get(String(response.get("status"))) response = response.set("notDocumented", notDocumented) } - let { tryItOutEnabled } = this.state - let shown = this.isShown() let onChangeKey = [ path, method ] // Used to add values to _this_ operation ( indexed by path and method ) return ( -
-
+
+
{method.toUpperCase()} - +
{ deprecated &&

Warning: Deprecated

} { description && @@ -214,8 +161,8 @@ export default class Operation extends PureComponent { parameters={parameters} operation={operation} onChangeKey={onChangeKey} - onTryoutClick = { this.onTryoutClick } - onCancelClick = { this.onCancelClick } + onTryoutClick = { onTryoutClick } + onCancelClick = { onCancelClick } tryItOutEnabled = { tryItOutEnabled } allowTryItOut={allowTryItOut} @@ -239,25 +186,23 @@ export default class Operation extends PureComponent { { !tryItOutEnabled || !allowTryItOut ? null : + onExecute={ onExecute } /> } { (!tryItOutEnabled || !response || !allowTryItOut) ? null : }
- {this.state.executeInProgress ?
: null} + {executeInProgress ?
: null} { !responses ? null : { operations.map( op => { + const path = op.get("path") + const method = op.get("method") - const path = op.get("path", "") - const method = op.get("method", "") - const jumpToKey = `paths.${path}.${method}` - - const operationId = - op.getIn(["operation", "operationId"]) || op.getIn(["operation", "__originalOperationId"]) || opId(op.get("operation"), path, method) || op.get("id") - const isShownKey = ["operations", createDeepLinkPath(tag), createDeepLinkPath(operationId)] - - const allowTryItOut = specSelectors.allowTryItOutFor(op.get("path"), op.get("method")) - const response = specSelectors.responseFor(op.get("path"), op.get("method")) - const request = specSelectors.requestFor(op.get("path"), op.get("method")) - - return { + let { layoutActions, isShownKey, isShown } = this.props + layoutActions.show(isShownKey, !isShown) + } + + onTryoutClick =() => { + this.setState({tryItOutEnabled: !this.state.tryItOutEnabled}) + } + + onCancelClick =() => { + let { specActions, path, method } = this.props + this.setState({tryItOutEnabled: !this.state.tryItOutEnabled}) + specActions.clearValidateParams([path, method]) + } + + onExecute = () => { + this.setState({ executeInProgress: true }) + } + + render() { + let { + op, + tag, + path, + method, + operationId, + showSummary, + isShown, + isShownKey, + jumpToKey, + allowTryItOut, + response, + request, + displayOperationId, + displayRequestDuration, + isDeepLinkingEnabled, + specSelectors, + specActions, + getComponent, + getConfigs, + layoutSelectors, + layoutActions, + authActions, + authSelectors, + fn + } = this.props + + const Operation = getComponent( "operation" ) + + const operationProps = fromJS({ + op, + tag, + path, + method, + operationId, + showSummary, + isShown, + isShownKey, + jumpToKey, + allowTryItOut, + response, + request, + displayOperationId, + displayRequestDuration, + isDeepLinkingEnabled, + executeInProgress: this.state.executeInProgress, + tryItOutEnabled: this.state.tryItOutEnabled + }) + + return ( + + ) + } + +} diff --git a/src/core/index.js b/src/core/index.js index ddf162ab..bac7cdc9 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -7,8 +7,7 @@ import * as AllPlugins from "core/plugins/all" import { parseSearch } from "core/utils" if (process.env.NODE_ENV !== "production") { - const Perf = require("react-addons-perf") - window.Perf = Perf + window.Perf = require("react-addons-perf") } // eslint-disable-next-line no-undef diff --git a/src/core/plugins/view/root-injects.js b/src/core/plugins/view/root-injects.js index b916bee3..568ac6ac 100644 --- a/src/core/plugins/view/root-injects.js +++ b/src/core/plugins/view/root-injects.js @@ -20,7 +20,7 @@ const RootWrapper = (reduxStore, ComponentToWrap) => class extends Component { } const makeContainer = (getSystem, component, reduxStore) => { - const mapStateToProps = component.prototype.constructor.mapStateToProps || function(state) { + const mapStateToProps = component.prototype.mapStateToProps || function(state) { return {state} } let wrappedWithSystem = SystemWrapper(getSystem, component, reduxStore) diff --git a/src/core/presets/base.js b/src/core/presets/base.js index 10a12645..c22f2255 100644 --- a/src/core/presets/base.js +++ b/src/core/presets/base.js @@ -12,6 +12,8 @@ import SplitPaneModePlugin from "core/plugins/split-pane-mode" import downloadUrlPlugin from "core/plugins/download-url" import deepLinkingPlugin from "core/plugins/deep-linking" +import OperationContainer from "core/containers/OperationContainer" + import App from "core/components/app" import AuthorizationPopup from "core/components/auth/authorization-popup" import AuthorizeBtn from "core/components/auth/authorize-btn" @@ -107,7 +109,8 @@ export default function() { TryItOutButton, Markdown, BaseLayout, - VersionStamp + VersionStamp, + OperationContainer } } diff --git a/src/core/system.js b/src/core/system.js index e4eee5b8..06071bc9 100644 --- a/src/core/system.js +++ b/src/core/system.js @@ -289,8 +289,7 @@ export default class Store { getMapStateToProps() { return () => { - let obj = Object.assign({}, this.getSystem()) - return obj + return Object.assign({}, this.getSystem()) } }