dce-reactkit 4.2.0-beta-select-admin-check.2 → 4.2.1

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.
@@ -20,6 +20,7 @@ type Props = {
20
20
  numMonthsToShow?: number;
21
21
  dontAllowPast?: boolean;
22
22
  dontAllowFuture?: boolean;
23
+ isDisabled?: boolean;
23
24
  };
24
25
  declare const SimpleDateChooser: React.FC<Props>;
25
26
  export default SimpleDateChooser;
@@ -15,6 +15,7 @@ type Props = {
15
15
  */
16
16
  onChange: (hour: number, minute: number) => void;
17
17
  intervalMin?: number;
18
+ isDisabled?: boolean;
18
19
  };
19
20
  declare const SimpleTimeChooser: React.FC<Props>;
20
21
  export default SimpleTimeChooser;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Checks if the current user is a select admin
3
+ * @author Gardenia Liu
4
+ * @returns true if the user is a select admin, false otherwise
5
+ */
6
+ declare const isSelectAdmin: () => Promise<boolean>;
7
+ export default isSelectAdmin;
@@ -81,6 +81,7 @@ import shuffleArray from './helpers/shuffleArray';
81
81
  import getWordCount from './helpers/getWordCount';
82
82
  import cloneDeep from './helpers/cloneDeep';
83
83
  import getTimestampFromTimeInfoInET from './helpers/getTimestampFromTimeInfoInET';
84
+ import isSelectAdmin from './helpers/isSelectAdmin';
84
85
  import ParamType from './types/ParamType';
85
86
  import ModalButtonType from './types/ModalButtonType';
86
87
  import ModalSize from './types/ModalSize';
@@ -106,4 +107,4 @@ import PickableItem from './components/ItemPicker/types/PickableItem';
106
107
  import DBEntry from './components/DBEntryManagerPanel/types/DBEntry';
107
108
  import DBEntryField from './components/DBEntryManagerPanel/types/DBEntryField';
108
109
  import DBEntryFieldType from './components/DBEntryManagerPanel/types/DBEntryFieldType';
109
- 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, SELECT_ADMIN_CHECK_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, };
110
+ 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, SELECT_ADMIN_CHECK_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, isSelectAdmin, 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, };
@@ -22,6 +22,8 @@ declare enum LogAction {
22
22
  Resume = "Resume",
23
23
  Jump = "Jump",
24
24
  Post = "Post",
25
+ Like = "Like",
26
+ Dislike = "Dislike",
25
27
  Unknown = "Unknown"
26
28
  }
27
29
  export default LogAction;
package/dist/index.d.ts CHANGED
@@ -316,6 +316,7 @@ type Props$g = {
316
316
  numMonthsToShow?: number;
317
317
  dontAllowPast?: boolean;
318
318
  dontAllowFuture?: boolean;
319
+ isDisabled?: boolean;
319
320
  };
320
321
  declare const SimpleDateChooser: React$1.FC<Props$g>;
321
322
 
@@ -336,6 +337,7 @@ type Props$f = {
336
337
  */
337
338
  onChange: (hour: number, minute: number) => void;
338
339
  intervalMin?: number;
340
+ isDisabled?: boolean;
339
341
  };
340
342
  declare const SimpleTimeChooser: React$1.FC<Props$f>;
341
343
 
@@ -1183,6 +1185,8 @@ declare enum LogAction {
1183
1185
  Resume = "Resume",
1184
1186
  Jump = "Jump",
1185
1187
  Post = "Post",
1188
+ Like = "Like",
1189
+ Dislike = "Dislike",
1186
1190
  Unknown = "Unknown"
1187
1191
  }
1188
1192
 
@@ -1580,6 +1584,13 @@ declare const getTimestampFromTimeInfoInET: (opts: {
1580
1584
  minute: number;
1581
1585
  }) => number;
1582
1586
 
1587
+ /**
1588
+ * Checks if the current user is a select admin
1589
+ * @author Gardenia Liu
1590
+ * @returns true if the user is a select admin, false otherwise
1591
+ */
1592
+ declare const isSelectAdmin: () => Promise<boolean>;
1593
+
1583
1594
  /**
1584
1595
  * Days of the week
1585
1596
  * @author Gabe Abrams
@@ -1707,4 +1718,4 @@ type LogReviewerFilterState = {
1707
1718
  advancedFilterState: AdvancedFilterState;
1708
1719
  };
1709
1720
 
1710
- 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, SELECT_ADMIN_CHECK_ROUTE, 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 };
1721
+ 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, SELECT_ADMIN_CHECK_ROUTE, 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, isSelectAdmin, 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.2.0-beta-select-admin-check.2",
3
+ "version": "4.2.1",
4
4
  "description": "Shared components for Harvard DCE apps",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -51,6 +51,8 @@ type Props = {
51
51
  dontAllowPast?: boolean,
52
52
  // If true, the user isn't allowed to select dates in the future
53
53
  dontAllowFuture?: boolean,
54
+ // If true, the chooser is disabled
55
+ isDisabled?: boolean,
54
56
  };
55
57
 
56
58
  /*------------------------------------------------------------------------*/
