dce-reactkit 3.2.2-beta.42 → 3.2.2-beta.46

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dce-reactkit",
3
- "version": "3.2.2-beta.42",
3
+ "version": "3.2.2-beta.46",
4
4
  "description": "Shared components for Harvard DCE apps",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -70,7 +70,7 @@ const CSVDownloadButton: React.FC<Props> = (props) => {
70
70
  <a
71
71
  id={id}
72
72
  download={filename}
73
- href={`data:application/octet-stream,${csv}`}
73
+ href={`data:application/octet-stream,${encodeURIComponent(csv)}`}
74
74
  className={`CSVDownloadButton-button ${className ?? 'btn btn-secondary'}`}
75
75
  aria-label={(
76
76
  ariaLabel
@@ -31,6 +31,7 @@ import ModalType from '../types/ModalType';
31
31
  import CheckboxButton from './CheckboxButton';
32
32
  import CSVDownloadButton from './CSVDownloadButton';
33
33
  import Variant from '../types/Variant';
34
+ import { alert } from './AppWrapper';
34
35
 
35
36
  /*------------------------------------------------------------------------*/
36
37
  /* Types */
@@ -92,6 +93,10 @@ enum ActionType {
92
93
  UpdateColumnVisibility = 'update-column-visibility',
93
94
  // Toggle the column visibility customization modal
94
95
  ToggleColVisCusModalVisibility = 'toggle-col-vis-cus-modal-visibility',
96
+ // Show all columns
97
+ ShowAllColumns = 'show-all-columns',
98
+ // Hide all columns
99
+ HideAllColumns = 'hide-all-columns',
95
100
  }
96
101
 
97
102
  // Action definitions
@@ -114,6 +119,8 @@ type Action = (
114
119
  // Action type
115
120
  type: (
116
121
  | ActionType.ToggleColVisCusModalVisibility
122
+ | ActionType.ShowAllColumns
123
+ | ActionType.HideAllColumns
117
124
  ),
118
125
  }
119
126
  );
@@ -163,6 +170,26 @@ const reducer = (state: State, action: Action): State => {
163
170
  columnVisibilityCustomizationModalVisible: !state.columnVisibilityCustomizationModalVisible,
164
171
  };
165
172
  }
173
+ case ActionType.ShowAllColumns: {
174
+ const { columnVisibilityMap } = state;
175
+ Object.keys(columnVisibilityMap).forEach((param) => {
176
+ columnVisibilityMap[param] = true;
177
+ });
178
+ return {
179
+ ...state,
180
+ columnVisibilityMap,
181
+ };
182
+ }
183
+ case ActionType.HideAllColumns: {
184
+ const { columnVisibilityMap } = state;
185
+ Object.keys(columnVisibilityMap).forEach((param) => {
186
+ columnVisibilityMap[param] = false;
187
+ });
188
+ return {
189
+ ...state,
190
+ columnVisibilityMap,
191
+ };
192
+ }
166
193
  default: {
167
194
  return state;
168
195
  }
@@ -251,12 +278,25 @@ const IntelliTable: React.FC<Props> = (props) => {
251
278
  type={ModalType.Okay}
252
279
  title="Choose columns to show:"
253
280
  onClose={() => {
281
+ const noColumnsSelected = (
282
+ Object.values(columnVisibilityMap)
283
+ .every((isSelected) => {
284
+ return !isSelected;
285
+ })
286
+ );
287
+ if (noColumnsSelected) {
288
+ return alert(
289
+ 'Choose at least one column',
290
+ 'To continue, you have to choose at least one column to show'
291
+ );
292
+ }
254
293
  dispatch({
255
294
  type: ActionType.ToggleColVisCusModalVisibility,
256
295
  });
257
296
  }}
258
297
  okayVariant={Variant.Light}
259
298
  >
299
+ {/* Columns */}
260
300
  {
261
301
  columns.map((column) => {
262
302
  return (
@@ -273,13 +313,42 @@ const IntelliTable: React.FC<Props> = (props) => {
273
313
  });
274
314
  }}
275
315
  checked={columnVisibilityMap[column.param]}
276
- ariaLabel={`show "${column.title}" column`}
316
+ ariaLabel={`show "${column.title}" column in the ${title} table`}
277
317
  checkedVariant={Variant.Light}
278
318
  uncheckedVariant={Variant.Secondary}
279
319
  />
280
320
  );
281
321
  })
