Skip to content

Commit 7225875

Browse files
authored
Merge pull request #15 from bci-oss/bug/#14
Fix tooltip text evaluation for enum properties
2 parents d288bc8 + 9802f80 commit 7225875

File tree

2 files changed

+36
-48
lines changed

2 files changed

+36
-48
lines changed

src/ng-generate/table/generators/html.generator.ts

Lines changed: 30 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -307,75 +307,60 @@ export class HtmlGenerator {
307307
}
308308

309309
private getColumnTemplate(property: Property, index: number, complexPrefix: string): string {
310-
const languageLabel = this.options.templateHelper.isMultiStringProperty(property) ? '[currentLanguage]' : '';
311-
return `<!-- ${complexPrefix}${property.name} Column -->
310+
const language = this.options.templateHelper.isMultiStringProperty(property) ? '[currentLanguage]' : '';
311+
const propertyName = this.templateHelper.isEnumPropertyWithEntityValues(property)
312+
? property.name + '?.' + this.templateHelper.getEnumEntityInstancePayloadKey(property)
313+
: property.name
314+
const cellPropertyPath = `${this.options.jsonAccessPath}${complexPrefix}${propertyName}`;
315+
const isEmptyValue = `row.${cellPropertyPath} === null || row.${cellPropertyPath} === undefined`;
316+
const propertyLocaleKeyPath = `${this.versionedAccessPrefix}${this.templateHelper.isAspectSelected(this.options) ? this.options.jsonAccessPath : ''}${complexPrefix}${property.name}`;
317+
318+
const datePipe = this.options.templateHelper.isDateTimeProperty(property) ? `| date: ${this.resolveDateTimeFormat(property)}` : '';
319+
const descriptionPipe = this.templateHelper.isEnumPropertyWithEntityValues(property) ? ` | showDescription:get${classify(property.name)}Value` : '';
320+
const cellContent = `!(${isEmptyValue}) ? (row.${cellPropertyPath}${descriptionPipe}${language}${datePipe}) : '-'`;
321+
322+
return ` <!-- ${complexPrefix}${property.name} Column -->
312323
<ng-container data-test="table-column" matColumnDef="${this.options.jsonAccessPath}${complexPrefix}${property.name}">
313324
<th data-test="table-header" mat-header-cell *matHeaderCellDef
314-
mat-sort-header="${this.options.jsonAccessPath}${complexPrefix}${
315-
this.templateHelper.isEnumPropertyWithEntityValues(property)
316-
? property.name + '.' + this.templateHelper.getEnumEntityInstancePayloadKey(property)
317-
: property.name
318-
}"
325+
mat-sort-header="${cellPropertyPath}"
319326
${this.templateHelper.isNumberProperty(property) ? `class="table-header-number"` : ''}
320327
${
321328
this.allProps.length - 1 > index
322329
? `[resizeColumn]="true" [index]="${index}" (dragging)='dragging = $event'`
323330
: ''
324331
}>
325-
<span [matTooltip]="'${this.versionedAccessPrefix}${
326-
this.templateHelper.isAspectSelected(this.options) ? this.options.jsonAccessPath : ''
327-
}${complexPrefix}${property.name}.description' | translate"
332+
<span [matTooltip]="'${propertyLocaleKeyPath}.description' | translate"
328333
[matTooltipDisabled]="headerTooltipsOff"
329334
matTooltipPosition="above"
330335
data-test="table-header-text">
331-
{{ '${this.versionedAccessPrefix}${
332-
this.templateHelper.isAspectSelected(this.options) ? this.options.jsonAccessPath : ''
333-
}${complexPrefix}${property.name}.preferredName' | translate }}
336+
{{ '${propertyLocaleKeyPath}.preferredName' | translate }}
334337
</span>
335338
</th>
336339
337340
<td data-test="table-cell" ${
338341
this.templateHelper.isEnumPropertyWithEntityValues(property)
339-
? `[matTooltip]="row.${this.options.jsonAccessPath}${complexPrefix}${
340-
property.name +
341-
'?.' +
342-
this.templateHelper.getEnumEntityInstancePayloadKey(property) +
343-
' | showDescription:get' +
344-
classify(property.name) +
345-
'Value' +
346-
':true'
347-
}${languageLabel}"`
348-
: ''
349-
} ${
350-
this.templateHelper.isEnumPropertyWithEntityValues(property)
351-
? `[matTooltipDisabled]="row.${this.options.jsonAccessPath}${complexPrefix}${
352-
this.templateHelper.isEnumPropertyWithEntityValues(property)
353-
? property.name + '?.' + this.templateHelper.getEnumEntityInstancePayloadKey(property)
354-
: property.name
355-
} === null "`
356-
: ''
357-
} mat-cell *matCellDef="let row" ${this.templateHelper.isNumberProperty(property) ? `class="table-cell-number"` : ''}>
342+
?
343+
`
344+
[matTooltip]="!(${isEmptyValue}) ? (row.${cellPropertyPath}${descriptionPipe}:true${language}) : ''"
345+
[matTooltipDisabled]="${isEmptyValue}"
346+
`
347+
: ''}
348+
mat-cell *matCellDef="let row" ${this.templateHelper.isNumberProperty(property) ? `class="table-cell-number"` : ''}>
358349
${this.hasSearchBar ? `
359350
<ng-container
360-
[ngTemplateOutlet]="(highlightConfig?.selected && ((${this.resolveTableValue(property, index, complexPrefix, languageLabel)}) | searchString: highlightString)) ? searchedWordExists : normal"
361-
[ngTemplateOutletContext]="{ value: (${this.resolveTableValue(property, index, complexPrefix, languageLabel)}) }"></ng-container>` : `{{${this.resolveTableValue(property, index, complexPrefix, languageLabel)}}}`}
351+
[ngTemplateOutlet]="highlightConfig?.selected && ((${cellContent}) | searchString: highlightString) ? searchedWordExists : normal"
352+
[ngTemplateOutletContext]="{ value: ${cellContent} }"></ng-container>` : `{{${cellContent}}}`}
362353
363-
<button data-test="copy-to-clipboard-button" mat-icon-button class="copy-to-clipboard" (click)="copyToClipboard(row.${this.options.jsonAccessPath}${complexPrefix}${
364-
this.templateHelper.isEnumPropertyWithEntityValues(property)
365-
? property.name + '?.' + this.templateHelper.getEnumEntityInstancePayloadKey(property)
366-
: property.name}, $event)">
367-
<mat-icon data-test="copy-to-clipboard-icon" class="material-icons">content_copy</mat-icon>
354+
<button data-test="copy-to-clipboard-button"
355+
*ngIf="!(${isEmptyValue})"
356+
mat-icon-button class="copy-to-clipboard"
357+
(click)="copyToClipboard(row.${cellPropertyPath}${language}, $event)">
358+
<mat-icon data-test="copy-to-clipboard-icon" class="material-icons">content_copy</mat-icon>
368359
</button>
369360
</td>
370361
</ng-container>`;
371362
}
372363

