Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(MgtProfile): Fix handling of null values for educations & work positions #2717

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 36 additions & 11 deletions packages/mgt-components/src/components/mgt-profile/mgt-profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@
* -------------------------------------------------------------------------------------------
*/

import { EducationalActivity, PersonAnnualEvent, PersonInterest, Profile } from '@microsoft/microsoft-graph-types-beta';
import { html, TemplateResult } from 'lit';
import {
EducationalActivity,
PersonAnnualEvent,
PersonInterest,
PhysicalAddress,
Profile
} from '@microsoft/microsoft-graph-types-beta';
import { html, TemplateResult, nothing } from 'lit';
import { BasePersonCardSection } from '../BasePersonCardSection';
import { getSvg, SvgIcon } from '../../utils/SvgHelper';
import { styles } from './mgt-profile-css';
Expand Down Expand Up @@ -306,7 +312,7 @@ export class MgtProfile extends BasePersonCardSection {
${position?.detail?.company?.displayName}
</div>
<div class="work-position__location" tabindex="0">
${position?.detail?.company?.address?.city}, ${position?.detail?.company?.address?.state}
${this.displayLocation(position?.detail?.company?.address)}
</div>
</div>
</div>
Expand Down Expand Up @@ -351,11 +357,14 @@ export class MgtProfile extends BasePersonCardSection {
${this.getDisplayDateRange(educationalActivity)}
</div>
</div>
<div class="data-list__item__content">
<div class="educational-activity__degree" tabindex="0">
${educationalActivity.program.displayName || 'Bachelors Degree'}
</div>
</div>
${
educationalActivity.program.displayName
? html`<div class="data-list__item__content">
<div class="educational-activity__degree" tabindex="0">
${educationalActivity.program.displayName}
</div>`
: nothing
}
</div>
`);
}
Expand Down Expand Up @@ -492,16 +501,32 @@ export class MgtProfile extends BasePersonCardSection {
});
}

private getDisplayDateRange(event: EducationalActivity): string {
private getDisplayDateRange(event: EducationalActivity): string | symbol {
// if startMonthYear is not defined, we do not show the date range (otherwise it will always start with 1970)
if (!event.startMonthYear) {
return nothing;
}

const start = new Date(event.startMonthYear).getFullYear();
if (start === 0) {
return null;
// if the start year is 0 or 1 - it's probably an error or a strange "undefined"-value
if (start === 0 || start === 1) {
return nothing;
}

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

private displayLocation(address: PhysicalAddress | undefined): string | symbol {
if (address?.city) {
if (address.state) {
return `${address.city}, ${address.state}`;
}
return address.city;
}
return nothing;
}

private initPostRenderOperations(): void {
setTimeout(() => {
try {
Expand Down