refactor: operations component (#7044)
This commit is contained in:
@@ -28,39 +28,33 @@ export default class Operations extends React.Component {
|
|||||||
render() {
|
render() {
|
||||||
let {
|
let {
|
||||||
specSelectors,
|
specSelectors,
|
||||||
|
} = this.props
|
||||||
|
|
||||||
|
const taggedOps = specSelectors.taggedOperations()
|
||||||
|
|
||||||
|
if(taggedOps.size === 0) {
|
||||||
|
return <h3> No operations defined in spec!</h3>
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
{ taggedOps.map(this.renderOperationTag).toArray() }
|
||||||
|
{ taggedOps.size < 1 ? <h3> No operations defined in spec! </h3> : null }
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
renderOperationTag = (tagObj, tag) => {
|
||||||
|
const {
|
||||||
|
specSelectors,
|
||||||
getComponent,
|
getComponent,
|
||||||
oas3Selectors,
|
oas3Selectors,
|
||||||
layoutSelectors,
|
layoutSelectors,
|
||||||
layoutActions,
|
layoutActions,
|
||||||
getConfigs,
|
getConfigs,
|
||||||
fn
|
|
||||||
} = this.props
|
} = this.props
|
||||||
|
|
||||||
let taggedOps = specSelectors.taggedOperations()
|
|
||||||
|
|
||||||
const OperationContainer = getComponent("OperationContainer", true)
|
const OperationContainer = getComponent("OperationContainer", true)
|
||||||
const OperationTag = getComponent("OperationTag")
|
const OperationTag = getComponent("OperationTag")
|
||||||
|
|
||||||
let {
|
|
||||||
maxDisplayedTags,
|
|
||||||
} = getConfigs()
|
|
||||||
|
|
||||||
let filter = layoutSelectors.currentFilter()
|
|
||||||
|
|
||||||
if (filter) {
|
|
||||||
if (filter !== true && filter !== "true" && filter !== "false") {
|
|
||||||
taggedOps = fn.opsFilter(taggedOps, filter)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (maxDisplayedTags && !isNaN(maxDisplayedTags) && maxDisplayedTags >= 0) {
|
|
||||||
taggedOps = taggedOps.slice(0, maxDisplayedTags)
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
{
|
|
||||||
taggedOps.map( (tagObj, tag) => {
|
|
||||||
const operations = tagObj.get("operations")
|
const operations = tagObj.get("operations")
|
||||||
return (
|
return (
|
||||||
<OperationTag
|
<OperationTag
|
||||||
@@ -73,6 +67,7 @@ export default class Operations extends React.Component {
|
|||||||
getConfigs={getConfigs}
|
getConfigs={getConfigs}
|
||||||
getComponent={getComponent}
|
getComponent={getComponent}
|
||||||
specUrl={specSelectors.url()}>
|
specUrl={specSelectors.url()}>
|
||||||
|
<div className="operation-tag-content">
|
||||||
{
|
{
|
||||||
operations.map(op => {
|
operations.map(op => {
|
||||||
const path = op.get("path")
|
const path = op.get("path")
|
||||||
@@ -92,25 +87,19 @@ export default class Operations extends React.Component {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
return <OperationContainer
|
return (
|
||||||
|
<OperationContainer
|
||||||
key={`${path}-${method}`}
|
key={`${path}-${method}`}
|
||||||
specPath={specPath}
|
specPath={specPath}
|
||||||
op={op}
|
op={op}
|
||||||
path={path}
|
path={path}
|
||||||
method={method}
|
method={method}
|
||||||
tag={tag}
|
tag={tag} />
|
||||||
/>
|
|
||||||
}).toArray()
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
</OperationTag>
|
|
||||||
)
|
)
|
||||||
}).toArray()
|
}).toArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
{ taggedOps.size < 1 ? <h3> No operations defined in spec! </h3> : null }
|
|
||||||
</div>
|
</div>
|
||||||
|
</OperationTag>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import reducers from "./reducers"
|
import reducers from "./reducers"
|
||||||
import * as actions from "./actions"
|
import * as actions from "./actions"
|
||||||
import * as selectors from "./selectors"
|
import * as selectors from "./selectors"
|
||||||
|
import * as wrapSelectors from "./spec-extensions/wrap-selector"
|
||||||
|
|
||||||
export default function() {
|
export default function() {
|
||||||
return {
|
return {
|
||||||
@@ -9,6 +10,9 @@ export default function() {
|
|||||||
reducers,
|
reducers,
|
||||||
actions,
|
actions,
|
||||||
selectors
|
selectors
|
||||||
|
},
|
||||||
|
spec: {
|
||||||
|
wrapSelectors
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
22
src/core/plugins/layout/spec-extensions/wrap-selector.js
Normal file
22
src/core/plugins/layout/spec-extensions/wrap-selector.js
Normal file
@@ -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
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user