From cd61f58b11987e7f44d2ddeacc45ad57816bea4a Mon Sep 17 00:00:00 2001 From: jaredevantabor Date: Tue, 10 Jan 2017 21:12:29 -0800 Subject: [PATCH 1/2] hiding default search param as a search tag in scenario where the user types a search that conflicts w/ the default search params. Ex: searching for kind:gce when kind:ssh is a default search param shouldn't create a search tag for kind:ssh, as someone shouldn't be able to remove that tag...it's a default! --- .../smart-search/smart-search.controller.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/awx/ui/client/src/shared/smart-search/smart-search.controller.js b/awx/ui/client/src/shared/smart-search/smart-search.controller.js index 95f3be3adb..fc9cca9e77 100644 --- a/awx/ui/client/src/shared/smart-search/smart-search.controller.js +++ b/awx/ui/client/src/shared/smart-search/smart-search.controller.js @@ -23,11 +23,24 @@ export default ['$stateParams', '$scope', '$state', 'QuerySet', 'GetBasePath', ' // Removes state definition defaults and pagination terms function stripDefaultParams(params) { - let stripped =_.pick(params, (value, key) => { + let strippedCopy, stripped =_.pick(params, (value, key) => { // setting the default value of a term to null in a state definition is a very explicit way to ensure it will NEVER generate a search tag, even with a non-default value return defaults[key] !== value && key !== 'order_by' && key !== 'page' && key !== 'page_size' && defaults[key] !== null; }); - return _(stripped).map(qs.decodeParam).flatten().value(); + strippedCopy = _.cloneDeep(stripped); + if(_.keys(_.pick(defaults, _.keys(strippedCopy))).length > 0){ + for (var key in strippedCopy) { + if (strippedCopy.hasOwnProperty(key)) { + let value = strippedCopy[key]; + if(_.isArray(value)){ + let index = _.indexOf(value, defaults[key]); + value = value.splice(index, 1)[0]; + } + } + } + stripped = strippedCopy; + } + return _(strippedCopy).map(qs.decodeParam).flatten().value(); } // searchable relationships From 82f16f0551ad70461d12c2f18fbef05bd4ee7747 Mon Sep 17 00:00:00 2001 From: jaredevantabor Date: Wed, 11 Jan 2017 14:25:08 -0800 Subject: [PATCH 2/2] small change based on PR feedback --- .../client/src/shared/smart-search/smart-search.controller.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/awx/ui/client/src/shared/smart-search/smart-search.controller.js b/awx/ui/client/src/shared/smart-search/smart-search.controller.js index fc9cca9e77..580a56c6f3 100644 --- a/awx/ui/client/src/shared/smart-search/smart-search.controller.js +++ b/awx/ui/client/src/shared/smart-search/smart-search.controller.js @@ -23,11 +23,11 @@ export default ['$stateParams', '$scope', '$state', 'QuerySet', 'GetBasePath', ' // Removes state definition defaults and pagination terms function stripDefaultParams(params) { - let strippedCopy, stripped =_.pick(params, (value, key) => { + let stripped =_.pick(params, (value, key) => { // setting the default value of a term to null in a state definition is a very explicit way to ensure it will NEVER generate a search tag, even with a non-default value return defaults[key] !== value && key !== 'order_by' && key !== 'page' && key !== 'page_size' && defaults[key] !== null; }); - strippedCopy = _.cloneDeep(stripped); + let strippedCopy = _.cloneDeep(stripped); if(_.keys(_.pick(defaults, _.keys(strippedCopy))).length > 0){ for (var key in strippedCopy) { if (strippedCopy.hasOwnProperty(key)) {