Skip to content

Commit

Permalink
Initial work enabling hierarchical tags
Browse files Browse the repository at this point in the history
  • Loading branch information
kael-shipman committed Mar 6, 2021
1 parent 5536916 commit 5aeef74
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
8 changes: 5 additions & 3 deletions src/core/components/operation-tag.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export default class OperationTag extends React.Component {
layoutActions,
getConfigs,
getComponent,
specSelectors,
specUrl,
} = this.props

Expand All @@ -68,6 +69,7 @@ export default class OperationTag extends React.Component {
} = getConfigs()

// Get the necessary components
const OperationContainer = getComponent("OperationContainer", true)
const Collapse = getComponent("Collapse")
const Markdown = getComponent("Markdown", true)
const DeepLink = getComponent("DeepLink")
Expand Down Expand Up @@ -137,7 +139,7 @@ export default class OperationTag extends React.Component {
</h4>

<Collapse isOpened={showTag}>
<div class="hierarchical-operation-tag-operations">
<div className="hierarchical-operation-tag-operations">
{
operations.map(op => {
const path = op.get("path")
Expand Down Expand Up @@ -195,7 +197,7 @@ export default class OperationTag extends React.Component {
<div className="hierarchical-operation-tags" style={isRoot ? null : {margin: "0 0 0 2rem"}}>
{
childTags.map((tag, tagName) => {
return <HierarchicalOperationTag
return <OperationTag
key={"operation-" + (tag.get("canonicalTagName") || tagName)}
tagObj={tag.get("data")}
tag={tagName}
Expand All @@ -208,7 +210,7 @@ export default class OperationTag extends React.Component {
childTags={tag.get("childTags")}
isRoot={false}
/>
})
}).toArray()
}
</div>
)
Expand Down
15 changes: 7 additions & 8 deletions src/core/components/operations.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ export default class Operations extends React.Component {
// flat list, even if the `hierarchicalTags` option is set to `true`.
let taggedOps = specSelectors.taggedOperations()

const OperationContainer = getComponent("OperationContainer", true)
const OperationTag = getComponent("OperationTag")

// Filter, if requested
Expand Down Expand Up @@ -76,7 +75,7 @@ export default class Operations extends React.Component {
// hierarchy

// For each raw tag....
for (const tagName in taggedOps) {
taggedOps.map((tagObj, tagName) => {
// Split the raw tag name into parts
const parts = tagName.split(tagSplitterChar);

Expand Down Expand Up @@ -104,27 +103,27 @@ export default class Operations extends React.Component {

// If this is the last part, set data on this object
if (i === parts.length - 1) {
current[part].data = taggedOps.get(tagName);
current[part].data = tagObj;
}

// Move to the next level of the hierarchy before looping around
current = current[part].childTags;
}
}
});
} else {
// If the `hierarchicalTags` option is not set, we just want to convert our flat tag map into
// the right format
for (const tagName in taggedOps) {
taggedOps.map((tagObj, tagName) => {
operationTagsRaw[tagName] = {
canonicalName: tagName,
data: taggedOps.get(tagName),
data: tagObj,
childTags: {}
}
}
});
}

// Convert to immutable map
const operationTags = Im.fromJs(operationTagsRaw);
const operationTags = Im.fromJS(operationTagsRaw);

// Return the render
return operationTags.size === 0
Expand Down
2 changes: 2 additions & 0 deletions src/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ export default function SwaggerUI(opts) {
showExtensions: false,
showCommonExtensions: false,
withCredentials: undefined,
hierarchicalTags: false,
tagSplitterChar: /[:|]/,
supportedSubmitMethods: [
"get",
"put",
Expand Down

0 comments on commit 5aeef74

Please sign in to comment.