Skip to content

Commit

Permalink
fix: allow programRuleAction translations [DHIS2-12971] (#848)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomzemp committed Dec 15, 2023
1 parent a5b4cfa commit cb538dc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/pages/Translations/TranslationCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const TranslationCard = props => {
alignItems="center"
>
<Grid item xs={6}>
<h3>{props.object.name}</h3>
<h3>{props.object[props.cardTitleProperty]}</h3>
</Grid>
<Grid style={translationCardStyles.icon} item xs={6}>
{getState() === TRANSLATED_ID && (
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/pages/Translations/TranslationsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const TranslationsList = props =>
openCard={props.openCard(object.id)}
openCardOnClick={props.openCardOnClick(object.id)}
clearFeedback={props.clearFeedback}
cardTitleProperty={props.cardTitleProperty}
/>
))}
{PaginationBuilder(
Expand All @@ -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,
Expand Down
24 changes: 18 additions & 6 deletions src/pages/Translations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => ({
Expand Down Expand Up @@ -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() : []
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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'
}
/>
<div id="feedback-snackbar">{feedbackElement}</div>
<ConfirmationDialog
Expand Down

0 comments on commit cb538dc

Please sign in to comment.