373-
private resolveTableValue(property: Property, index: number, complexPrefix: string, languageLabel: string): string {
374-
return `row.${this.options.jsonAccessPath}${complexPrefix}${
375-
this.templateHelper.isEnumPropertyWithEntityValues(property) ? property.name + '?.' + this.templateHelper.getEnumEntityInstancePayloadKey(property) : property.name} === null? '-': row.${this.options.jsonAccessPath}${complexPrefix}${
376-
this.templateHelper.isEnumPropertyWithEntityValues(property) ? property.name + '?.' + this.templateHelper.getEnumEntityInstancePayloadKey(property) + ' | showDescription:get' + classify(property.name) + 'Value' : property.name}${languageLabel}${this.options.templateHelper.isDateTimeProperty(property) ? `| date: ${this.resolveDateTimeFormat(property)}` : ''}`
377-
}
378-
379364
private resolveDateTimeFormat(property: Property): string {
380365
if (this.options.templateHelper.isTimeProperty(property)) {
381366
return 'tableTimeFormat';

src/ng-generate/table/generators/ts-pipe.generator.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@ export class TsPipeGenerator {
2222
@Pipe({name: 'showDescription'})
2323
export class ShowDescriptionPipe implements PipeTransform {
2424
transform(value: any, getByValueFn: any, onlyDesc?: boolean): any {
25-
return onlyDesc
26-
? \`\${getByValueFn(value.toString())?.description}\` || ''
27-
: \`\${value} - \${getByValueFn(value.toString())?.description}\` || '';
25+
value = value?.toString();
26+
27+
const resultParts: string[] = value && !onlyDesc ? [value] : [];
28+
resultParts.push(getByValueFn(value)?.description);
29+
30+
return resultParts.join(' - ');
2831
}
2932
}
3033
`;

0 commit comments

Comments
 (0)