Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Display X-axis title in chart for custom vocabulary type fields [SDESK-7268] #152

Merged
merged 3 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,21 @@ 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
.getAllVocabulary()
.filter((vocabulary) => superdeskVocab.isCustomVocabulary(vocabulary))
.map((data) => ({
name: data.display_name,
qcode: {scheme: data._id},
}));
}
Loading