Skip to content
Merged
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
10 changes: 5 additions & 5 deletions src/core/components/operations.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ export default class Operations extends React.Component {
layoutActions: PropTypes.object.isRequired,
authActions: PropTypes.object.isRequired,
authSelectors: PropTypes.object.isRequired,
getConfigs: PropTypes.func.isRequired
getConfigs: PropTypes.func.isRequired,
fn: PropTypes.func.isRequired
};

render() {
Expand All @@ -30,7 +31,8 @@ export default class Operations extends React.Component {
getComponent,
layoutSelectors,
layoutActions,
getConfigs
getConfigs,
fn
} = this.props

let taggedOps = specSelectors.taggedOperations()
Expand All @@ -52,9 +54,7 @@ export default class Operations extends React.Component {

if (filter) {
if (filter !== true) {
taggedOps = taggedOps.filter((tagObj, tag) => {
return tag.indexOf(filter) !== -1
})
taggedOps = fn.opsFilter(taggedOps, filter)
}
}

Expand Down
9 changes: 9 additions & 0 deletions src/core/plugins/filter/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import opsFilter from "./opsFilter"

export default function() {
return {
fn: {
opsFilter
}
}
}
3 changes: 3 additions & 0 deletions src/core/plugins/filter/opsFilter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function(taggedOps, phrase) {
return taggedOps.filter((tagObj, tag) => tag.indexOf(phrase) !== -1)
}
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 SplitPaneModePlugin from "core/plugins/split-pane-mode"
import downloadUrlPlugin from "core/plugins/download-url"
import configsPlugin from "core/plugins/configs"
import deepLinkingPlugin from "core/plugins/deep-linking"
import filter from "core/plugins/filter"

import OperationContainer from "core/containers/OperationContainer"

Expand Down Expand Up @@ -152,6 +153,7 @@ export default function() {
ast,
SplitPaneModePlugin,
downloadUrlPlugin,
deepLinkingPlugin
deepLinkingPlugin,
filter
]
}
25 changes: 25 additions & 0 deletions test/core/plugins/filter/opsFilter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Map } from "immutable"
import opsFilter from "corePlugins/filter/opsFilter"
import expect from "expect"

describe("opsFilter", function() {
const taggedOps = Map([["pet"], ["store"], ["user"]])

it("should filter taggedOps by tag name", function () {
const filtered = opsFilter(taggedOps, "sto")

expect(filtered.size).toEqual(1)
})

it("should return all taggedOps when search phrase is empty", function () {
const filtered = opsFilter(taggedOps, "")

expect(filtered.size).toEqual(taggedOps.size)
})

it("should return empty result when there is no match", function () {
const filtered = opsFilter(taggedOps, "NoMatch")

expect(filtered.size).toEqual(0)
})
})
17 changes: 17 additions & 0 deletions test/core/system/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import System from "core/system"
import { fromJS } from "immutable"
import { render } from "enzyme"
import ViewPlugin from "core/plugins/view/index.js"
import filterPlugin from "core/plugins/filter/index.js"
import { connect, Provider } from "react-redux"

describe("bound system", function(){
Expand Down Expand Up @@ -264,6 +265,22 @@ describe("bound system", function(){

})

describe("fn", function() {

it("should return helper functions", function () {
// Given
const system = new System({
plugins: [
filterPlugin
]
})

// When
const fn = system.getSystem().fn.opsFilter
expect(typeof fn).toEqual("function")
})
})

describe("selectors", function(){

it("should have the first arg be the nested state, and all other args to follow", function(){
Expand Down