dce-reactkit 4.1.3 → 4.1.5

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.
@@ -6,6 +6,7 @@ import React from 'react';
6
6
  type Props = {
7
7
  filename: string;
8
8
  csv: string;
9
+ label?: string;
9
10
  id?: string;
10
11
  className?: string;
11
12
  ariaLabel?: string;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Get a timestamp (ms since epoch) from time info (year, month, day, hour, minute, etc.) in Eastern Time (ET)
3
+ * @author Gardenia Liu
4
+ * @author Gabe Abrams
5
+ * @param opts object containing all arguments
6
+ * @param opts.year Year (e.g. 2023)
7
+ * @param opts.month Month (1-12)
8
+ * @param opts.day Day of the month (1-31)
9
+ * @param opts.hour Hour (0-23)
10
+ * @param opts.minute Minute (0-59))
11
+ * @returns Timestamp in milliseconds since epoch
12
+ */
13
+ declare const getTimestampFromTimeInfoInET: (opts: {
14
+ year: number;
15
+ month: number;
16
+ day: number;
17
+ hour: number;
18
+ minute: number;
19
+ }) => number;
20
+ export default getTimestampFromTimeInfoInET;
@@ -79,6 +79,7 @@ import capitalize from './helpers/capitalize';
79
79
  import shuffleArray from './helpers/shuffleArray';
80
80
  import getWordCount from './helpers/getWordCount';
81
81
  import cloneDeep from './helpers/cloneDeep';
82
+ import getTimestampFromTimeInfoInET from './helpers/getTimestampFromTimeInfoInET';
82
83
  import ParamType from './types/ParamType';
83
84
  import ModalButtonType from './types/ModalButtonType';
84
85
  import ModalSize from './types/ModalSize';
@@ -104,4 +105,4 @@ import PickableItem from './components/ItemPicker/types/PickableItem';
104
105
  import DBEntry from './components/DBEntryManagerPanel/types/DBEntry';
105
106
  import DBEntryField from './components/DBEntryManagerPanel/types/DBEntryField';
106
107
  import DBEntryFieldType from './components/DBEntryManagerPanel/types/DBEntryFieldType';
