This repository has been archived by the owner on Mar 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Worktray.tsx
224 lines (200 loc) · 6.07 KB
/
Worktray.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
import React from "react";
import { Table } from "../Table/Table";
import "lbh-frontend/lbh/components/lbh-table/_table.scss";
import "./Worktray.scss";
import { FilterTabs } from "../FilterTabs/FilterTabs";
/**
* The prop types for the {@link WorkTray} component.
*
* @noInheritDoc
*/
export interface WorkTrayProps {
/**
* Array of {@link WorkTrayRow} that defines the number of rows within the Work Tray
*/
rows: WorkTrayRow[];
/**
* Array of {@link WorkTrayColumn} that defines the number of columns within the Work Tray
*/
columns: WorkTrayColumn[];
/**
* Callback function used to reassign a work item to another user. If this function returns true, the item will be removed from the work tray.
*/
reassignWorkItem: (workItemId: string) => boolean;
/**
* Callback function used to cancel a work item. If this function returns true, the item will be removed from the work tray.
*/
cancelWorkItem: (workItemId: string) => boolean;
/**
* Callback function used to pass a search query back to your API and update the data being passed to {@link WorkTrayProps.rows}
*/
searchWorkItems: (searchTerm: string) => void;
}
export interface WorkTrayRow {
/**
* Array of {@link WorkTrayCell} that defines the data that will be displayed in a particular row on the Work Tray
*/
cells: WorkTrayCell[];
/**
* When a {@link WorkTrayColumn.key} is provided, an icon marking a Cautionary Contact will be display in that cell for the row.
*/
cautionaryContactKey?: string;
/**
* Contains a URL to open the Work Item in its original application.
*/
workItemLink: string;
/**
* A unique ID to identify a Work Item
*/
workItemId: string;
/**
* Identifies the status of the Work Item for sorting.
*/
workItemStatus: Status;
}
export interface WorkTrayCell {
/**
* The key is used to identify which column this data point should be displayed under. See {@link WorkTrayColumn.key}
*/
key: string;
/**
* The value which will be displayed in the cell.
*/
value: string | Date;
}
export interface WorkTrayColumn {
/**
* Title of the Column to be displayed in the Work Tray
*/
name: string;
/**
* Used to identify which column a {@link WorkTrayCell} should be displayed under
*/
key: string;
/**
* Used to determine how data within the column should be parsed. Can be set to "basic", "datetime", or "alphanumeric"
*/
sortType: string;
/**
* Used with the {@link WorkTrayColumn.sortType} when set to datetime to determine whether to show icons alerting users to approaching due dates
*/
dueDateWarning?: boolean;
}
export enum Status {
/**
* Work Items marked as inProgress will be sorted with other In Progress items
*/
inProgress,
/**
* Work Items marked as complete will be sorted with other Complete items
*/
complete,
}
const mapAllData = (
props: WorkTrayProps
): {
[key: string]: string | Date;
}[] => {
const dataArrayAll: { [key: string]: string | Date }[] = [];
props.rows.forEach((row) => {
const rowObject: { [key: string]: string | Date } = {};
row.cells.forEach((cell) => {
rowObject[cell.key] = cell.value;
});
rowObject.link = row.workItemLink;
dataArrayAll.push(rowObject);
});
return dataArrayAll;
};
const mapCompletedData = (
props: WorkTrayProps
): {
[key: string]: string | Date;
}[] => {
const dataArrayCompleted: { [key: string]: string | Date }[] = [];
props.rows.forEach((row) => {
if (row.workItemStatus === Status.complete) {
const rowObject: { [key: string]: string | Date } = {};
row.cells.forEach((cell) => {
rowObject[cell.key] = cell.value;
});
rowObject.link = row.workItemLink;
dataArrayCompleted.push(rowObject);
}
});
return dataArrayCompleted;
};
const mapInProgressData = (
props: WorkTrayProps
): {
[key: string]: string | Date;
}[] => {
const dataArrayInProgress: { [key: string]: string | Date }[] = [];
props.rows.forEach((row) => {
if (row.workItemStatus === Status.inProgress) {
const rowObject: { [key: string]: string | Date } = {};
row.cells.forEach((cell) => {
rowObject[cell.key] = cell.value;
});
rowObject.link = row.workItemLink;
dataArrayInProgress.push(rowObject);
}
});
return dataArrayInProgress;
};
/**
* A component that when provided with work Item data, displays a work tray with the items split into "In Progress", "Completed" and "All Items"
*/
export const WorkTray = (props: WorkTrayProps): React.ReactElement => {
const columnsArray = props.columns.map((column) => ({
Header: column.name,
accessor: column.key,
sortType: column.sortType,
}));
const dueDateWarningArray: string[] = [];
props.columns.map((column) => {
if (column.dueDateWarning === true) {
dueDateWarningArray.push(column.key);
}
});
const columns: {
Header: string;
accessor: string;
sortType: string;
}[] = React.useMemo(() => columnsArray, [columnsArray]);
const dataArrayInProgress: {
[key: string]: string | Date;
}[] = mapInProgressData(props);
const dataInProgress = React.useMemo(() => dataArrayInProgress, [
dataArrayInProgress,
]);
const dataArrayCompleted: {
[key: string]: string | Date;
}[] = mapCompletedData(props);
const dataCompleted = React.useMemo(() => dataArrayCompleted, [
dataArrayCompleted,
]);
const dataArrayAll: { [key: string]: string | Date }[] = mapAllData(props);
const dataAll = React.useMemo(() => dataArrayAll, [dataArrayAll]);
return (
<div className="worktray-container" data-test="worktray-container">
<FilterTabs tabTitles={["In progress", "Due / Completed", "All items"]}>
<Table
columns={columns}
data={dataInProgress}
dueDateWarning={dueDateWarningArray}
/>
<Table
columns={columns}
data={dataCompleted}
dueDateWarning={dueDateWarningArray}
/>
<Table
columns={columns}
data={dataAll}
dueDateWarning={dueDateWarningArray}
/>
</FilterTabs>
</div>
);
};