-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathfeedbackBoardContainer.tsx
1925 lines (1739 loc) · 84.8 KB
/
feedbackBoardContainer.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import React from 'react';
import { ActionButton, DefaultButton, IconButton, MessageBarButton, PrimaryButton } from 'office-ui-fabric-react/lib/Button';
import { ContextualMenuItemType, IContextualMenuItem } from 'office-ui-fabric-react/lib/ContextualMenu';
import { Dialog, DialogType, DialogFooter, DialogContent } from 'office-ui-fabric-react/lib/Dialog';
import { Pivot, PivotItem } from 'office-ui-fabric-react/lib/Pivot';
import { MessageBar, MessageBarType } from 'office-ui-fabric-react/lib/MessageBar';
import { Spinner, SpinnerSize } from 'office-ui-fabric-react/lib/Spinner';
import { MobileWidthBreakpoint } from '../config/constants';
import { WorkflowPhase } from '../interfaces/workItem';
import WorkflowStage from './workflowStage';
import BoardDataService from '../dal/boardDataService';
import { FeedbackBoardDocumentHelper, IFeedbackBoardDocument, IFeedbackBoardDocumentPermissions, IFeedbackColumn, IFeedbackItemDocument } from '../interfaces/feedback';
import { reflectBackendService } from '../dal/reflectBackendService';
import BoardSummaryTable from './boardSummaryTable';
import FeedbackBoardMetadataForm from './feedbackBoardMetadataForm';
import FeedbackBoard from '../components/feedbackBoard';
import { azureDevOpsCoreService } from '../dal/azureDevOpsCoreService';
import { workItemService } from '../dal/azureDevOpsWorkItemService';
import { WebApiTeam } from 'azure-devops-extension-api/Core';
import { getBoardUrl } from '../utilities/boardUrlHelper';
import NoFeedbackBoardsView from './noFeedbackBoardsView';
import { userDataService } from '../dal/userDataService';
import ExtensionSettingsMenu from './extensionSettingsMenu';
import SelectorCombo, { ISelectorList } from './selectorCombo';
import FeedbackBoardPreviewEmail from './feedbackBoardPreviewEmail';
import { ToastContainer, toast, Slide } from 'react-toastify';
import { WorkItemType, WorkItemTypeReference } from 'azure-devops-extension-api/WorkItemTracking/WorkItemTracking';
import { TooltipHost } from 'office-ui-fabric-react/lib/Tooltip';
import { shareBoardHelper } from '../utilities/shareBoardHelper';
import { itemDataService } from '../dal/itemDataService';
import { TeamMember } from 'azure-devops-extension-api/WebApi';
import EffectivenessMeasurementRow from './effectivenessMeasurementRow';
import { encrypt, getUserIdentity } from '../utilities/userIdentityHelper';
import { getQuestionName, getQuestionShortName, getQuestionTooltip, getQuestionFontAwesomeClass, questions } from '../utilities/effectivenessMeasurementQuestionHelper';
import { withAITracking } from '@microsoft/applicationinsights-react-js';
import { appInsights, reactPlugin, TelemetryEvents } from '../utilities/telemetryClient';
import copyToClipboard from 'copy-to-clipboard';
import { getColumnsByTemplateId } from '../utilities/boardColumnsHelper';
import { FeedbackBoardPermissionOption } from './feedbackBoardMetadataFormPermissions';
import { CommonServiceIds, IHostNavigationService } from 'azure-devops-extension-api/Common/CommonServices';
import { FontIcon } from 'office-ui-fabric-react';
import { SDKContext } from '../dal/azureDevOpsContextProvider';
export interface FeedbackBoardContainerProps {
isHostedAzureDevOps: boolean;
projectId: string;
}
export interface FeedbackBoardContainerState {
boards: IFeedbackBoardDocument[];
currentUserId: string;
currentBoard: IFeedbackBoardDocument;
currentTeam: WebApiTeam;
filteredProjectTeams: WebApiTeam[];
filteredUserTeams: WebApiTeam[];
isAppInitialized: boolean;
isBackendServiceConnected: boolean;
isReconnectingToBackendService: boolean;
isSummaryDashboardVisible: boolean;
isTeamDataLoaded: boolean;
isAllTeamsLoaded: boolean;
maxvotesPerUser: number;
/**
* Teams that the current user is specifically a member of.
*/
userTeams: WebApiTeam[];
/**
* All teams within the current organization.
*/
projectTeams: WebApiTeam[];
nonHiddenWorkItemTypes: WorkItemType[];
allWorkItemTypes: WorkItemType[];
isPreviewEmailDialogHidden: boolean;
isRetroSummaryDialogHidden: boolean;
isBoardCreationDialogHidden: boolean;
isBoardDuplicateDialogHidden: boolean;
isBoardUpdateDialogHidden: boolean;
isArchiveBoardConfirmationDialogHidden: boolean;
isDeleteBoardConfirmationDialogHidden: boolean;
isMobileBoardActionsDialogHidden: boolean;
isMobileTeamSelectorDialogHidden: boolean;
isTeamBoardDeletedInfoDialogHidden: boolean;
isTeamSelectorCalloutVisible: boolean;
teamBoardDeletedDialogMessage: string;
teamBoardDeletedDialogTitle: string;
isCarouselDialogHidden: boolean;
isIncludeTeamEffectivenessMeasurementDialogHidden: boolean;
isPrimeDirectiveDialogHidden: boolean;
isLiveSyncInTfsIssueMessageBarVisible: boolean;
isDropIssueInEdgeMessageBarVisible: boolean;
isDesktop: boolean;
isAutoResizeEnabled: boolean;
allowCrossColumnGroups: boolean;
feedbackItems: IFeedbackItemDocument[];
contributors: { id: string, name: string, imageUrl: string }[];
effectivenessMeasurementSummary: { questionId: number, question: string, average: number }[];
effectivenessMeasurementChartData: { questionId: number, red: number, yellow: number, green: number }[];
teamEffectivenessMeasurementAverageVisibilityClassName: string;
actionItemIds: number[];
/**
* Members of the all teams that the current user access to. This may not be all the team
* members within the organization.
*/
allMembers: TeamMember[];
castedVoteCount: number;
boardColumns: IFeedbackColumn[];
questionIdForDiscussAndActBoardUpdate: number;
}
class FeedbackBoardContainer extends React.Component<FeedbackBoardContainerProps, FeedbackBoardContainerState> {
constructor(props: FeedbackBoardContainerProps) {
super(props);
this.state = {
allWorkItemTypes: [],
allowCrossColumnGroups: false,
boards: [],
currentUserId: getUserIdentity().id,
currentBoard: undefined,
currentTeam: undefined,
filteredProjectTeams: [],
filteredUserTeams: [],
isAllTeamsLoaded: false,
isAppInitialized: false,
isAutoResizeEnabled: true,
isBackendServiceConnected: false,
isBoardCreationDialogHidden: true,
isBoardDuplicateDialogHidden: true,
isBoardUpdateDialogHidden: true,
isCarouselDialogHidden: true,
isIncludeTeamEffectivenessMeasurementDialogHidden: true,
isPrimeDirectiveDialogHidden: true,
isArchiveBoardConfirmationDialogHidden: true,
isDeleteBoardConfirmationDialogHidden: true,
isDesktop: true,
isDropIssueInEdgeMessageBarVisible: true,
isLiveSyncInTfsIssueMessageBarVisible: true,
isMobileBoardActionsDialogHidden: true,
isMobileTeamSelectorDialogHidden: true,
isPreviewEmailDialogHidden: true,
isRetroSummaryDialogHidden: true,
isReconnectingToBackendService: false,
isSummaryDashboardVisible: false,
isTeamBoardDeletedInfoDialogHidden: true,
isTeamDataLoaded: false,
isTeamSelectorCalloutVisible: false,
nonHiddenWorkItemTypes: [],
projectTeams: [],
teamBoardDeletedDialogMessage: '',
teamBoardDeletedDialogTitle: '',
userTeams: [],
maxvotesPerUser: 5,
feedbackItems: [],
contributors: [],
effectivenessMeasurementSummary: [],
effectivenessMeasurementChartData: [],
teamEffectivenessMeasurementAverageVisibilityClassName: "hidden",
actionItemIds: [],
allMembers: [],
castedVoteCount: 0,
boardColumns: [],
questionIdForDiscussAndActBoardUpdate: -1
};
}
public async componentDidMount() {
let initialCurrentTeam: WebApiTeam | undefined;
let initialCurrentBoard: IFeedbackBoardDocument | undefined;
try {
const isBackendServiceConnected = await reflectBackendService.startConnection();
this.setState({ isBackendServiceConnected });
} catch (error) {
console.error({ m: "isBackendServiceConnected", error });
}
try {
const initializedTeamAndBoardState = await this.initializeFeedbackBoard();
initialCurrentTeam = initializedTeamAndBoardState.currentTeam;
initialCurrentBoard = initializedTeamAndBoardState.currentBoard;
await this.initializeProjectTeams(initialCurrentTeam);
this.setState({ ...initializedTeamAndBoardState, isTeamDataLoaded: true, });
} catch (error) {
console.error({ m: "initializedTeamAndBoardState", error });
}
try {
await this.setSupportedWorkItemTypesForProject();
} catch (error) {
console.error({ m: "setSupportedWorkItemTypesForProject", error });
}
try {
await this.updateFeedbackItemsAndContributors(initialCurrentTeam, initialCurrentBoard);
} catch (error) {
console.error({ m: "updateFeedbackItemsAndContributors", error });
}
try {
const votes = Object.values(initialCurrentBoard?.boardVoteCollection || []);
this.setState({ castedVoteCount: (votes !== null && votes.length > 0) ? votes.reduce((a, b) => a + b, 0) : 0 });
} catch (error) {
console.error({ m: "votes", error });
}
try {
reflectBackendService.onConnectionClose(() => {
this.setState({
isBackendServiceConnected: false,
isReconnectingToBackendService: true,
});
setTimeout(this.tryReconnectToBackend, 2000);
});
// Listen for signals for board updates.
reflectBackendService.onReceiveNewBoard(this.handleNewBoardAvailable);
reflectBackendService.onReceiveDeletedBoard(this.handleBoardDeleted);
reflectBackendService.onReceiveUpdatedBoard(this.handleBoardUpdated);
}
catch (e) {
console.error(e);
appInsights.trackException(e);
}
this.setState({ isAppInitialized: true });
}
public componentDidUpdate(prevProps: FeedbackBoardContainerProps, prevState: FeedbackBoardContainerState) {
if (prevState.currentTeam !== this.state.currentTeam) {
appInsights.trackEvent({name: TelemetryEvents.TeamSelectionChanged, properties: {teamId: this.state.currentTeam.id}});
}
if (prevState.currentBoard !== this.state.currentBoard) {
reflectBackendService.switchToBoard(this.state.currentBoard ? this.state.currentBoard.id : undefined);
appInsights.trackEvent({name: TelemetryEvents.FeedbackBoardSelectionChanged, properties: {boardId: this.state.currentBoard?.id}});
if (this.state.isAppInitialized) {
userDataService.addVisit(this.state.currentTeam.id, this.state.currentBoard ? this.state.currentBoard.id : undefined);
}
}
}
public componentWillUnmount() {
window.removeEventListener('resize', this.handleResolutionChange);
reflectBackendService.removeOnReceiveNewBoard(this.handleNewBoardAvailable);
reflectBackendService.removeOnReceiveDeletedBoard(this.handleBoardDeleted);
reflectBackendService.removeOnReceiveUpdatedBoard(this.handleBoardUpdated);
}
private async updateUrlWithBoardAndTeamInformation(teamId: string, boardId: string) {
const { SDK } = React.useContext(SDKContext);
SDK.getService<IHostNavigationService>(CommonServiceIds.HostNavigationService).then(service => {
service.setHash(`teamId=${teamId}&boardId=${boardId}`);
});
}
private async parseUrlForBoardAndTeamInformation(): Promise<{ teamId: string, boardId: string }> {
const { SDK } = React.useContext(SDKContext);
const service = await SDK.getService<IHostNavigationService>(CommonServiceIds.HostNavigationService);
let hash = await service.getHash();
if (hash.startsWith('#')) {
hash = hash.substring(1);
}
const hashParams = new URLSearchParams(hash);
const teamId = hashParams.get("teamId");
const boardId = hashParams.get("boardId");
return { teamId, boardId };
}
private async updateFeedbackItemsAndContributors(currentTeam: WebApiTeam, currentBoard: IFeedbackBoardDocument) {
if (!currentTeam || !currentBoard) {
return;
}
const board: IFeedbackBoardDocument = await itemDataService.getBoardItem(currentTeam.id, currentBoard.id);
const feedbackItems = await itemDataService.getFeedbackItemsForBoard(board?.id) ?? [];
await this.updateUrlWithBoardAndTeamInformation(currentTeam.id, board.id);
let actionItemIds: number[] = [];
feedbackItems.forEach(item => {
actionItemIds = actionItemIds.concat(item.associatedActionItemIds);
});
const contributors = feedbackItems.map(e => { return { id: e.userIdRef, name: e?.createdBy?.displayName, imageUrl: e?.createdBy?.imageUrl }; }).filter((v, i, a) => a.indexOf(v) === i);
const votes = Object.values(board.boardVoteCollection || []);
this.setState({
actionItemIds: actionItemIds.filter(item => item !== undefined),
feedbackItems,
contributors: [...new Set(contributors.map(e => e.id))].map(e => contributors.find(i => i.id === e)),
castedVoteCount: (votes !== null && votes.length > 0) ? votes.reduce((a, b) => a + b, 0) : 0
});
}
private readonly toggleAndFixResolution = () => {
this.setState((prevState) => ({
isAutoResizeEnabled: false,
isDesktop: !prevState.isDesktop,
}));
}
private readonly handleResolutionChange = () => {
const isDesktop = window.innerWidth >= MobileWidthBreakpoint;
if (this.state.isAutoResizeEnabled && this.state.isDesktop != isDesktop) {
this.setState({
isDesktop: isDesktop,
});
}
}
private readonly numberFormatter = (value: number) => {
const formatter = new Intl.NumberFormat("en-US", { style: "decimal", minimumFractionDigits: 1, maximumFractionDigits: 1 });
return formatter.format(value);
}
private readonly percentageFormatter = (value: number) => {
const formatter = new Intl.NumberFormat("en-US", { style: "percent", minimumFractionDigits: 1, maximumFractionDigits: 1 });
return formatter.format(value / 100);
}
private readonly handleNewBoardAvailable = async (teamId: string, boardId: string) => {
if (!teamId || this.state.currentTeam.id !== teamId) {
return;
}
const boardToAdd = await BoardDataService.getBoardForTeamById(this.state.currentTeam.id, boardId);
if (!boardToAdd) {
return;
}
// @ts-ignore TS2345
this.setState(prevState => {
const boardsForTeam = [...prevState.boards, boardToAdd]
.filter((board: IFeedbackBoardDocument) => FeedbackBoardDocumentHelper.filter(board, this.state.userTeams.map(t => t.id), this.state.currentUserId))
.sort((b1, b2) => FeedbackBoardDocumentHelper.sort(b1, b2));
const baseResult = {
boards: boardsForTeam,
isTeamBoardDeletedInfoDialogHidden: true,
};
if (boardsForTeam.length === 1) {
return {
...baseResult,
currentBoard: boardsForTeam[0],
};
}
return baseResult;
});
}
private readonly setSupportedWorkItemTypesForProject = async (): Promise<void> => {
const allWorkItemTypes: WorkItemType[] = await workItemService.getWorkItemTypesForCurrentProject();
const hiddenWorkItemTypes: WorkItemTypeReference[] = await workItemService.getHiddenWorkItemTypes();
const hiddenWorkItemTypeNames = hiddenWorkItemTypes.map((workItemType) => workItemType.name);
const nonHiddenWorkItemTypes = allWorkItemTypes.filter(workItemType => hiddenWorkItemTypeNames.indexOf(workItemType.name) === -1);
this.setState({
nonHiddenWorkItemTypes: nonHiddenWorkItemTypes,
allWorkItemTypes: allWorkItemTypes,
});
}
private readonly replaceBoard = (updatedBoard: IFeedbackBoardDocument) => {
this.setState(prevState => {
const newBoards = prevState.boards.map((board) => board.id === updatedBoard.id ? updatedBoard : board);
const newCurrentBoard = this.state.currentBoard && this.state.currentBoard.id === updatedBoard.id ? updatedBoard : this.state.currentBoard;
return {
boards: newBoards,
currentBoard: newCurrentBoard,
};
})
}
private readonly handleBoardUpdated = async (teamId: string, updatedBoardId: string) => {
if (!teamId || this.state.currentTeam.id !== teamId) {
return;
}
const updatedBoard = await BoardDataService.getBoardForTeamById(this.state.currentTeam.id, updatedBoardId);
if (!updatedBoard) {
// Board has been deleted after the update. Just ignore the update. The delete should be handled on its own.
return;
}
this.replaceBoard(updatedBoard);
};
private readonly handleBoardDeleted = async (teamId: string, deletedBoardId: string) => {
if (!teamId || this.state.currentTeam.id !== teamId) {
return;
}
// @ts-ignore TS2345
this.setState(prevState => {
const currentBoards = prevState.boards;
// Note: Javascript filter maintains order.
const boardsForTeam = currentBoards.filter(board => board.id !== deletedBoardId);
if (prevState.currentBoard && deletedBoardId === prevState.currentBoard.id) {
if (!boardsForTeam || boardsForTeam.length === 0) {
reflectBackendService.switchToBoard(undefined);
return {
boards: [],
currentBoard: null,
isBoardUpdateDialogHidden: true,
isTeamBoardDeletedInfoDialogHidden: false,
teamBoardDeletedDialogTitle: 'Retrospective deleted',
teamBoardDeletedDialogMessage: 'The retrospective you were viewing has been deleted by another user.',
}
}
const currentBoard = boardsForTeam[0];
reflectBackendService.switchToBoard(currentBoard.id);
return {
boards: boardsForTeam,
currentBoard: currentBoard,
isBoardUpdateDialogHidden: true,
isTeamBoardDeletedInfoDialogHidden: false,
teamBoardDeletedDialogTitle: 'Retrospective deleted',
teamBoardDeletedDialogMessage: 'The retrospective you were viewing has been deleted by another user. You will be switched to the last created retrospective for this team.',
};
}
return {
boards: boardsForTeam,
};
}, async () => {
await userDataService.addVisit(this.state.currentTeam?.id, this.state.currentBoard?.id);
});
}
/**
* @description Loads team data for this project and the current user. Attempts to use query
* params or user records to pre-select team and board, otherwise default to the first team
* the current user is a part of and most recently created board.
* @returns An object to update the state with initialized team and board data.
*/
private readonly initializeFeedbackBoard = async (): Promise<{
userTeams: WebApiTeam[],
filteredUserTeams: WebApiTeam[],
currentTeam: WebApiTeam,
boards: IFeedbackBoardDocument[],
currentBoard: IFeedbackBoardDocument,
isTeamBoardDeletedInfoDialogHidden: boolean,
teamBoardDeletedDialogTitle: string,
teamBoardDeletedDialogMessage: string,
}> => {
const userTeams = await azureDevOpsCoreService.getAllTeams(this.props.projectId, true);
userTeams?.sort((t1, t2) => {
return t1.name.localeCompare(t2.name, [], { sensitivity: "accent" });
});
// Default to select first user team or the project's default team.
const defaultTeam = (userTeams?.length) ? userTeams[0] : await azureDevOpsCoreService.getDefaultTeam(this.props.projectId);
const baseTeamState = {
userTeams,
filteredUserTeams: userTeams,
currentTeam: defaultTeam,
isTeamBoardDeletedInfoDialogHidden: true,
teamBoardDeletedDialogTitle: '',
teamBoardDeletedDialogMessage: '',
};
const searchParams = new URLSearchParams(document.location.search);
if (searchParams.has("name")) {
const name = searchParams.get("name");
const maxVotes = searchParams.get("maxVotes") || "5";
const isTeamAssessment = searchParams.get("isTeamAssessment") || "true";
const columns = getColumnsByTemplateId(searchParams.get("templateId") || "start-stop-continue");
const teamId = searchParams.get("teamId");
if (teamId) {
const matchedTeam = await azureDevOpsCoreService.getTeam(this.props.projectId, teamId);
if (matchedTeam) {
this.setState({ currentTeam: matchedTeam });
}
}
if (this.state.currentTeam === undefined) {
this.setState({ currentTeam: defaultTeam });
}
const newBoard = await this.createBoard(name, parseInt(maxVotes), columns, isTeamAssessment === "true", false, false, false, { Members: [], Teams: [] });
parent.location.href = await getBoardUrl(this.state.currentTeam.id, newBoard.id);
}
const info = await this.parseUrlForBoardAndTeamInformation();
try {
if (!info) {
if (!this.props.isHostedAzureDevOps) {
throw new Error("URL-related issue occurred with on-premise Azure DevOps");
}
else if (!document.referrer) {
throw new Error("URL-related issue occurred with this URL: (Empty URL)");
}
else {
const indexVisualStudioCom = document.location.href.indexOf("visualstudio.com");
const indexDevAzureCom = document.location.href.indexOf("dev.azure.com");
if (indexVisualStudioCom >= 0) {
const indexSecondSlashAfterVisualStudioCom = document.location.href.indexOf("/", indexVisualStudioCom + "visualstudio.com/".length);
throw new Error("URL-related issue occurred with this URL: " + document.location.href.substring(indexSecondSlashAfterVisualStudioCom));
}
else if (indexDevAzureCom >= 0) {
const indexSecondSlashAfterDevAzureCom = document.location.href.indexOf("/", indexDevAzureCom + "dev.azure.com/".length);
const indexThirdSlashAfterDevAzureCom = document.location.href.indexOf("/", indexSecondSlashAfterDevAzureCom + 1);
throw new Error("URL-related issue occurred with this URL: " + document.location.href.substring(indexThirdSlashAfterDevAzureCom));
}
else {
throw new Error("URL-related issue occurred with hosted Azure DevOps but document referrer does not contain dev.azure.com or visualstudio.com");
}
}
}
}
catch (e) {
appInsights.trackException(e);
}
if (!info?.teamId) {
// If the teamId query param doesn't exist, attempt to pre-select a team and board by last
// visited user records.
const recentVisitState = await this.loadRecentlyVisitedOrDefaultTeamAndBoardState(defaultTeam, userTeams);
return {
...baseTeamState,
...recentVisitState,
}
}
// Attempt to pre-select the team based on the teamId query param.
const teamIdQueryParam = info.teamId;
const matchedTeam = await azureDevOpsCoreService.getTeam(this.props.projectId, teamIdQueryParam);
if (!matchedTeam) {
// If the teamId query param wasn't valid attempt to pre-select a team and board by last
// visited user records.
const recentVisitState = await this.loadRecentlyVisitedOrDefaultTeamAndBoardState(defaultTeam, userTeams);
const recentVisitWithDialogState = {
...recentVisitState,
isTeamBoardDeletedInfoDialogHidden: false,
teamBoardDeletedDialogTitle: 'Team not found',
teamBoardDeletedDialogMessage: 'Could not find the team specified in the url.',
}
return {
...baseTeamState,
...recentVisitWithDialogState,
};
}
let boardsForMatchedTeam = await BoardDataService.getBoardsForTeam(matchedTeam.id);
if (boardsForMatchedTeam?.length) {
boardsForMatchedTeam = boardsForMatchedTeam
.filter((board: IFeedbackBoardDocument) => FeedbackBoardDocumentHelper.filter(board, this.state.userTeams.map(t => t.id), this.state.currentUserId))
.sort((b1, b2) => FeedbackBoardDocumentHelper.sort(b1, b2));
}
const queryParamTeamAndDefaultBoardState = {
...baseTeamState,
currentBoard: boardsForMatchedTeam.length ? boardsForMatchedTeam[0] : null,
currentTeam: matchedTeam,
boards: boardsForMatchedTeam,
};
if (!info.boardId) {
// If the boardId query param doesn't exist, we fall back to using the most recently
// created board. We don't use the last visited records in this case since it may be for
// a different team.
return queryParamTeamAndDefaultBoardState;
}
// Attempt to pre-select the board based on the boardId query param.
const boardIdQueryParam = info.boardId;
const matchedBoard = boardsForMatchedTeam.find((board) => board.id === boardIdQueryParam);
if (matchedBoard) {
if (matchedBoard.teamEffectivenessMeasurementVoteCollection === undefined) {
matchedBoard.teamEffectivenessMeasurementVoteCollection = [];
}
return {
...queryParamTeamAndDefaultBoardState,
currentBoard: matchedBoard,
}
} else {
// If the boardId query param wasn't valid, we fall back to using the most recently
// created board. We don't use the last visited records in this case since it may be for
// a different team.
return {
...queryParamTeamAndDefaultBoardState,
isTeamBoardDeletedInfoDialogHidden: false,
teamBoardDeletedDialogTitle: 'Board not found',
teamBoardDeletedDialogMessage: 'Could not find the board specified in the url.'
};
}
}
private readonly initializeProjectTeams = async (defaultTeam: WebApiTeam) => {
// true returns all teams that user is a member in the project
// false returns all teams that are in project
// intentionally restricting to teams the user is a member
const allTeams = await azureDevOpsCoreService.getAllTeams(this.props.projectId, true);
allTeams.sort((t1, t2) => {
return t1.name.localeCompare(t2.name, [], { sensitivity: "accent" });
});
const promises = []
for (const team of allTeams) {
promises.push(azureDevOpsCoreService.getMembers(this.props.projectId, team.id));
}
// if user is member of more than one team, then will return duplicates
Promise.all(promises).then((values) => {
const allTeamMembers: TeamMember[] = [];
for (const members of values) {
allTeamMembers.push(...members);
}
// remove duplicate members
const uniqueTeamMembers = Array.from(
new Map(allTeamMembers.map(member => [member.identity.id, member])).values());
this.setState({
allMembers: uniqueTeamMembers,
projectTeams: allTeams?.length > 0 ? allTeams : [defaultTeam],
filteredProjectTeams: allTeams?.length > 0 ? allTeams : [defaultTeam],
isAllTeamsLoaded: true,
});
});
}
/**
* @description Load the last team and board that this user visited, if such records exist.
* @returns An object to update the state with recently visited or default team and board data.
*/
private readonly loadRecentlyVisitedOrDefaultTeamAndBoardState = async (defaultTeam: WebApiTeam, userTeams: WebApiTeam[]): Promise<{
boards: IFeedbackBoardDocument[],
currentBoard: IFeedbackBoardDocument,
currentTeam: WebApiTeam,
}> => {
const mostRecentUserVisit = await userDataService.getMostRecentVisit();
if (mostRecentUserVisit) {
const mostRecentTeam = await azureDevOpsCoreService.getTeam(this.props.projectId, mostRecentUserVisit.teamId);
if (mostRecentTeam) {
let boardsForTeam = await BoardDataService.getBoardsForTeam(mostRecentTeam.id);
if (boardsForTeam?.length > 0) {
boardsForTeam = boardsForTeam
.filter((board: IFeedbackBoardDocument) => FeedbackBoardDocumentHelper.filter(board, userTeams.map(t => t.id), this.state.currentUserId))
.sort((b1, b2) => FeedbackBoardDocumentHelper.sort(b1, b2));
}
const currentBoard = boardsForTeam?.length > 0 ? boardsForTeam.at(0) : null;
const recentVisitState = {
boards: boardsForTeam,
currentBoard,
currentTeam: mostRecentTeam,
};
if (boardsForTeam?.length && mostRecentUserVisit.boardId) {
const mostRecentBoard = boardsForTeam.find((board) => board.id === mostRecentUserVisit.boardId);
recentVisitState.currentBoard = mostRecentBoard || currentBoard;
}
return recentVisitState;
}
}
let boardsForMatchedTeam = await BoardDataService.getBoardsForTeam(defaultTeam.id);
if (boardsForMatchedTeam?.length) {
boardsForMatchedTeam = boardsForMatchedTeam
.filter((board: IFeedbackBoardDocument) => FeedbackBoardDocumentHelper.filter(board, userTeams.map(t => t.id), this.state.currentUserId))
.sort((b1, b2) => FeedbackBoardDocumentHelper.sort(b1, b2));
}
return {
boards: boardsForMatchedTeam,
currentBoard: (boardsForMatchedTeam?.length) ? boardsForMatchedTeam[0] : null,
currentTeam: defaultTeam,
};
}
/**
* @description Attempts to select a team from the specified teamId. If the teamId is valid,
* currentTeam is set to the new team and that team's boards are loaded.
* @param teamId The id of the team to select.
*/
private readonly setCurrentTeam = async (teamId: string) => {
this.setState({ isTeamDataLoaded: false });
const matchedTeam = this.state.projectTeams.find((team) => team.id === teamId) ||
this.state.userTeams.find((team) => team.id === teamId);
if (matchedTeam) {
let boardsForTeam = await BoardDataService.getBoardsForTeam(matchedTeam.id);
if (boardsForTeam?.length) {
boardsForTeam = boardsForTeam
.filter((board: IFeedbackBoardDocument) => FeedbackBoardDocumentHelper.filter(board, this.state.userTeams.map(t => t.id), this.state.currentUserId))
.sort((b1, b2) => FeedbackBoardDocumentHelper.sort(b1, b2));
}
// @ts-ignore TS2345
this.setState(prevState => {
// Ensure that we are actually changing teams to prevent needless rerenders.
if (!prevState.currentTeam || prevState.currentTeam.id !== matchedTeam.id) {
return {
boards: (boardsForTeam?.length) ? boardsForTeam : [],
currentBoard: (boardsForTeam?.length) ? boardsForTeam[0] : null,
currentTeam: matchedTeam,
isTeamDataLoaded: true,
}
}
return {};
});
}
}
/**
* @description Loads all feedback boards for the current team. Defaults the selected board to
* the most recently created board.
*/
private readonly reloadBoardsForCurrentTeam = async () => {
this.setState({ isTeamDataLoaded: false });
let boardsForTeam = await BoardDataService.getBoardsForTeam(this.state.currentTeam.id);
if (!boardsForTeam.length) {
this.setState({
isTeamDataLoaded: true,
boards: [],
currentBoard: null
});
return;
}
boardsForTeam = boardsForTeam
.filter((board: IFeedbackBoardDocument) => FeedbackBoardDocumentHelper.filter(board, this.state.userTeams.map(t => t.id), this.state.currentUserId))
.sort((b1, b2) => FeedbackBoardDocumentHelper.sort(b1, b2));
this.setState({
isTeamDataLoaded: true,
boards: boardsForTeam,
currentBoard: boardsForTeam[0],
});
}
/**
* @description Attempts to select a board from the specified boardId. If the boardId is valid,
* currentBoard is set to the new board. If not, nothing changes.
* @param boardId The id of the board to select.
*/
private readonly setCurrentBoard = (selectedBoard: IFeedbackBoardDocument) => {
const matchedBoard = this.state.boards.find((board) => board.id === selectedBoard.id);
if (matchedBoard.teamEffectivenessMeasurementVoteCollection === undefined) {
matchedBoard.teamEffectivenessMeasurementVoteCollection = [];
}
if (matchedBoard) {
// @ts-ignore TS2345
this.setState(prevState => {
// Ensure that we are actually changing boards to prevent needless rerenders.
if (!prevState.currentBoard || prevState.currentBoard.id !== matchedBoard.id) {
return {
currentBoard: matchedBoard,
};
}
return {};
});
}
}
private readonly changeSelectedTeam = (team: WebApiTeam) => {
if (team) {
if (this.state.currentTeam.id === team.id) {
return;
}
this.setCurrentTeam(team.id);
appInsights.trackEvent({name: TelemetryEvents.TeamSelectionChanged, properties: {teamId: team.id}});
}
}
private readonly changeSelectedBoard = async (board: IFeedbackBoardDocument) => {
if (board) {
this.setCurrentBoard(board);
this.updateUrlWithBoardAndTeamInformation(this.state.currentTeam.id, board.id);
appInsights.trackEvent({name: TelemetryEvents.FeedbackBoardSelectionChanged, properties: {boardId: board.id}});
}
}
private readonly clickWorkflowStateCallback = (_: React.MouseEvent<HTMLElement> | React.KeyboardEvent<HTMLDivElement>, newPhase: WorkflowPhase) => {
appInsights.trackEvent({name: TelemetryEvents.WorkflowPhaseChanged, properties: {oldWorkflowPhase: this.state.currentBoard.activePhase, newWorkflowPhase: newPhase}});
this.setState(prevState => {
const updatedCurrentBoard = prevState.currentBoard;
updatedCurrentBoard.activePhase = newPhase;
return {
currentBoard: updatedCurrentBoard,
};
});
}
private readonly createBoard = async (title: string, maxvotesPerUser: number, columns: IFeedbackColumn[], isIncludeTeamEffectivenessMeasurement: boolean, isBoardAnonymous: boolean, shouldShowFeedbackAfterCollect: boolean, displayPrimeDirective: boolean, permissions: IFeedbackBoardDocumentPermissions) => {
const createdBoard = await BoardDataService.createBoardForTeam(this.state.currentTeam.id,
title,
maxvotesPerUser,
columns,
isIncludeTeamEffectivenessMeasurement,
isBoardAnonymous,
shouldShowFeedbackAfterCollect,
displayPrimeDirective,
undefined, // Start Date
undefined, // End Date
permissions);
await this.reloadBoardsForCurrentTeam();
this.hideBoardCreationDialog();
this.hideBoardDuplicateDialog();
reflectBackendService.broadcastNewBoard(this.state.currentTeam.id, createdBoard.id);
appInsights.trackEvent({name: TelemetryEvents.FeedbackBoardCreated, properties: {boardId: createdBoard.id}});
return createdBoard;
}
private readonly showBoardCreationDialog = (): void => {
this.setState({ isBoardCreationDialogHidden: false });
}
private readonly hideBoardCreationDialog = (): void => {
this.setState({ isBoardCreationDialogHidden: true });
}
private readonly showPreviewEmailDialog = (): void => {
this.setState({ isPreviewEmailDialogHidden: false });
}
private readonly showRetroSummaryDialog = async () => {
const measurements: { id: number, selected: number }[] = [];
const board = await BoardDataService.getBoardForTeamById(this.state.currentTeam.id, this.state.currentBoard.id);
const voteCollection = board.teamEffectivenessMeasurementVoteCollection || [];
voteCollection.forEach(vote => {
vote?.responses?.forEach(response => {
measurements.push({ id: response.questionId, selected: response.selection });
});
});
const average: { questionId: number, question: string, average: number }[] = [];
[...new Set(measurements.map(item => item.id))].forEach(e => {
average.push({ questionId: e, question: getQuestionName(e), average: measurements.filter(m => m.id === e).reduce((a, b) => a + b.selected, 0) / measurements.filter(m => m.id === e).length });
});
const chartData: { questionId: number, red: number, yellow: number, green: number }[] = [];
[...Array(questions.length).keys()].forEach(e => {
chartData.push({ questionId: (e + 1), red: 0, yellow: 0, green: 0 });
});
voteCollection?.forEach(vote => {
[...Array(questions.length).keys()].forEach(e => {
const selection = vote.responses.find(response => response.questionId === (e + 1))?.selection;
const data = chartData.find(d => d.questionId === (e + 1));
if (selection <= 6) {
data.red++;
} else if (selection <= 8) {
data.yellow++;
} else {
data.green++;
}
});
});
chartData.sort((a, b) => {
if (a.red > b.red) {
return -1;
}
if (a.red < b.red) {
return 1;
}
const avgA = average.find(e => e.questionId === a.questionId)?.average;
const avgB = average.find(e => e.questionId === b.questionId)?.average;
if (avgA > avgB) {
return 1;
}
if (avgA < avgB) {
return -1;
}
return 0;
});
await this.updateFeedbackItemsAndContributors(this.state.currentTeam, board);
this.setState({
currentBoard: board,
isRetroSummaryDialogHidden: false,
effectivenessMeasurementChartData: chartData,
effectivenessMeasurementSummary: average,
});
}
private readonly hidePreviewEmailDialog = (): void => {
this.setState({ isPreviewEmailDialogHidden: true });
}
private readonly hideRetroSummaryDialog = (): void => {
this.setState({ isRetroSummaryDialogHidden: true });
}
private readonly updateBoardMetadata = async (title: string, maxvotesPerUser: number, columns: IFeedbackColumn[], isIncludeTeamEffectivenessMeasurement: boolean, isBoardAnonymous: boolean, shouldShowFeedbackAfterCollect: boolean, displayPrimeDirective: boolean, permissions: IFeedbackBoardDocumentPermissions) => {
const updatedBoard = await BoardDataService.updateBoardMetadata(this.state.currentTeam.id, this.state.currentBoard.id, maxvotesPerUser, title, columns, permissions);
this.updateBoardAndBroadcast(updatedBoard);
}
private readonly showBoardUpdateDialog = (): void => {
this.setState({ isBoardUpdateDialogHidden: false });
}
private readonly hideBoardUpdateDialog = (): void => {
this.setState({ isBoardUpdateDialogHidden: true });
}
private readonly showBoardDuplicateDialog = (): void => {
this.setState({ isBoardDuplicateDialogHidden: false });
}
private readonly hideBoardDuplicateDialog = (): void => {
this.setState({ isBoardDuplicateDialogHidden: true });
}
// Note: This is temporary, to support older boards that do not have an active phase.
private readonly getCurrentBoardPhase = () => {
if (!this.state.currentBoard?.activePhase) {
return WorkflowPhase.Collect;
}
return this.state.currentBoard.activePhase;
}
private readonly showDeleteBoardConfirmationDialog = () => {
this.setState({ isDeleteBoardConfirmationDialogHidden: false });
}
private readonly hideDeleteBoardConfirmationDialog = () => {
this.setState({ isDeleteBoardConfirmationDialogHidden: true });
}
private readonly showArchiveBoardConfirmationDialog = () => {
this.setState({ isArchiveBoardConfirmationDialogHidden: false });
}
private readonly hideArchiveBoardConfirmationDialog = () => {
this.setState({ isArchiveBoardConfirmationDialogHidden: true });
}
private readonly hideTeamBoardDeletedInfoDialog = () => {
this.setState(
{
isTeamBoardDeletedInfoDialogHidden: true,
teamBoardDeletedDialogTitle: '',
teamBoardDeletedDialogMessage: '',
}
);
}
private readonly showBoardUrlCopiedToast = () => {
toast(`The link to retrospective ${this.state.currentBoard.title} has been copied to your clipboard.`);
}
private readonly showEmailCopiedToast = () => {
toast(`The email summary for "${this.state.currentBoard.title}" has been copied to your clipboard.`);
}
private readonly tryReconnectToBackend = async () => {
this.setState({ isReconnectingToBackendService: true });
const backendConnectionResult = await reflectBackendService.startConnection();
if (backendConnectionResult) {