107
- export { AppWrapper, LoadingSpinner, ErrorBox, Modal, TabBox, RadioButton, CheckboxButton, ButtonInputGroup, SimpleDateChooser, SimpleTimeChooser, Drawer, PopSuccessMark, PopFailureMark, PopPendingMark, CopiableBox, ItemPicker, LogReviewer, IntelliTable, CSVDownloadButton, DBEntryManagerPanel, Tooltip, ToggleSwitch, AutoscrollToBottomContainer, MultiSwitch, Dropdown, alert, prompt, confirm, showFatalError, ErrorWithCode, MINUTE_IN_MS, HOUR_IN_MS, DAY_IN_MS, LOG_REVIEW_ROUTE_PATH_PREFIX, LOG_ROUTE_PATH, LOG_REVIEW_STATUS_ROUTE, LOG_REVIEW_GET_LOGS_ROUTE, DynamicWord, abbreviate, avg, ceilToNumDecimals, floorToNumDecimals, forceNumIntoBounds, padDecimalZeros, padZerosLeft, roundToNumDecimals, sum, waitMs, getOrdinal, getTimeInfoInET, stubServerEndpoint, startMinWait, getHumanReadableDate, getPartOfDay, stringsToHumanReadableList, onlyKeepLetters, parallelLimit, getMonthName, genCSV, canReviewLogs, isMobileOrTablet, extractProp, compareArraysByProp, genCommaList, validateEmail, validatePhoneNumber, validateString, getLocalTimeInfo, idify, makeLinksClickable, prefixWithAOrAn, everyAsync, filterAsync, forEachAsync, mapAsync, someAsync, capitalize, shuffleArray, getWordCount, cloneDeep, initClient, visitServerEndpoint, logClientEvent, addFatalErrorHandler, leaveToURL, combineClassNames, useForceRender, setClientEventMetadataPopulator, ParamType, ModalButtonType, ModalSize, ModalType, ReactKitErrorCode, Variant, DayOfWeek, Log, LogType, LogSource, LogAction, LogBuiltInMetadata, LogMetadataType, LogFunction, LogTypeSpecificInfo, LogMainInfo, LogSourceSpecificInfo, LogLevel, IntelliTableColumn, DropdownItemType, LogReviewerFilterState, PickableItem, DBEntry, DBEntryField, DBEntryFieldType, };
108
+ export { AppWrapper, LoadingSpinner, ErrorBox, Modal, TabBox, RadioButton, CheckboxButton, ButtonInputGroup, SimpleDateChooser, SimpleTimeChooser, Drawer, PopSuccessMark, PopFailureMark, PopPendingMark, CopiableBox, ItemPicker, LogReviewer, IntelliTable, CSVDownloadButton, DBEntryManagerPanel, Tooltip, ToggleSwitch, AutoscrollToBottomContainer, MultiSwitch, Dropdown, alert, prompt, confirm, showFatalError, ErrorWithCode, MINUTE_IN_MS, HOUR_IN_MS, DAY_IN_MS, LOG_REVIEW_ROUTE_PATH_PREFIX, LOG_ROUTE_PATH, LOG_REVIEW_STATUS_ROUTE, LOG_REVIEW_GET_LOGS_ROUTE, DynamicWord, abbreviate, avg, ceilToNumDecimals, floorToNumDecimals, forceNumIntoBounds, padDecimalZeros, padZerosLeft, roundToNumDecimals, sum, waitMs, getOrdinal, getTimeInfoInET, stubServerEndpoint, startMinWait, getHumanReadableDate, getPartOfDay, stringsToHumanReadableList, onlyKeepLetters, parallelLimit, getMonthName, genCSV, canReviewLogs, isMobileOrTablet, extractProp, compareArraysByProp, genCommaList, validateEmail, validatePhoneNumber, validateString, getLocalTimeInfo, idify, makeLinksClickable, prefixWithAOrAn, everyAsync, filterAsync, forEachAsync, mapAsync, someAsync, capitalize, shuffleArray, getWordCount, cloneDeep, getTimestampFromTimeInfoInET, initClient, visitServerEndpoint, logClientEvent, addFatalErrorHandler, leaveToURL, combineClassNames, useForceRender, setClientEventMetadataPopulator, ParamType, ModalButtonType, ModalSize, ModalType, ReactKitErrorCode, Variant, DayOfWeek, Log, LogType, LogSource, LogAction, LogBuiltInMetadata, LogMetadataType, LogFunction, LogTypeSpecificInfo, LogMainInfo, LogSourceSpecificInfo, LogLevel, IntelliTableColumn, DropdownItemType, LogReviewerFilterState, PickableItem, DBEntry, DBEntryField, DBEntryFieldType, };
@@ -8,6 +8,7 @@ declare enum ReactKitErrorCode {
8
8
  SessionExpired = "DRK3",
9
9
  NoCACCLSendRequestFunction = "DRK7",
10
10
  SimpleDateChooserInvalidDateRange = "DRK35",
11
- SimpleDateChooserInvalidNumMonths = "DRK36"
11
+ SimpleDateChooserInvalidNumMonths = "DRK36",
12
+ ETTimestampInvalid = "DRK37"
12
13
  }
13
14
  export default ReactKitErrorCode;
