@@ -21,8 +21,8 @@ export const timeDifferenceInMinutes = (first: Date | null, second: Date | null)
21
21
return Math . round ( difference / 60000 ) ;
22
22
} ;
23
23
24
- export const getActivityTableColumns = ( title : string , shouldShowCreatedBy : boolean ) => {
25
- return [
24
+ export const getActivityTableColumns = ( title : string , shouldShowCreatedBy : boolean , shouldShowHelpedBy : boolean ) => {
25
+ const baseTable = [
26
26
{
27
27
Header : title ,
28
28
columns : [
@@ -42,15 +42,6 @@ export const getActivityTableColumns = (title: string, shouldShowCreatedBy: bool
42
42
Header : 'Location' ,
43
43
accessor : 'locationName' ,
44
44
} ,
45
- shouldShowCreatedBy
46
- ? {
47
- Header : 'Created by' ,
48
- accessor : 'createdByName' ,
49
- }
50
- : {
51
- Header : 'Helped by' ,
52
- accessor : 'helpedByName' ,
53
- } ,
54
45
{
55
46
Header : 'Duration (m)' ,
56
47
accessor : 'duration' ,
@@ -62,6 +53,28 @@ export const getActivityTableColumns = (title: string, shouldShowCreatedBy: bool
62
53
] ,
63
54
} ,
64
55
] ;
56
+
57
+ // This isn't necessary, but it keeps typescript happy
58
+ if ( baseTable [ 0 ] === undefined ) {
59
+ throw new Error ( 'baseTable[0] is undefined' ) ;
60
+ }
61
+
62
+ // Add createdBy and/or helpedBy columns
63
+ if ( shouldShowCreatedBy ) {
64
+ baseTable [ 0 ] . columns . splice ( 4 , 0 , {
65
+ Header : 'Created By' ,
66
+ accessor : 'createdByName' ,
67
+ } ) ;
68
+ }
69
+
70
+ if ( shouldShowHelpedBy ) {
71
+ baseTable [ 0 ] . columns . splice ( 4 , 0 , {
72
+ Header : 'Helped By' ,
73
+ accessor : 'helpedByName' ,
74
+ } ) ;
75
+ }
76
+
77
+ return baseTable ;
65
78
} ;
66
79
67
80
export const addDurationToTickets = ( tickets : TicketWithNames [ ] ) => {
@@ -103,20 +116,20 @@ export type ImportUsersMethodPossiblitiesType = 'IMPORT_STAFF' | 'IMPORT_STAFF_A
103
116
104
117
export const resolveTime = ( t : TicketStats ) => {
105
118
if ( ! t . resolvedAt || ! t . createdAt ) {
106
- return 0 ;
119
+ return 0 ;
107
120
}
108
121
return Math . round ( ( ( t . resolvedAt . getTime ( ) - t . createdAt . getTime ( ) ) / 60000 ) * 1000 ) / 1000 ; // in minutes, 3 decimals
109
122
} ;
110
123
111
124
export const helpTime = ( t : TicketStats ) => {
112
125
if ( ! t . resolvedAt || ! t . helpedAt ) {
113
- return 0 ;
126
+ return 0 ;
114
127
}
115
128
return Math . round ( ( ( t . resolvedAt . getTime ( ) - t . helpedAt . getTime ( ) ) / 60000 ) * 1000 ) / 1000 ; // in minutes, 3 decimals
116
129
} ;
117
130
118
131
export const computeMean = ( data : number [ ] ) => {
119
- return data . length > 0 ? Math . round ( data . reduce ( ( a , b ) => a + b ) / data . length * 1000 ) / 1000 : 0 ;
132
+ return data . length > 0 ? Math . round ( ( data . reduce ( ( a , b ) => a + b ) / data . length ) * 1000 ) / 1000 : 0 ;
120
133
} ;
121
134
122
135
export const computeMedian = ( data : number [ ] ) => {
0 commit comments