diff --git a/src/core/components/operations.jsx b/src/core/components/operations.jsx index 660542e56e3..6bc4030e101 100644 --- a/src/core/components/operations.jsx +++ b/src/core/components/operations.jsx @@ -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() { @@ -30,7 +31,8 @@ export default class Operations extends React.Component { getComponent, layoutSelectors, layoutActions, - getConfigs + getConfigs, + fn } = this.props let taggedOps = specSelectors.taggedOperations() @@ -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) } } diff --git a/src/core/plugins/filter/index.js b/src/core/plugins/filter/index.js new file mode 100644 index 00000000000..e7f37c92b83 --- /dev/null +++ b/src/core/plugins/filter/index.js @@ -0,0 +1,9 @@ +import opsFilter from "./opsFilter" + +export default function() { + return { + fn: { + opsFilter + } + } +} diff --git a/src/core/plugins/filter/opsFilter.js b/src/core/plugins/filter/opsFilter.js new file mode 100644 index 00000000000..fecf262f40d --- /dev/null +++ b/src/core/plugins/filter/opsFilter.js @@ -0,0 +1,3 @@ +export default function(taggedOps, phrase) { + return taggedOps.filter((tagObj, tag) => tag.indexOf(phrase) !== -1) +} diff --git a/src/core/presets/base.js b/src/core/presets/base.js index 65bf891e8f2..de5a34da750 100644 --- a/src/core/presets/base.js +++ b/src/core/presets/base.js @@ -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" @@ -152,6 +153,7 @@ export default function() { ast, SplitPaneModePlugin, downloadUrlPlugin, - deepLinkingPlugin + deepLinkingPlugin, + filter ] } diff --git a/test/core/plugins/filter/opsFilter.js b/test/core/plugins/filter/opsFilter.js new file mode 100644 index 00000000000..ef15468c367 --- /dev/null +++ b/test/core/plugins/filter/opsFilter.js @@ -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) + }) +}) diff --git a/test/core/system/system.js b/test/core/system/system.js index 24bfbf8ad48..69e184885af 100644 --- a/test/core/system/system.js +++ b/test/core/system/system.js @@ -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(){ @@ -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(){