diff options
author | Phil Hughes <me@iamphill.com> | 2017-03-15 13:52:49 +0300 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2017-03-16 11:42:41 +0300 |
commit | fbf1cc6aab74cff9a425e8b2118f19141bb516a5 (patch) | |
tree | 63e173c7c75b2c7193134eeb3e30328acf6a3822 /app/assets/javascripts/boards/utils | |
parent | 4e5bf7d6ddc4cbeda2a09c2cc77b1ddabff6756e (diff) |
Moved reduce function to a util
Fixed issue with modal window including main search bars tokens
Diffstat (limited to 'app/assets/javascripts/boards/utils')
-rw-r--r-- | app/assets/javascripts/boards/utils/query_data.js | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/app/assets/javascripts/boards/utils/query_data.js b/app/assets/javascripts/boards/utils/query_data.js new file mode 100644 index 00000000000..94cb5fbff42 --- /dev/null +++ b/app/assets/javascripts/boards/utils/query_data.js @@ -0,0 +1,22 @@ +export default (path, extraData) => { + return path.split('&').reduce((data, filterParam) => { + if (filterParam === '') return data; + + const paramSplit = filterParam.split('='); + const paramKeyNormalized = paramSplit[0].replace('[]', ''); + const isArray = paramSplit[0].indexOf('[]'); + const value = decodeURIComponent(paramSplit[1]).replace(/\+/g, ' '); + + if (isArray !== -1) { + if (!data[paramKeyNormalized]) { + data[paramKeyNormalized] = []; + } + + data[paramKeyNormalized].push(value); + } else { + data[paramKeyNormalized] = value; + } + + return data; + }, extraData); +} |