package/dist/index.d.ts CHANGED
@@ -543,6 +543,7 @@ declare const IntelliTable: React$1.FC<Props$7>;
543
543
  type Props$6 = {
544
544
  filename: string;
545
545
  csv: string;
546
+ label?: string;
546
547
  id?: string;
547
548
  className?: string;
548
549
  ariaLabel?: string;
@@ -1553,6 +1554,26 @@ declare const getWordCount: (text: string) => number;
1553
1554
  */
1554
1555
  declare const cloneDeep: <T>(obj: T) => T;
1555
1556
 
1557
+ /**
1558
+ * Get a timestamp (ms since epoch) from time info (year, month, day, hour, minute, etc.) in Eastern Time (ET)
1559
+ * @author Gardenia Liu
1560
+ * @author Gabe Abrams
1561
+ * @param opts object containing all arguments
1562
+ * @param opts.year Year (e.g. 2023)
1563
+ * @param opts.month Month (1-12)
1564
+ * @param opts.day Day of the month (1-31)
1565
+ * @param opts.hour Hour (0-23)
1566
+ * @param opts.minute Minute (0-59))
1567
+ * @returns Timestamp in milliseconds since epoch
1568
+ */
1569
+ declare const getTimestampFromTimeInfoInET: (opts: {
1570
+ year: number;
1571
+ month: number;
1572
+ day: number;
1573
+ hour: number;
1574
+ minute: number;
1575
+ }) => number;
1576
+
1556
1577
  /**
1557
1578
  * Days of the week
1558
1579
  * @author Gabe Abrams
@@ -1593,7 +1614,8 @@ declare enum ReactKitErrorCode {
1593
1614
  SessionExpired = "DRK3",
1594
1615
  NoCACCLSendRequestFunction = "DRK7",
1595
1616
  SimpleDateChooserInvalidDateRange = "DRK35",
1596
- SimpleDateChooserInvalidNumMonths = "DRK36"
1617
+ SimpleDateChooserInvalidNumMonths = "DRK36",
1618
+ ETTimestampInvalid = "DRK37"
1597
1619
  }
1598
1620
 
1599
1621
  /**
@@ -1679,4 +1701,4 @@ type LogReviewerFilterState = {
1679
1701
  advancedFilterState: AdvancedFilterState;
1680
1702
  };
1681
1703
 
1682
- export { AppWrapper, AutoscrollToBottomContainer, ButtonInputGroup, CSVDownloadButton, CheckboxButton, CopiableBox, DAY_IN_MS, DBEntry, DBEntryField, DBEntryFieldType, DBEntryManagerPanel, DayOfWeek, Drawer, Dropdown, DropdownItemType, DynamicWord, ErrorBox, ErrorWithCode, HOUR_IN_MS, IntelliTable, IntelliTableColumn, ItemPicker, LOG_REVIEW_GET_LOGS_ROUTE, LOG_REVIEW_ROUTE_PATH_PREFIX, LOG_REVIEW_STATUS_ROUTE, LOG_ROUTE_PATH, LoadingSpinner, Log, LogAction, LogBuiltInMetadata, LogFunction, LogLevel, LogMainInfo, LogMetadataType, LogReviewer, LogReviewerFilterState, LogSource, LogSourceSpecificInfo, LogType, LogTypeSpecificInfo, MINUTE_IN_MS, Modal, ModalButtonType, ModalSize, ModalType, MultiSwitch, ParamType, PickableItem, PopFailureMark, PopPendingMark, PopSuccessMark, RadioButton, ReactKitErrorCode, SimpleDateChooser, SimpleTimeChooser, TabBox, ToggleSwitch, Tooltip, Variant, abbreviate, addFatalErrorHandler, alert, avg, canReviewLogs, capitalize, ceilToNumDecimals, cloneDeep, combineClassNames, compareArraysByProp, confirm, everyAsync, extractProp, filterAsync, floorToNumDecimals, forEachAsync, forceNumIntoBounds, genCSV, genCommaList, getHumanReadableDate, getLocalTimeInfo, getMonthName, getOrdinal, getPartOfDay, getTimeInfoInET, getWordCount, idify, initClient, isMobileOrTablet, leaveToURL, logClientEvent, makeLinksClickable, mapAsync, onlyKeepLetters, padDecimalZeros, padZerosLeft, parallelLimit, prefixWithAOrAn, prompt, roundToNumDecimals, setClientEventMetadataPopulator, showFatalError, shuffleArray, someAsync, startMinWait, stringsToHumanReadableList, stubServerEndpoint, sum, useForceRender, validateEmail, validatePhoneNumber, validateString, visitServerEndpoint, waitMs };
1704
+ export { AppWrapper, AutoscrollToBottomContainer, ButtonInputGroup, CSVDownloadButton, CheckboxButton, CopiableBox, DAY_IN_MS, DBEntry, DBEntryField, DBEntryFieldType, DBEntryManagerPanel, DayOfWeek, Drawer, Dropdown, DropdownItemType, DynamicWord, ErrorBox, ErrorWithCode, HOUR_IN_MS, IntelliTable, IntelliTableColumn, ItemPicker, LOG_REVIEW_GET_LOGS_ROUTE, LOG_REVIEW_ROUTE_PATH_PREFIX, LOG_REVIEW_STATUS_ROUTE, LOG_ROUTE_PATH, LoadingSpinner, Log, LogAction, LogBuiltInMetadata, LogFunction, LogLevel, LogMainInfo, LogMetadataType, LogReviewer, LogReviewerFilterState, LogSource, LogSourceSpecificInfo, LogType, LogTypeSpecificInfo, MINUTE_IN_MS, Modal, ModalButtonType, ModalSize, ModalType, MultiSwitch, ParamType, PickableItem, PopFailureMark, PopPendingMark, PopSuccessMark, RadioButton, ReactKitErrorCode, SimpleDateChooser, SimpleTimeChooser, TabBox, ToggleSwitch, Tooltip, Variant, abbreviate, addFatalErrorHandler, alert, avg, canReviewLogs, capitalize, ceilToNumDecimals, cloneDeep, combineClassNames, compareArraysByProp, confirm, everyAsync, extractProp, filterAsync, floorToNumDecimals, forEachAsync, forceNumIntoBounds, genCSV, genCommaList, getHumanReadableDate, getLocalTimeInfo, getMonthName, getOrdinal, getPartOfDay, getTimeInfoInET, getTimestampFromTimeInfoInET, getWordCount, idify, initClient, isMobileOrTablet, leaveToURL, logClientEvent, makeLinksClickable, mapAsync, onlyKeepLetters, padDecimalZeros, padZerosLeft, parallelLimit, prefixWithAOrAn, prompt, roundToNumDecimals, setClientEventMetadataPopulator, showFatalError, shuffleArray, someAsync, startMinWait, stringsToHumanReadableList, stubServerEndpoint, sum, useForceRender, validateEmail, validatePhoneNumber, validateString, visitServerEndpoint, waitMs };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dce-reactkit",
3
- "version": "4.1.3",
3
+ "version": "4.1.5",
4
4
  "description": "Shared components for Harvard DCE apps",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -20,6 +20,8 @@ type Props = {
20
20
  filename: string,
21
21
  // The contents of the CSV file to download
22
22
  csv: string,
23
+ // Label for the button
24
+ label?: string,
23
25
  // Id of the button
24
26
  id?: string,
25
27
  // Class name of the button
@@ -55,6 +57,7 @@ const CSVDownloadButton: React.FC<Props> = (props) => {
55
57
  style,
56
58
  onClick,
57
59
  children,
60
+ label = 'Download CSV',
58
61
  } = props;
59
62
 
60
63
  /*------------------------------------------------------------------------*/
@@ -86,7 +89,7 @@ const CSVDownloadButton: React.FC<Props> = (props) => {
86
89
  icon={faCloudDownloadAlt}
87
90
  />
88
91
  {' '}
89
- Download CSV
92
+ {label}
90
93
  </>
91
94
  )}
