From cb538dcb368356af6d445b50843967ceb75031bb Mon Sep 17 00:00:00 2001 From: Thomas Zemp Date: Fri, 15 Dec 2023 10:12:04 +0100 Subject: [PATCH] fix: allow programRuleAction translations [DHIS2-12971] (#848) --- src/pages/Translations/TranslationCard.js | 3 ++- src/pages/Translations/TranslationsList.js | 2 ++ src/pages/Translations/index.js | 24 ++++++++++++++++------ 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/pages/Translations/TranslationCard.js b/src/pages/Translations/TranslationCard.js index 129889cb..57e00a8a 100644 --- a/src/pages/Translations/TranslationCard.js +++ b/src/pages/Translations/TranslationCard.js @@ -69,7 +69,7 @@ const TranslationCard = props => { alignItems="center" > -

{props.object.name}

+

{props.object[props.cardTitleProperty]}

{getState() === TRANSLATED_ID && ( @@ -145,6 +145,7 @@ const TranslationCard = props => { } TranslationCard.propTypes = { + cardTitleProperty: PropTypes.string.isRequired, clearFeedback: PropTypes.func.isRequired, hasUnsavedChanges: PropTypes.func.isRequired, localeId: PropTypes.string.isRequired, diff --git a/src/pages/Translations/TranslationsList.js b/src/pages/Translations/TranslationsList.js index 1adb80ce..adffec57 100644 --- a/src/pages/Translations/TranslationsList.js +++ b/src/pages/Translations/TranslationsList.js @@ -54,6 +54,7 @@ const TranslationsList = props => openCard={props.openCard(object.id)} openCardOnClick={props.openCardOnClick(object.id)} clearFeedback={props.clearFeedback} + cardTitleProperty={props.cardTitleProperty} /> ))} {PaginationBuilder( @@ -67,6 +68,7 @@ const TranslationsList = props => ) TranslationsList.propTypes = { + cardTitleProperty: PropTypes.string.isRequired, clearFeedback: PropTypes.func.isRequired, goToNextPage: PropTypes.func.isRequired, goToPreviousPage: PropTypes.func.isRequired, diff --git a/src/pages/Translations/index.js b/src/pages/Translations/index.js index 96895d68..38f9337c 100644 --- a/src/pages/Translations/index.js +++ b/src/pages/Translations/index.js @@ -19,6 +19,10 @@ const DEFAULT_SNACKBAR_CONF = { onActionClick: null, } +const OVERRIDE_TITLE_AND_SEARCH_PROPS = { + programRuleAction: 'content', +} + /* auxiliar methods */ /* FIXME move to an external file, SchemaEntry class */ const modelToSchemaEntry = model => ({ @@ -532,7 +536,7 @@ class TranslationsPage extends PureComponent { model .list({ paging: false, - fields: 'id,displayName,name,translations', + fields: 'id,displayName,name,content,translations', }) .then(objects => { const objectInstances = objects ? objects.toArray() : [] @@ -647,14 +651,17 @@ class TranslationsPage extends PureComponent { .trim() .toLowerCase() const newElements = [] - for (let i = 0; i < elements.length; i++) { const element = elements[i] if ( - element.name - .trim() - .toLowerCase() - .includes(currentSearchTerm) + element[ + OVERRIDE_TITLE_AND_SEARCH_PROPS[ + searchFilter.selectedObject?.id + ] ?? 'name' + ] + ?.trim() + ?.toLowerCase() + ?.includes(currentSearchTerm) ) { const flatElement = flatElementForPropertiesAndLocale( element, @@ -826,6 +833,11 @@ class TranslationsPage extends PureComponent { openCardOnClick={this.openCardOnClick} hasUnsavedChanges={this.hasUnsavedChanges} clearFeedback={this.clearFeedbackSnackbar} + cardTitleProperty={ + OVERRIDE_TITLE_AND_SEARCH_PROPS[ + this.state?.searchFilter?.selectedObject?.id + ] ?? 'name' + } />
{feedbackElement}