-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathboardSummary.tsx
312 lines (290 loc) · 11.2 KB
/
boardSummary.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
import React from 'react';
import { WorkItem, WorkItemType } from 'azure-devops-extension-api/WorkItemTracking/WorkItemTracking';
import { DocumentCard, DocumentCardTitle, DocumentCardType } from 'office-ui-fabric-react/lib/DocumentCard';
import { Image } from 'office-ui-fabric-react/lib/Image';
import { WorkItemTrackingServiceIds, IWorkItemFormNavigationService } from 'azure-devops-extension-api/WorkItemTracking';
import { DetailsList, DetailsListLayoutMode, SelectionMode, IColumn } from 'office-ui-fabric-react/lib/DetailsList';
import { withAITracking } from '@microsoft/applicationinsights-react-js';
import { reactPlugin } from '../utilities/telemetryClient';
import { SDKContext } from '../dal/azureDevOpsContextProvider';
export interface IBoardSummaryProps {
actionItems: WorkItem[];
pendingWorkItemsCount: number;
resolvedActionItemsCount: number;
boardName: string;
feedbackItemsCount: number;
supportedWorkItemTypes: WorkItemType[];
}
interface IBoardSummaryState {
actionItemTableItems: IActionItemsTableProps[];
actionItemTableColumns: IColumn[];
}
interface IIconProps {
name: string;
class: string;
url: string;
}
interface IActionItemsTableProps {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[key: string]: any;
icon: IIconProps;
title: string;
state: string;
type: string;
changedDate: string;
assignedTo: string;
priority: string;
id: number;
onActionItemClick: (id: number) => void;
}
class BoardSummary extends React.Component<IBoardSummaryProps, IBoardSummaryState> {
constructor(props: IBoardSummaryProps) {
super(props);
const actionItemsTableColumns: IColumn[] = [
{
ariaLabel: 'Work item type icon',
fieldName: 'icon',
isIconOnly: true,
isResizable: false,
key: 'icon',
maxWidth: 16,
minWidth: 16,
name: 'Work Item Icon',
onRender: ({ icon, type }: IActionItemsTableProps) => {
return <Image
src={icon.url}
className="work-item-type-icon"
alt={`${type} icon`}
/>;
}
},
{
ariaLabel: 'Work item title.',
fieldName: 'title',
isResizable: true,
key: 'title',
maxWidth: 350,
minWidth: 100,
name: 'Title',
onColumnClick: this.onColumnClick,
onRender: ({ id, title, onActionItemClick }: IActionItemsTableProps) => {
return <button
onClick={() => {
onActionItemClick(id);
}}
className="work-item-title overflow-ellipsis">
{title}
</button>;
}
},
{
key: 'state',
name: 'State',
fieldName: 'state',
minWidth: 50,
maxWidth: 100,
isResizable: true,
ariaLabel: 'Work item state.',
onColumnClick: this.onColumnClick,
},
{
key: 'type',
name: 'Type',
fieldName: 'type',
minWidth: 50,
maxWidth: 100,
isResizable: true,
ariaLabel: 'Work item type.',
onColumnClick: this.onColumnClick,
},
{
key: 'changedDate',
name: 'Last Updated',
fieldName: 'changedDate',
minWidth: 100,
maxWidth: 150,
isResizable: true,
ariaLabel: 'Work item changed date.',
onRender: ({ changedDate }: IActionItemsTableProps) => {
const changedDateAsDate = new Date(changedDate);
return <div
className="overflow-ellipsis">
{new Intl.DateTimeFormat('en-US',
{ year: 'numeric', month: 'short', day: 'numeric' }
).format(changedDateAsDate)}
</div>;
},
onColumnClick: this.onColumnClick,
},
{
key: 'assignedTo',
name: 'Assigned To',
fieldName: 'assignedTo',
minWidth: 100,
maxWidth: 400,
isResizable: true,
ariaLabel: 'Work item assigned to.',
onColumnClick: this.onColumnClick,
},
{
key: 'priority',
name: 'Priority',
fieldName: 'priority',
minWidth: 50,
maxWidth: 50,
isResizable: true,
ariaLabel: 'Work item priority.',
onColumnClick: this.onColumnClick,
},
];
this.state = {
actionItemTableItems: new Array<IActionItemsTableProps>(),
actionItemTableColumns: actionItemsTableColumns
};
}
public componentDidMount() {
const actionItemTableItems = this.buildActionItemsList();
this.setState({ actionItemTableItems });
}
private readonly getIconForWorkItemType = (type: string): IIconProps => {
const workItemType: WorkItemType = this.props.supportedWorkItemTypes.find(wit => wit.name === type);
return {
name: workItemType.name,
class: workItemType.icon.id,
url: workItemType.icon.url,
};
}
private readonly buildActionItemsList = () => {
const actionItemsList = new Array<IActionItemsTableProps>();
this.props.actionItems.forEach(workItem => {
const item: IActionItemsTableProps = {
icon: this.getIconForWorkItemType(workItem.fields['System.WorkItemType']),
title: workItem.fields['System.Title'],
state: workItem.fields['System.State'],
type: workItem.fields['System.WorkItemType'],
changedDate: workItem.fields['System.ChangedDate'],
assignedTo: workItem.fields['System.AssignedTo']?.displayName ?? "",
priority: workItem.fields['Microsoft.VSTS.Common.Priority'],
id: workItem.id,
onActionItemClick: async (id: number) => {
const { SDK } = React.useContext(SDKContext);
const workItemNavSvc = await SDK.getService<IWorkItemFormNavigationService>(WorkItemTrackingServiceIds.WorkItemFormNavigationService);
await workItemNavSvc.openWorkItem(id);
}
};
actionItemsList.push(item);
});
return actionItemsList;
}
private readonly onColumnClick = (_: React.MouseEvent<HTMLElement>, column: IColumn): void => {
const actionItems = this.state.actionItemTableItems;
let newActionItems = actionItems.slice();
const newTableColumns: IColumn[] = this.state.actionItemTableColumns.slice();
const currColumn: IColumn = newTableColumns.filter((currCol: IColumn) => {
return column.key === currCol.key;
})[0];
newTableColumns.forEach((newCol: IColumn) => {
if (newCol === currColumn) {
currColumn.isSortedDescending = !currColumn.isSortedDescending;
currColumn.isSorted = true;
} else {
newCol.isSorted = false;
newCol.isSortedDescending = true;
}
});
newActionItems = this.sortActionItemsByColumn(newActionItems, currColumn.fieldName || '', currColumn.isSortedDescending);
this.setState({
actionItemTableColumns: newTableColumns,
actionItemTableItems: newActionItems
});
}
private readonly onItemInvoked = async (item: { id: number }) => {
const { SDK } = React.useContext(SDKContext);
const workItemNavSvc = await SDK.getService<IWorkItemFormNavigationService>(WorkItemTrackingServiceIds.WorkItemFormNavigationService);
await workItemNavSvc.openWorkItem(item.id);
}
private readonly sortActionItemsByColumn = (actionItems: IActionItemsTableProps[], columnName: string, descending = false): IActionItemsTableProps[] => {
if (descending) {
return actionItems.sort((itemA: IActionItemsTableProps, itemB: IActionItemsTableProps) => {
if (itemA[columnName] < itemB[columnName]) {
return 1;
}
if (itemA[columnName] > itemB[columnName]) {
return -1;
}
return 0;
});
} else {
return actionItems.sort((itemA: IActionItemsTableProps, itemB: IActionItemsTableProps) => {
if (itemA[columnName] < itemB[columnName]) {
return -1;
}
if (itemA[columnName] > itemB[columnName]) {
return 1;
}
return 0;
});
}
}
public render() {
return (
<div className="board-summary-container" aria-label="Retrospective history container">
<DocumentCard className="board-summary-card" type={DocumentCardType.normal} aria-label="Retrospective history card">
<div className="ms-DocumentCard-details board-summary-card-title">
<DocumentCardTitle title={this.props.boardName} shouldTruncate={false} aria-label="Retrospective name" />
</div>
<div className="items-stats-container" aria-label="feedback items statistics container">
<i className="stats-icon fas fa-comment-dots"></i>
<div className="count-and-text" aria-label="count and text container">
<div className="count" aria-label="feedback item count">{this.props.feedbackItemsCount}</div>
<div className="text">Feedback items created.</div>
</div>
</div>
<div className="items-stats-container" aria-label="feedback items statistics container">
<i className="stats-icon fa-regular fa-square-plus"></i>
<div className="count-and-text" aria-label="count and text container">
<div className="count" aria-label="total work items count">{this.props.actionItems.length}</div>
<div className="text">Work items created.</div>
</div>
</div>
<div className="items-stats-container" aria-label="feedback items statistics container">
<i className="stats-icon pending-action-item-color fa-solid fa-hourglass-half"></i>
<div className="count-and-text" aria-label="count and text container">
<div className={`count ${this.props.pendingWorkItemsCount > 0 ? 'pending-action-item-color' : ''}`} aria-label="pending work items count">
{this.props.pendingWorkItemsCount}</div>
<div className="text">Work items pending.</div>
</div>
</div>
<div className="items-stats-container" aria-label="feedback items statistics container">
<i className="stats-icon resolved-green fa-solid fa-clipboard-check"></i>
<div className="count-and-text" aria-label="count and text container">
<div className={`count ${this.props.resolvedActionItemsCount > 0 ? 'resolved-green' : ''}`} aria-label="resolved work items count">
{this.props.resolvedActionItemsCount}</div>
<div className="text">Work items resolved.</div>
</div>
</div>
</DocumentCard>
<div className="action-items-summary-card">
{
this.props.actionItems.length > 0 &&
<DetailsList
items={this.state.actionItemTableItems}
compact={false}
columns={this.state.actionItemTableColumns}
selectionMode={SelectionMode.none}
setKey="set"
layoutMode={DetailsListLayoutMode.justified}
isHeaderVisible={true}
selectionPreservedOnEmptyClick={true}
onItemInvoked={this.onItemInvoked} />
}
{
this.props.actionItems.length === 0 &&
<div className="no-action-items">Looks like no work items were created for this board.</div>
}
</div>
</div>
);
}
}
export default withAITracking(reactPlugin, BoardSummary);