282
322
  }
323
+ <div className="mt-3">
324
+ Or you can:
325
+ </div>
326
+ <button
327
+ type="button"
328
+ id={`IntelliTable-${id}-select-all-columns`}
329
+ className="btn btn-secondary me-2"
330
+ aria-label={`show all columns in the ${title} table`}
331
+ onClick={() => {
332
+ dispatch({
333
+ type: ActionType.ShowAllColumns,
334
+ });
335
+ }}
336
+ >
337
+ Select All
338
+ </button>
339
+ <button
340
+ type="button"
341
+ id={`IntelliTable-${id}-select-none-columns`}
342
+ className="btn btn-secondary"
343
+ aria-label={`hide all columns in the ${title} table`}
344
+ onClick={() => {
345
+ dispatch({
346
+ type: ActionType.HideAllColumns,
347
+ });
348
+ }}
349
+ >
350
+ Deselect All
351
+ </button >
283
352
  </Modal>
284
353
  );
285
354
  }
@@ -625,7 +694,9 @@ const IntelliTable: React.FC<Props> = (props) => {
625
694
  // Build CSV
626
695
  const csv = genCSV(
627
696
  data,
628
- columns,
697
+ columns.filter((column) => {
698
+ return columnVisibilityMap[column.param];
699
+ }),
629
700
  );
630
701
 
631
702
  // Build main UI
@@ -645,7 +716,7 @@ const IntelliTable: React.FC<Props> = (props) => {
645
716
  <CSVDownloadButton
646
717
  aria-label={`download data as csv for ${title}`}
647
718
  id={`IntelliTable-${id}-download-as-csv`}
648
- filename={`${title}.csv`}
719
+ filename={filename}
649
720
  csv={csv}
650
721
  />
651
722
  {/* Show/Hide Columns */}
@@ -262,6 +262,197 @@ const style = `
262
262
  }
263
263
  `;
264
264
 
265
+ /*------------------------------------------------------------------------*/
266
+ /* Constants */
267
+ /*------------------------------------------------------------------------*/
268
+
269
+ const columns: IntelliTableColumn[] = [
270
+ {
271
+ title: 'First Name',
272
+ param: 'userFirstName',
273
+ type: ParamType.String,
274
+ },
275
+ {
276
+ title: 'Last Name',
277
+ param: 'userLastName',
278
+ type: ParamType.String,
279
+ },
280
+ {
281
+ title: 'Email',
282
+ param: 'userEmail',
283
+ type: ParamType.String,
284
+ },
285
+ {
286
+ title: 'Canvas Id',
287
+ param: 'userId',
288
+ type: ParamType.Int,
289
+ },
290
+ {
291
+ title: 'Student?',
292
+ param: 'isLearner',
293
+ type: ParamType.Boolean,
294
+ },
295
+ {
296
+ title: 'Teaching Staff?',
297
+ param: 'isTTM',
298
+ type: ParamType.Boolean,
299
+ startsHidden: true,
300
+ },
301
+ {
302
+ title: 'Admin?',
303
+ param: 'isAdmin',
304
+ type: ParamType.Boolean,
305
+ startsHidden: true,
306
+ },
307
+ {
308
+ title: 'Course Canvas Id',
309
+ param: 'courseId',
310
+ type: ParamType.Int,
311
+ startsHidden: true,
312
+ },
313
+ {
314
+ title: 'Course Name',
315
+ param: 'courseName',
316
+ type: ParamType.String,
317
+ },
318
+ {
319
+ title: 'Browser Name',
320
+ param: 'browser.name',
321
+ type: ParamType.String,
322
+ startsHidden: true,
323
+ },
324
+ {
325
+ title: 'Browser Version',
326
+ param: 'browser.version',
327
+ type: ParamType.String,
328
+ startsHidden: true,
329
+ },
330
+ {
331
+ title: 'OS',
332
+ param: 'device.os',
333
+ type: ParamType.String,
334
+ startsHidden: true,
335
+ },
336
+ {
337
+ title: 'Mobile?',
338
+ param: 'device.isMobile',
339
+ type: ParamType.Boolean,
340
+ startsHidden: true,
341
+ },
342
+ {
343
+ title: 'Year',
344
+ param: 'year',
345
+ type: ParamType.Int,
346
+ },
347
+ {
348
+ title: 'Month',
349
+ param: 'month',
350
+ type: ParamType.Int,
351
+ },
352
+ {
353
+ title: 'Day',
354
+ param: 'day',
355
+ type: ParamType.Int,
356
+ },
357
+ {
358
+ title: 'Hour',
359
+ param: 'hour',
360
+ type: ParamType.Int,
361
+ },
362
+ {
363
+ title: 'Minute',
364
+ param: 'minute',
365
+ type: ParamType.Int,
366
+ startsHidden: true,
367
+ },
368
+ {
369
+ title: 'Timestamp',
370
+ param: 'timestamp',
371
+ type: ParamType.Int,
372
+ startsHidden: true,
373
+ },
374
+ {
375
+ title: 'Context',
376
+ param: 'context',
377
+ type: ParamType.String,
378
+ },
379
+ {
380
+ title: 'Subcontext',
381
+ param: 'subcontext',
382
+ type: ParamType.String,
383
+ },
384
+ {
385
+ title: 'Tags',
386
+ param: 'tags',
387
+ type: ParamType.JSON,
388
+ startsHidden: true,
389
+ },
390
+ {
391
+ title: 'Log Level',
392
+ param: 'level',
393
+ type: ParamType.String,
394
+ startsHidden: true,
395
+ },
396
+ {
397
+ title: 'Metadata',
398
+ param: 'metadata',
399
+ type: ParamType.JSON,
400
+ startsHidden: true,
401
+ },
402
+ {
403
+ title: 'Source',
404
+ param: 'source',
405
+ type: ParamType.String,
406
+ },
407
+ {
408
+ title: 'Server Route Path',
409
+ param: 'routePath',
410
+ type: ParamType.String,
411
+ startsHidden: true,
412
+ },
413
+ {
414
+ title: 'Server Route Template',
415
+ param: 'routeTemplate',
416
+ type: ParamType.String,
417
+ startsHidden: true,
418
+ },
419
+ {
420
+ title: 'Type',
421
+ param: 'type',
422
+ type: ParamType.String,
423
+ },
424
+ {
425
+ title: 'Error Message',
426
+ param: 'errorMessage',
427
+ type: ParamType.String,
428
+ startsHidden: true,
429
+ },
430
+ {
431
+ title: 'Error Code',
432
+ param: 'errorCode',
433
+ type: ParamType.String,
434
+ startsHidden: true,
435
+ },
436
+ {
437
+ title: 'Error Stack',
438
+ param: 'errorStack',
439
+ type: ParamType.String,
440
+ startsHidden: true,
441
+ },
442
+ {
443
+ title: 'Action Target',
444
+ param: 'target',
445
+ type: ParamType.String,
446
+ startsHidden: true,
447
+ },
448
+ {
449
+ title: 'Action Type',
450
+ param: 'action',
451
+ type: ParamType.String,
452
+ startsHidden: true,
453
+ },
454
+ ];
455
+
265
456
  /*------------------------------------------------------------------------*/
266
457
  /* Static Functions */
267
458
  /*------------------------------------------------------------------------*/
@@ -1942,194 +2133,6 @@ const LogReviewer: React.FC<Props> = (props) => {
1942
2133
  /* Data */
1943
2134
  /*----------------------------------------*/
1944
2135
 
1945
- // Create data table
1946
- const columns: IntelliTableColumn[] = [
1947
- {
1948
- title: 'First Name',
1949
- param: 'userFirstName',
1950
- type: ParamType.String,
1951
- },
1952
- {
1953
- title: 'Last Name',
1954
- param: 'userLastName',
1955
- type: ParamType.String,
1956
- },
1957
- {
1958
- title: 'Email',
1959
- param: 'userEmail',
1960
- type: ParamType.String,
1961
- },
1962
- {
1963
- title: 'Canvas Id',
1964
- param: 'userId',
1965
- type: ParamType.Int,
1966
- },
1967
- {
1968
- title: 'Student?',
1969
- param: 'isLearner',
1970
- type: ParamType.Boolean,
1971
- },
1972
- {
1973
- title: 'Teaching Staff?',
1974
- param: 'isTTM',
1975
- type: ParamType.Boolean,
1976
- startsHidden: true,
1977
- },
1978
- {
1979
- title: 'Admin?',
1980
- param: 'isAdmin',
1981
- type: ParamType.Boolean,
1982
- startsHidden: true,
1983
- },
1984
- {
1985
- title: 'Course Canvas Id',
1986
- param: 'courseId',
1987
- type: ParamType.Int,
1988
- startsHidden: true,
1989
- },
1990
- {
1991
- title: 'Course Name',
1992
- param: 'courseName',
1993
- type: ParamType.String,
1994
- },
1995
- {
1996
- title: 'Browser Name',
1997
- param: 'browser.name',
1998
- type: ParamType.String,
1999
- startsHidden: true,
2000
- },
2001
- {
2002
- title: 'Browser Version',
2003
- param: 'browser.version',
2004
- type: ParamType.String,
2005
- startsHidden: true,
2006
- },
2007
- {
2008
- title: 'OS',
2009
- param: 'device.os',
2010
- type: ParamType.String,
2011
- startsHidden: true,
2012
- },
2013
- {
2014
- title: 'Mobile?',
2015
- param: 'device.isMobile',
2016
- type: ParamType.Boolean,
2017
- startsHidden: true,
2018
- },
2019
- {
2020
- title: 'Year',
2021
- param: 'year',
2022
- type: ParamType.Int,
2023
- },
2024
- {
2025
- title: 'Month',
2026
- param: 'month',
2027
- type: ParamType.Int,
2028
- },
2029
- {
2030
- title: 'Day',
2031
- param: 'day',
2032
- type: ParamType.Int,
2033
- },
2034
- {
2035
- title: 'Hour',
2036
- param: 'hour',
2037
- type: ParamType.Int,
2038
- },
2039
- {
2040
- title: 'Minute',
2041
- param: 'minute',
2042
- type: ParamType.Int,
2043
- startsHidden: true,
2044
- },
2045
- {
2046
- title: 'Timestamp',
2047
- param: 'timestamp',
2048
- type: ParamType.Int,
2049
- startsHidden: true,
2050
- },
2051
- {
2052
- title: 'Context',
2053
- param: 'context',
2054
- type: ParamType.String,
2055
- },
2056
- {
2057
- title: 'Subcontext',
2058
- param: 'subcontext',
2059
- type: ParamType.String,
2060
- },
2061
- {
2062
- title: 'Tags',
2063
- param: 'tags',
2064
- type: ParamType.JSON,
2065
- startsHidden: true,
2066
- },
2067
- {
2068
- title: 'Log Level',
2069
- param: 'level',
2070
- type: ParamType.String,
2071
- startsHidden: true,
2072
- },
2073
- {
2074
- title: 'Metadata',
2075
- param: 'metadata',
2076
- type: ParamType.JSON,
2077
- startsHidden: true,
2078
- },
2079
- {
2080
- title: 'Source',
2081
- param: 'source',
2082
- type: ParamType.String,
2083
- },
2084
- {
2085
- title: 'Server Route Path',
2086
- param: 'routePath',
2087
- type: ParamType.String,
2088
- startsHidden: true,
2089
- },
2090
- {
2091
- title: 'Server Route Template',
2092
- param: 'routeTemplate',
2093
- type: ParamType.String,
2094
- startsHidden: true,
2095
- },
2096
- {
2097
- title: 'Type',
2098
- param: 'type',
2099
- type: ParamType.String,
2100
- },
2101
- {
2102
- title: 'Error Message',
2103
- param: 'errorMessage',
2104
- type: ParamType.String,
2105
- startsHidden: true,
2106
- },
2107
- {
2108
- title: 'Error Code',
2109
- param: 'errorCode',
2110
- type: ParamType.String,
2111
- startsHidden: true,
2112
- },
2113
- {
2114
- title: 'Error Stack',
2115
- param: 'errorStack',
2116
- type: ParamType.String,
2117
- startsHidden: true,
2118
- },
2119
- {
2120
- title: 'Action Target',
2121
- param: 'target',
2122
- type: ParamType.String,
2123
- startsHidden: true,
2124
- },
2125
- {
2126
- title: 'Action Type',
2127
- param: 'action',
2128
- type: ParamType.String,
2129
- startsHidden: true,
2130
- },
2131
- ];
2132
-
2133
2136
  // Nothing to show notice
2134
2137
  const noLogsNotice = (
2135
2138
  logs.length === 0