Skip to content

Commit ba381c8

Browse files
chaellimichaelkellerviugavinbarron
authored
fix(MgtProfile): Fix handling of null values for educations & work positions (#2717)
improved nullish value handling for education and work, only render when data is present --------- Co-authored-by: Michael Keller <[email protected]> Co-authored-by: Gavin Barron <[email protected]>
1 parent ab7f18e commit ba381c8

File tree

1 file changed

+36
-11
lines changed

1 file changed

+36
-11
lines changed

packages/mgt-components/src/components/mgt-profile/mgt-profile.ts

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@
55
* -------------------------------------------------------------------------------------------
66
*/
77

8-
import { EducationalActivity, PersonAnnualEvent, PersonInterest, Profile } from '@microsoft/microsoft-graph-types-beta';
9-
import { html, TemplateResult } from 'lit';
8+
import {
9+
EducationalActivity,
10+
PersonAnnualEvent,
11+
PersonInterest,
12+
PhysicalAddress,
13+
Profile
14+
} from '@microsoft/microsoft-graph-types-beta';
15+
import { html, TemplateResult, nothing } from 'lit';
1016
import { BasePersonCardSection } from '../BasePersonCardSection';
1117
import { getSvg, SvgIcon } from '../../utils/SvgHelper';
1218
import { styles } from './mgt-profile-css';
@@ -306,7 +312,7 @@ export class MgtProfile extends BasePersonCardSection {
306312
${position?.detail?.company?.displayName}
307313
</div>
308314
<div class="work-position__location" tabindex="0">
309-
${position?.detail?.company?.address?.city}, ${position?.detail?.company?.address?.state}
315+
${this.displayLocation(position?.detail?.company?.address)}
310316
</div>
311317
</div>
312318
</div>
@@ -351,11 +357,14 @@ export class MgtProfile extends BasePersonCardSection {
351357
${this.getDisplayDateRange(educationalActivity)}
352358
</div>
353359
</div>
354-
<div class="data-list__item__content">
355-
<div class="educational-activity__degree" tabindex="0">
356-
${educationalActivity.program.displayName || 'Bachelors Degree'}
357-
</div>
358-
</div>
360+
${
361+
educationalActivity.program.displayName
362+
? html`<div class="data-list__item__content">
363+
<div class="educational-activity__degree" tabindex="0">
364+
${educationalActivity.program.displayName}
365+
</div>`
366+
: nothing
367+
}
359368
</div>
360369
`);
361370
}
@@ -492,16 +501,32 @@ export class MgtProfile extends BasePersonCardSection {
492501
});
493502
}
494503

495-
private getDisplayDateRange(event: EducationalActivity): string {
504+
private getDisplayDateRange(event: EducationalActivity): string | symbol {
505+
// if startMonthYear is not defined, we do not show the date range (otherwise it will always start with 1970)
506+
if (!event.startMonthYear) {
507+
return nothing;
508+
}
509+
496510
const start = new Date(event.startMonthYear).getFullYear();
497-
if (start === 0) {
498-
return null;
511+
// if the start year is 0 or 1 - it's probably an error or a strange "undefined"-value
512+
if (start === 0 || start === 1) {
513+
return nothing;
499514
}
500515

501516
const end = event.endMonthYear ? new Date(event.endMonthYear).getFullYear() : this.strings.currentYearSubtitle;
502517
return `${start}${end}`;
503518
}
504519

520+
private displayLocation(address: PhysicalAddress | undefined): string | symbol {
521+
if (address?.city) {
522+
if (address.state) {
523+
return `${address.city}, ${address.state}`;
524+
}
525+
return address.city;
526+
}
527+
return nothing;
528+
}
529+
505530
private initPostRenderOperations(): void {
506531
setTimeout(() => {
507532
try {

0 commit comments

Comments
 (0)