From 8ced6c4b897f94b6e309737e48d9f0c70e3ad4df Mon Sep 17 00:00:00 2001 From: Thomas Zemp Date: Thu, 14 Dec 2023 14:30:54 +0100 Subject: [PATCH] fix: allow programRuleAction translations [DHIS2-12971] --- 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 c84b0da4..f8dbac1f 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 955bf2e8..8d905be2 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 acd5086a..8f1e28ce 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) => ({ @@ -538,7 +542,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() : [] @@ -653,14 +657,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, @@ -835,6 +842,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}