@@ -291,6 +293,7 @@ const SimpleDateChooser: React.FC<Props> = (props) => {
291
293
  month,
292
294
  day,
293
295
  year,
296
+ isDisabled = false,
294
297
  } = props;
295
298
 
296
299
  // Get choices
@@ -435,6 +438,7 @@ const SimpleDateChooser: React.FC<Props> = (props) => {
435
438
  choice.year,
436
439
  );
437
440
  }}
441
+ disabled={isDisabled}
438
442
  >
439
443
  {monthOptions}
440
444
  </select>
@@ -454,6 +458,7 @@ const SimpleDateChooser: React.FC<Props> = (props) => {
454
458
  year,
455
459
  );
456
460
  }}
461
+ disabled={isDisabled}
457
462
  >
458
463
  {dayOptions}
459
464
  </select>
@@ -32,6 +32,8 @@ type Props = {
32
32
  // Allowed options: 15, 30, 60, defaults to 15
33
33
  // If an unsupported interval is passed in, it will default to 15
34
34
  intervalMin?: number,
35
+ // If true, the chooser is disabled
36
+ isDisabled?: boolean,
35
37
  };
36
38
 
37
39
  /*------------------------------------------------------------------------*/
@@ -61,6 +63,7 @@ const SimpleTimeChooser: React.FC<Props> = (props) => {
61
63
  hour,
62
64
  minute,
63
65
  onChange,
66
+ isDisabled = false,
64
67
  } = props;
65
68
  let {
66
69
  intervalMin = DEFAULT_INTERVAL,
@@ -181,6 +184,7 @@ const SimpleTimeChooser: React.FC<Props> = (props) => {
181
184
  // Notify parent
182
185
  onChange(timeInfo.hours, timeInfo.minutes);
183
186
  }}
187
+ disabled={isDisabled}
184
188
  >
185
189
  {timeOptions}
186
190
  </select>
@@ -0,0 +1,48 @@
1
+ // Import shared constants
2
+ import SELECT_ADMIN_CHECK_ROUTE from '../constants/SELECT_ADMIN_CHECK_ROUTE';
3
+
4
+ // Import shared helpers
5
+ import visitServerEndpoint from './visitServerEndpoint';
6
+
7
+ /*------------------------------------------------------------------------*/
8
+ /* ------------------------------- Caching ------------------------------ */
9
+ /*------------------------------------------------------------------------*/
10
+
11
+ // If true, user is a select admin
12
+ let cachedUserIsSelectAdmin: boolean | undefined;
13
+
14
+ /*------------------------------------------------------------------------*/
15
+ /* -------------------------------- Main -------------------------------- */
16
+ /*------------------------------------------------------------------------*/
17
+
18
+ /**
19
+ * Checks if the current user is a select admin
20
+ * @author Gardenia Liu
21
+ * @returns true if the user is a select admin, false otherwise
22
+ */
23
+ const isSelectAdmin = async (): Promise<boolean> => {
24
+ // Use cached version if we have one
25
+ if (cachedUserIsSelectAdmin !== undefined) {
26
+ return cachedUserIsSelectAdmin;
27
+ }
28
+
29
+ // Check if the user is a select admin
30
+ try {
31
+ const userIsSelectAdmin: boolean = await visitServerEndpoint({
32
+ path: SELECT_ADMIN_CHECK_ROUTE,
33
+ method: 'GET',
34
+ });
35
+
36
+ // Cache the result
37
+ cachedUserIsSelectAdmin = !!userIsSelectAdmin;
38
+
39
+ // Return the result
40
+ return userIsSelectAdmin;
41
+ } catch (err) {
42
+ // Error means the user isn't a select admin
43
+ cachedUserIsSelectAdmin = false;
44
+ return false;
45
+ }
46
+ };
47
+
48
+ export default isSelectAdmin;
package/src/index.ts CHANGED
@@ -97,6 +97,7 @@ import shuffleArray from './helpers/shuffleArray';
97
97
  import getWordCount from './helpers/getWordCount';
98
98
  import cloneDeep from './helpers/cloneDeep';
99
99
  import getTimestampFromTimeInfoInET from './helpers/getTimestampFromTimeInfoInET';
100
+ import isSelectAdmin from './helpers/isSelectAdmin';
100
101
 
101
102
  // Import types
102
103
  import ParamType from './types/ParamType';
@@ -217,6 +218,7 @@ export {
217
218
  getWordCount,
218
219
  cloneDeep,
219
220
  getTimestampFromTimeInfoInET,
221
+ isSelectAdmin,
220
222
  // Client helpers
221
223
  initClient,
222
224
  visitServerEndpoint,
@@ -41,6 +41,10 @@ enum LogAction {
41
41
  Jump = 'Jump',
42
42
  // Post a submission/message/etc. into the target
43
43
  Post = 'Post',
44
+ // Like something
45
+ Like = 'Like',
46
+ // Dislike something
47
+ Dislike = 'Dislike',
44
48
  // Unknown action
45
49
  Unknown = 'Unknown',
46
50
  }