From 61433fabb4bce3fa916b8b91975945126ec5dfcf Mon Sep 17 00:00:00 2001 From: John Cowen Date: Wed, 17 Jun 2020 14:11:40 +0100 Subject: [PATCH] ui: Don't show duplicate services in the intentions form dropdown (#8133) * Add uniq-by helper * Pass unique services through to intentions form * Add acceptance test --- ui-v2/app/helpers/uniq-by.js | 13 +++++++++ ui-v2/app/templates/dc/intentions/edit.hbs | 2 +- .../dc/intentions/filtered-select.feature | 29 +++++++++++++++++-- 3 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 ui-v2/app/helpers/uniq-by.js diff --git a/ui-v2/app/helpers/uniq-by.js b/ui-v2/app/helpers/uniq-by.js new file mode 100644 index 0000000000..c8c46ee027 --- /dev/null +++ b/ui-v2/app/helpers/uniq-by.js @@ -0,0 +1,13 @@ +import { helper } from '@ember/component/helper'; +import { isEmpty } from '@ember/utils'; +import { A as emberArray } from '@ember/array'; + +export function uniqBy([byPath, array]) { + if (isEmpty(byPath)) { + return []; + } + + return emberArray(array).uniqBy(byPath); +} + +export default helper(uniqBy); diff --git a/ui-v2/app/templates/dc/intentions/edit.hbs b/ui-v2/app/templates/dc/intentions/edit.hbs index 12d38a121f..d2f995a205 100644 --- a/ui-v2/app/templates/dc/intentions/edit.hbs +++ b/ui-v2/app/templates/dc/intentions/edit.hbs @@ -39,7 +39,7 @@