diff --git a/src/core/components/operations.jsx b/src/core/components/operations.jsx index b50e2afb4cf..0b0836a6af6 100644 --- a/src/core/components/operations.jsx +++ b/src/core/components/operations.jsx @@ -28,89 +28,78 @@ export default class Operations extends React.Component { render() { let { specSelectors, + } = this.props + + const taggedOps = specSelectors.taggedOperations() + + if(taggedOps.size === 0) { + return

No operations defined in spec!

+ } + + return ( +
+ { taggedOps.map(this.renderOperationTag).toArray() } + { taggedOps.size < 1 ?

No operations defined in spec!

: null } +
+ ) + } + + renderOperationTag = (tagObj, tag) => { + const { + specSelectors, getComponent, oas3Selectors, layoutSelectors, layoutActions, getConfigs, - fn } = this.props - - let taggedOps = specSelectors.taggedOperations() - const OperationContainer = getComponent("OperationContainer", true) const OperationTag = getComponent("OperationTag") + const operations = tagObj.get("operations") + return ( + +
+ { + operations.map(op => { + const path = op.get("path") + const method = op.get("method") + const specPath = Im.List(["paths", path, method]) - let { - maxDisplayedTags, - } = getConfigs() - - let filter = layoutSelectors.currentFilter() - if (filter) { - if (filter !== true && filter !== "true" && filter !== "false") { - taggedOps = fn.opsFilter(taggedOps, filter) - } - } + // FIXME: (someday) this logic should probably be in a selector, + // but doing so would require further opening up + // selectors to the plugin system, to allow for dynamic + // overriding of low-level selectors that other selectors + // rely on. --KS, 12/17 + const validMethods = specSelectors.isOAS3() ? + OAS3_OPERATION_METHODS : SWAGGER2_OPERATION_METHODS - if (maxDisplayedTags && !isNaN(maxDisplayedTags) && maxDisplayedTags >= 0) { - taggedOps = taggedOps.slice(0, maxDisplayedTags) - } + if (validMethods.indexOf(method) === -1) { + return null + } - return ( -
- { - taggedOps.map( (tagObj, tag) => { - const operations = tagObj.get("operations") return ( - - { - operations.map( op => { - const path = op.get("path") - const method = op.get("method") - const specPath = Im.List(["paths", path, method]) - - - // FIXME: (someday) this logic should probably be in a selector, - // but doing so would require further opening up - // selectors to the plugin system, to allow for dynamic - // overriding of low-level selectors that other selectors - // rely on. --KS, 12/17 - const validMethods = specSelectors.isOAS3() ? - OAS3_OPERATION_METHODS : SWAGGER2_OPERATION_METHODS - - if(validMethods.indexOf(method) === -1) { - return null - } - - return - }).toArray() - } - - - + ) }).toArray() } - - { taggedOps.size < 1 ?

No operations defined in spec!

: null }
+ ) } diff --git a/src/core/plugins/layout/index.js b/src/core/plugins/layout/index.js index f96af37a9e1..51dd9117e16 100644 --- a/src/core/plugins/layout/index.js +++ b/src/core/plugins/layout/index.js @@ -1,6 +1,7 @@ import reducers from "./reducers" import * as actions from "./actions" import * as selectors from "./selectors" +import * as wrapSelectors from "./spec-extensions/wrap-selector" export default function() { return { @@ -9,6 +10,9 @@ export default function() { reducers, actions, selectors + }, + spec: { + wrapSelectors } } } diff --git a/src/core/plugins/layout/spec-extensions/wrap-selector.js b/src/core/plugins/layout/spec-extensions/wrap-selector.js new file mode 100644 index 00000000000..712980179e0 --- /dev/null +++ b/src/core/plugins/layout/spec-extensions/wrap-selector.js @@ -0,0 +1,22 @@ + +export const taggedOperations = (oriSelector, system) => (state, ...args) => { + let taggedOps = oriSelector(state, ...args) + + const { fn, layoutSelectors, getConfigs } = system.getSystem() + const configs = getConfigs() + const { maxDisplayedTags } = configs + + // Filter, if requested + let filter = layoutSelectors.currentFilter() + if (filter) { + if (filter !== true && filter !== "true" && filter !== "false") { + taggedOps = fn.opsFilter(taggedOps, filter) + } + } + // Limit to [max] items, if specified + if (maxDisplayedTags && !isNaN(maxDisplayedTags) && maxDisplayedTags >= 0) { + taggedOps = taggedOps.slice(0, maxDisplayedTags) + } + + return taggedOps +}