Skip to content

Commit

Permalink
Fix: Display X-axis title in chart for custom vocabulary type fields…
Browse files Browse the repository at this point in the history
… [SDESK-7268] (superdesk#152)

* modify get vocabularies method

* refactore code

* minor chnage
  • Loading branch information
devketanpro authored Jun 14, 2024
1 parent 23bbcf1 commit b199e02
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
8 changes: 7 additions & 1 deletion client/charts/SDChart/Chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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},
}));
}

0 comments on commit b199e02

Please sign in to comment.