92
95
  {children}
@@ -59,6 +59,7 @@ const genCSV = (
59
59
  if (
60
60
  typeof cell === 'string'
61
61
  || typeof cell === 'number'
62
+ || typeof cell === 'boolean'
62
63
  ) {
63
64
  contents = String(cell);
64
65
  } else if (cell === null) {
@@ -0,0 +1,74 @@
1
+ // Import shared types
2
+ import ErrorWithCode from '../errors/ErrorWithCode';
3
+ import ReactKitErrorCode from '../types/ReactKitErrorCode';
4
+
5
+ // Import shared helpers
6
+ import getTimeInfoInET from './getTimeInfoInET';
7
+ import padZerosLeft from './padZerosLeft';
8
+
9
+ /**
10
+ * Get a timestamp (ms since epoch) from time info (year, month, day, hour, minute, etc.) in Eastern Time (ET)
11
+ * @author Gardenia Liu
12
+ * @author Gabe Abrams
13
+ * @param opts object containing all arguments
14
+ * @param opts.year Year (e.g. 2023)
15
+ * @param opts.month Month (1-12)
16
+ * @param opts.day Day of the month (1-31)
17
+ * @param opts.hour Hour (0-23)
18
+ * @param opts.minute Minute (0-59))
19
+ * @returns Timestamp in milliseconds since epoch
20
+ */
21
+ const getTimestampFromTimeInfoInET = (
22
+ opts: {
23
+ year: number,
24
+ month: number,
25
+ day: number,
26
+ hour: number,
27
+ minute: number,
28
+ },
29
+ ): number => {
30
+ // Destructure opts
31
+ const {
32
+ year,
33
+ month,
34
+ day,
35
+ hour,
36
+ minute,
37
+ } = opts;
38
+
39
+ // Determine if the date is in DST in Eastern Time
40
+ const tempDate = new Date(year, month - 1, day);
41
+ const janOffset = new Date(year, 0, 1).getTimezoneOffset();
42
+ const isDST = tempDate.getTimezoneOffset() < janOffset;
43
+ const etOffset = isDST ? '-04:00' : '-05:00';
44
+
45
+ // Format with leading zeroes
46
+ const mm = padZerosLeft(month, 2);
47
+ const dd = padZerosLeft(day, 2);
48
+ const hh = padZerosLeft(hour, 2);
49
+ const min = padZerosLeft(minute, 2);
50
+
51
+ // Build ET ISO string and convert to UTC timestamp
52
+ const etISOString = `${year}-${mm}-${dd}T${hh}:${min}:00${etOffset}`;
53
+ const timestamp = (new Date(etISOString)).getTime();
54
+
55
+ // Verify that the timestamp is correct
56
+ const timeInfoInET = getTimeInfoInET(timestamp);
57
+ if (
58
+ timeInfoInET.year !== year
59
+ || timeInfoInET.month !== month
60
+ || timeInfoInET.day !== day
61
+ || timeInfoInET.hour !== hour
62
+ || timeInfoInET.minute !== minute
63
+ ) {
64
+ throw new ErrorWithCode(
65
+ `Timestamp mismatch: expected ${year}-${mm}-${dd} ${hh}:${min}, got ${timeInfoInET.year}-${padZerosLeft(timeInfoInET.month, 2)}-${padZerosLeft(timeInfoInET.day, 2)} ${padZerosLeft(timeInfoInET.hour, 2)}:${padZerosLeft(timeInfoInET.minute, 2)}`,
66
+ ReactKitErrorCode.ETTimestampInvalid,
67
+ );
68
+ }
69
+
70
+ // Valid! Return the timestamp
71
+ return timestamp;
72
+ };
73
+
74
+ export default getTimestampFromTimeInfoInET;
package/src/index.ts CHANGED
@@ -95,6 +95,7 @@ import capitalize from './helpers/capitalize';
95
95
  import shuffleArray from './helpers/shuffleArray';
96
96
  import getWordCount from './helpers/getWordCount';
97
97
  import cloneDeep from './helpers/cloneDeep';
98
+ import getTimestampFromTimeInfoInET from './helpers/getTimestampFromTimeInfoInET';
98
99
 
99
100
  // Import types
100
101
  import ParamType from './types/ParamType';
@@ -213,6 +214,7 @@ export {
213
214
  shuffleArray,
214
215
  getWordCount,
215
216
  cloneDeep,
217
+ getTimestampFromTimeInfoInET,
216
218
  // Client helpers
217
219
  initClient,
218
220
  visitServerEndpoint,
@@ -1,4 +1,4 @@
1
- // Highest error code = DRK36
1
+ // Highest error code = DRK37
2
2
 
3
3
  /**
4
4
  * List of error codes built into the react kit
@@ -11,6 +11,7 @@ enum ReactKitErrorCode {
11
11
  NoCACCLSendRequestFunction = 'DRK7',
12
12
  SimpleDateChooserInvalidDateRange = 'DRK35',
13
13
  SimpleDateChooserInvalidNumMonths = 'DRK36',
14
+ ETTimestampInvalid = 'DRK37',
14
15
  }
15
16
 
16
17
  export default ReactKitErrorCode;