Skip to content

Commit f4aed2d

Browse files
authored
Merge pull request #563 from keymanapp/fix/faces-are-not-working
fix: calculate user order for contributions at data load
2 parents 6c4a7d1 + 46a1588 commit f4aed2d

File tree

3 files changed

+34
-30
lines changed

3 files changed

+34
-30
lines changed

public/src/app/data/data.model.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { platforms, PlatformSpec } from "../../../../shared/platforms";
22
import { ServiceStateCache, ServiceState, ServiceIdentifier } from "../../../../shared/services";
3+
import { getTz } from "../../../../shared/users";
34
import { sites, siteSentryNames, sitesWithState } from "../sites";
45
import { EMPTY_STATUS, Status } from "../status/status.interface";
56
import { pullEmoji } from "../utility/pullEmoji";
@@ -30,6 +31,7 @@ export class DataModel {
3031

3132
sprintDays = [];
3233

34+
contributionUsers = [];
3335

3436
// Phase data, grabbing from github's milestones for the keyman repo
3537
milestones = {};
@@ -98,6 +100,7 @@ export class DataModel {
98100
break;
99101
case ServiceIdentifier.GitHubContributions:
100102
this.status.contributions = data.contributions;
103+
this.transformContributionUsers();
101104
break;
102105
case ServiceIdentifier.CommunitySite:
103106
this.status.communitySite = this.transformCommunitySiteData(data.communitySite.contributions);
@@ -142,6 +145,34 @@ export class DataModel {
142145
}
143146
}
144147

148+
nullUser = { login:'', avatarUrl: null, contributions: {
149+
issues: { nodes: [] },
150+
pullRequests: { nodes: [] },
151+
reviews: { nodes: [] },
152+
tests: { nodes: [] },
153+
} };
154+
155+
private getTimezoneOffset(timeZone){
156+
if(!timeZone) return undefined;
157+
const str = new Date().toLocaleString('en', {timeZone, timeZoneName: 'longOffset'});
158+
const [_,h,m] = (str.match(/([+-]\d+):(\d+)$/) || [, '+00', '00']).map(t => parseInt(t,10));
159+
return h * 60 + (h > 0 ? +m : -m);
160+
}
161+
162+
transformContributionUsers() {
163+
let users = [];
164+
if(this.status?.contributions?.data.repository.contributions.nodes) {
165+
const usersWithTimeZones = this.status.contributions.data.repository.contributions.nodes.map(u => ({...u, tzOffset: this.getTimezoneOffset(getTz(u.login))}));
166+
users = [].concat([this.nullUser],usersWithTimeZones.sort( (a:any, b:any) =>
167+
a.tzOffset == b.tzOffset ? a.login.localeCompare(b.login) :
168+
a.tzOffset == undefined ? 1 :
169+
b.tzOffset == undefined ? -1 :
170+
a.tzOffset - b.tzOffset
171+
));
172+
}
173+
this.contributionUsers = users;
174+
}
175+
145176
transformPlatformStatusData() {
146177
this.labeledPulls = [];
147178

public/src/app/home/home.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
</span>
2020

2121
<span class="navbar-contributions" *ngIf="showContributions">
22-
<span *ngFor="let user of contributionUsers()" class="navbar-contribution {{activeTab === user.login ? 'fixed' : ''}}">
22+
<span *ngFor="let user of contributionUsers" class="navbar-contribution {{activeTab === user.login ? 'fixed' : ''}}">
2323
<app-contributions (onSelectTab)="selectTab($event)" [user]="user"></app-contributions>
2424
</span>
2525
<span class="navbar-contribution">
@@ -51,7 +51,7 @@
5151
<div id="tabs">
5252

5353
<ng-container *ngIf="showContributions">
54-
<div id="tab-{{user.login ?? 'unassigned-contributions'}}" class="{{activeTab == user.login ? 'tab-active' : ''}}" *ngFor="let user of contributionUsers()">
54+
<div id="tab-{{user.login ?? 'unassigned-contributions'}}" class="{{activeTab == user.login ? 'tab-active' : ''}}" *ngFor="let user of contributionUsers">
5555
<app-contributions-tab [user]="user"></app-contributions-tab>
5656
</div>
5757
</ng-container>

public/src/app/home/home.component.ts

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export class HomeComponent {
4444
get phaseEnd() { return this.data.phaseEnd };
4545
get unlabeledPulls() { return this.data.unlabeledPulls };
4646
get serviceState() { return this.data.serviceState };
47+
get contributionUsers() { return this.data.contributionUsers; }
4748

4849
constructor(private statusService: StatusService, private route: ActivatedRoute, private zone: NgZone) {
4950
};
@@ -96,34 +97,6 @@ export class HomeComponent {
9697

9798
// Tab View
9899

99-
nullUser = { login:'', avatarUrl: null, contributions: {
100-
issues: { nodes: [] },
101-
pullRequests: { nodes: [] },
102-
reviews: { nodes: [] },
103-
tests: { nodes: [] },
104-
} };
105-
106-
private getTimezoneOffset(timeZone){
107-
if(!timeZone) return undefined;
108-
const str = new Date().toLocaleString('en', {timeZone, timeZoneName: 'longOffset'});
109-
const [_,h,m] = (str.match(/([+-]\d+):(\d+)$/) || [, '+00', '00']).map(t => parseInt(t,10));
110-
return h * 60 + (h > 0 ? +m : -m);
111-
}
112-
113-
contributionUsers() {
114-
let users = [];
115-
if(this.status?.contributions?.data.repository.contributions.nodes) {
116-
const usersWithTimeZones = this.status?.contributions?.data.repository.contributions.nodes.map(u => ({...u, tzOffset: this.getTimezoneOffset(getTz(u.login))}));
117-
users = [].concat([this.nullUser],usersWithTimeZones.sort( (a:any, b:any) =>
118-
a.tzOffset == b.tzOffset ? a.login.localeCompare(b.login) :
119-
a.tzOffset == undefined ? 1 :
120-
b.tzOffset == undefined ? -1 :
121-
a.tzOffset - b.tzOffset
122-
));
123-
}
124-
return users;
125-
}
126-
127100
getAllContributions = () => {
128101
let text = '';
129102
for(let user of this.status?.contributions?.data.repository.contributions.nodes) {

0 commit comments

Comments
 (0)