@@ -97,6 +97,8 @@ export function convertArabicToRoman(num) {
97
97
/**
98
98
* Render name template based on config.
99
99
* Use substitution map to replace a config value with a more readable variant.
100
+ * NOTE: We currently iterate through the whole object. A more efficient albeit more verbose approach would be
101
+ * to give the property path in the subsitution map, e.g., `{ "user.name": {"user001": "John Doe"} }`.
100
102
* @param {string|undefined } template - Template for the name property
101
103
* @param {Object } data - Entity config
102
104
* @param {Object } substitutionMap - Maps object value to human-readable string
@@ -115,13 +117,19 @@ export function renderTextWithSubstitutes(template, data, substitutionMap = {})
115
117
116
118
// Helper function for recursive substitution
117
119
function substituteNested ( obj ) {
118
- lodash . forIn ( obj , ( value , key ) => {
120
+ if ( ! lodash . isPlainObject ( obj ) ) {
121
+ return ;
122
+ }
123
+ // eslint-disable-next-line no-restricted-syntax
124
+ for ( const [ key , value ] of Object . entries ( obj ) ) {
119
125
if ( lodash . isPlainObject ( value ) ) {
120
126
substituteNested ( value ) ;
127
+ } else if ( Array . isArray ( value ) ) {
128
+ value . forEach ( ( val ) => substituteNested ( val ) ) ;
121
129
} else if ( substitutionMap [ value ] ) {
122
130
obj [ key ] = substitutionMap [ value ] ;
123
131
}
124
- } ) ;
132
+ }
125
133
}
126
134
127
135
substituteNested ( renderData ) ;
0 commit comments