Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mathis' Contributions #2

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 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,
hierarchicalTagsEnabled: true, // TODO: switch to false
hierarchicalTagDelimiter: "|",
supportedSubmitMethods: [
"get",
"put",
Expand Down Expand Up @@ -107,6 +109,10 @@ export default function SwaggerUI(opts) {
spec: {
spec: "",
url: constructorConfig.url
},
hierarchicalTags: {
enabled: constructorConfig.hierarchicalTagsEnabled,
delimiter: constructorConfig.hierarchicalTagDelimiter
}
}, constructorConfig.initialState)
}
Expand Down
11 changes: 11 additions & 0 deletions src/core/plugins/hierarchical-tags/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import spec from "./spec-extension"
import * as selectors from "./selectors"

export default () => ({
statePlugins: {
hierarchicalTags: {
selectors
},
spec
}
})
14 changes: 14 additions & 0 deletions src/core/plugins/hierarchical-tags/selectors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { createSelector } from "reselect"
import { Map } from "immutable"

const state = state => state || Map()

export const isEnabled = createSelector(
state,
state => state.get("enabled", false)
)

export const getTagDelimiter = createSelector(
state,
state => state.get( "delimiter", "|")
)
6 changes: 6 additions & 0 deletions src/core/plugins/hierarchical-tags/spec-extension/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import * as selectors from "./selectors"
import * as wrapSelectors from "./wrap-selectors"
export default {
selectors,
wrapSelectors
}
62 changes: 62 additions & 0 deletions src/core/plugins/hierarchical-tags/spec-extension/selectors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { taggedOperations } from "../../spec/selectors"
import { OrderedMap } from "immutable"

export const hierarchicalTaggedOperations = (state) => (system) => {
const {
hierarchicalTagsSelectors,
layoutSelectors,
fn
} = system = system.getSystem()
const delimiter = hierarchicalTagsSelectors.getTagDelimiter()
const filter = layoutSelectors.currentFilter()

let taggedOperationsMap = taggedOperations(state)(system)

if (filter) {
if (filter !== true && filter !== "true" && filter !== "false") {
taggedOperationsMap = fn.opsFilter(taggedOperationsMap, filter)
}
}

let hierarchicalTaggedOperations = OrderedMap()

const addTagIn = (nestedTagPath, targetValue) => {
targetValue = targetValue.set("tags", OrderedMap())
const visitedTags = []
let currentTag = nestedTagPath.shift()
while(currentTag !== undefined) {
const isTargetTag = nestedTagPath.length === 0
const isRootTag = visitedTags.length === 0
const isNewRootTag = isRootTag && !hierarchicalTaggedOperations.has(currentTag)

const newTagValue = isTargetTag ? targetValue : OrderedMap({tags: OrderedMap()})

if(isNewRootTag) {
hierarchicalTaggedOperations = hierarchicalTaggedOperations.set(
currentTag,
newTagValue
)
visitedTags.push(currentTag)
currentTag = nestedTagPath.shift()
continue
}

const hierarchicalUpdatePath = visitedTags
.reduce((acc, x) => acc.concat([x, "tags"]), [])
hierarchicalUpdatePath.push(currentTag)

hierarchicalTaggedOperations = hierarchicalTaggedOperations.mergeDeepIn(
hierarchicalUpdatePath,
newTagValue
)

visitedTags.push(currentTag)
currentTag = nestedTagPath.shift()
}
}

taggedOperationsMap.forEach((v, k) => {
addTagIn(k.split(delimiter), v)
})
return hierarchicalTaggedOperations
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const taggedOperations = (oriSelector, system) => (...args) => {
const { hierarchicalTagsSelectors, specSelectors } = system.getSystem()
if(!hierarchicalTagsSelectors.isEnabled()) {
return oriSelector(...args)
}

return specSelectors.hierarchicalTaggedOperations()
}
4 changes: 3 additions & 1 deletion src/core/presets/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import configsPlugin from "core/plugins/configs"
import deepLinkingPlugin from "core/plugins/deep-linking"
import filter from "core/plugins/filter"
import onComplete from "core/plugins/on-complete"
import hierarchicalTags from "core/plugins/hierarchical-tags"

import OperationContainer from "core/containers/OperationContainer"

Expand Down Expand Up @@ -191,6 +192,7 @@ export default function() {
downloadUrlPlugin,
deepLinkingPlugin,
filter,
onComplete
onComplete,
hierarchicalTags
]
}