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' }] };