From 2a1662c78163e94a2f2b8b07dbb79825928a3722 Mon Sep 17 00:00:00 2001 From: Sivin Varghese <64252451+iamsivin@users.noreply.github.com> Date: Fri, 4 Aug 2023 13:54:21 +0530 Subject: [PATCH] fix: Edit custom views folder (#7670) --- .../dashboard/helper/customViewsHelper.js | 6 +++++ .../helper/specs/customViewsHelper.spec.js | 27 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/app/javascript/dashboard/helper/customViewsHelper.js b/app/javascript/dashboard/helper/customViewsHelper.js index 5e8b550ab..be3ee2c38 100644 --- a/app/javascript/dashboard/helper/customViewsHelper.js +++ b/app/javascript/dashboard/helper/customViewsHelper.js @@ -36,6 +36,10 @@ export const getValuesName = (values, list, idKey, nameKey) => { }; }; +export const getValuesForStatus = values => { + return values.map(value => ({ id: value, name: value })); +}; + const getValuesForLabels = (values, labels) => { const selectedLabels = labels.filter(label => values.includes(label.title)); return selectedLabels.map(({ title }) => ({ @@ -76,6 +80,8 @@ export const getValuesForFilter = (filter, params) => { labels, } = params; switch (attribute_key) { + case 'status': + return getValuesForStatus(values); case 'assignee_id': return getValuesName(values, agents, 'id', 'name'); case 'inbox_id': diff --git a/app/javascript/dashboard/helper/specs/customViewsHelper.spec.js b/app/javascript/dashboard/helper/specs/customViewsHelper.spec.js index 473f0bf01..0709c4e8d 100644 --- a/app/javascript/dashboard/helper/specs/customViewsHelper.spec.js +++ b/app/javascript/dashboard/helper/specs/customViewsHelper.spec.js @@ -2,6 +2,7 @@ import { getAttributeInputType, getInputType, getValuesName, + getValuesForStatus, getValuesForFilter, generateValuesForEditCustomViews, generateCustomAttributesInputType, @@ -106,7 +107,33 @@ describe('customViewsHelper', () => { }); }); + describe('#getValuesForStatus', () => { + it('should return id and name if value is present', () => { + const values = ['open']; + expect(getValuesForStatus(values)).toEqual([ + { id: 'open', name: 'open' }, + ]); + }); + + it('should return id and name if multiple values are present', () => { + const values = ['open', 'resolved']; + expect(getValuesForStatus(values)).toEqual([ + { id: 'open', name: 'open' }, + { id: 'resolved', name: 'resolved' }, + ]); + }); + }); + describe('#getValuesForFilter', () => { + it('should return id and name if attribute_key is status', () => { + const filter = { attribute_key: 'status', values: ['open', 'resolved'] }; + const params = {}; + expect(getValuesForFilter(filter, params)).toEqual([ + { id: 'open', name: 'open' }, + { id: 'resolved', name: 'resolved' }, + ]); + }); + it('should return id and name if attribute_key is assignee_id', () => { const filter = { attribute_key: 'assignee_id', values: [1] }; const params = { agents: [{ id: 1, name: 'test' }] };