From b199e02faef538d1e7e18e90e9a8faed9d40a734 Mon Sep 17 00:00:00 2001 From: Ketan <73937490+devketanpro@users.noreply.github.com> Date: Fri, 14 Jun 2024 14:25:19 +0530 Subject: [PATCH] Fix: Display X-axis title in chart for custom vocabulary type fields [SDESK-7268] (#152) * modify get vocabularies method * refactore code * minor chnage --- client/charts/SDChart/Chart.js | 8 +++++- .../ContentPublishingReportController.js | 26 ++++++++++++++----- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/client/charts/SDChart/Chart.js b/client/charts/SDChart/Chart.js index 936ab31de..e12442a00 100644 --- a/client/charts/SDChart/Chart.js +++ b/client/charts/SDChart/Chart.js @@ -2,6 +2,7 @@ import {forEach, get, sum, drop, cloneDeep} from 'lodash'; import {Axis} from './Axis'; import {convertHtmlStringToText} from '../../utils'; +import {getCustomVocabFieldName} from '../../content_publishing_report/controllers/ContentPublishingReportController'; /** * @ngdoc class @@ -795,7 +796,12 @@ export class Chart { * @description Helper function to get the translated title for a field */ getTranslationTitle(field) { - return this.getTranslation(field).title || field; + let _field = field; + + if (_field.startsWith('{"scheme')) { + _field = getCustomVocabFieldName(_field); + } + return this.getTranslation(_field).title || _field; } /** diff --git a/client/content_publishing_report/controllers/ContentPublishingReportController.js b/client/content_publishing_report/controllers/ContentPublishingReportController.js index e48dc8cac..7a832393c 100644 --- a/client/content_publishing_report/controllers/ContentPublishingReportController.js +++ b/client/content_publishing_report/controllers/ContentPublishingReportController.js @@ -355,10 +355,7 @@ export const generateTitle = (chart, params) => { let parentField = _.get(params, 'aggs.group.field'); if (parentField.startsWith('{"scheme')) { - const obj = JSON.parse(parentField); - - parentField = getCustomVocabulariesData().find( - (value) => value.qcode.scheme == obj.scheme)?.name; + parentField = getCustomVocabFieldName(parentField); } const parentName = chart.getSourceName(parentField); @@ -376,8 +373,23 @@ export const generateTitle = (chart, params) => { return gettext('Published Stories per {{group}}', {group: parentName}); }; +export function getCustomVocabFieldName(field) { + const obj = JSON.parse(field); + + return getCustomVocabulariesData().find( + (value) => value.qcode.scheme == obj.scheme + )?.name; +} + export function getCustomVocabulariesData() { - return superdeskApi.entities.vocabulary.getCustomVocabulary().map((data) => { - return {'name': data['display_name'], 'qcode': {'scheme': data['_id']}}; - }); + const superdeskVocab = superdeskApi.entities.vocabulary; + + return superdeskVocab + .getAll() + .toArray() + .filter((vocabulary) => superdeskVocab.isCustomVocabulary(vocabulary)) + .map((data) => ({ + name: data.display_name, + qcode: {scheme: data._id}, + })); }