dce-reactkit 3.9.4-beta.1 → 3.9.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.
@@ -48,25 +48,33 @@ export declare const confirm: (title: string, text: string, opts?: {
48
48
  * Show a prompt modal asking the user for input
49
49
  * @author Yuen Ler Chow
50
50
  * @param title the title text to display at the top of the prompt
51
- * @param text the text to display in the prompt
52
51
  * @param [opts={}] additional options for the prompt dialog
53
- * @param [opts.placeholder] the placeholder text for the input field
52
+ * @param [opts.textAboveInputField] the text to display in the prompt
54
53
  * @param [opts.defaultText] the default text for the input field
54
+ * @param [opts.placeholder] the placeholder text for the input field
55
55
  * @param [opts.confirmButtonText=Okay] the text of the confirm button
56
56
  * @param [opts.confirmButtonVariant=Variant.Dark] the variant of the confirm button
57
57
  * @param [opts.cancelButtonText=Cancel] the text of the cancel button
58
58
  * @param [opts.cancelButtonVariant=Variant.Secondary] the variant of the cancel button
59
+ * @param [opts.minNumChars] the minimum number of characters required for
60
+ * the input to be valid
61
+ * @param [opts.findValidationError] a function that takes the input text and
62
+ * returns an error message if the input is invalid, returns undefined if the
63
+ * input is valid
64
+ * @param [opts.ariaLabel] the aria label for the input field
59
65
  * @returns Promise that resolves with the input string or null if canceled
60
66
  */
61
- export declare const prompt: (title: string, text: string, currentInputFieldText: string, opts?: {
62
- placeholder?: string | undefined;
67
+ export declare const prompt: (title: string, opts?: {
68
+ textAboveInputField?: string | undefined;
63
69
  defaultText?: string | undefined;
70
+ placeholder?: string | undefined;
64
71
  confirmButtonText?: string | undefined;
65
72
  confirmButtonVariant?: Variant | undefined;
66
73
  cancelButtonText?: string | undefined;
67
74
  cancelButtonVariant?: Variant | undefined;
68
75
  minNumChars?: number | undefined;
69
76
  findValidationError?: ((text: string) => string | undefined) | undefined;
77
+ ariaLabel?: string | undefined;
70
78
  } | undefined) => Promise<string | null>;
71
79
  /**
72
80
  * Show a fatal error message
@@ -1,4 +1,4 @@
1
- import AppWrapper, { alert, confirm, showFatalError, addFatalErrorHandler, leaveToURL } from './components/AppWrapper';
1
+ import AppWrapper, { alert, prompt, confirm, showFatalError, addFatalErrorHandler, leaveToURL } from './components/AppWrapper';
2
2
  import LoadingSpinner from './components/LoadingSpinner';
3
3
  import ErrorBox from './components/ErrorBox';
4
4
  import Modal from './components/Modal';
@@ -99,4 +99,4 @@ import PickableItem from './components/ItemPicker/types/PickableItem';
99
99
  import DBEntry from './components/DBEntryManagerPanel/types/DBEntry';
100
100
  import DBEntryField from './components/DBEntryManagerPanel/types/DBEntryField';
101
101
  import DBEntryFieldType from './components/DBEntryManagerPanel/types/DBEntryFieldType';
102
- export { AppWrapper, LoadingSpinner, ErrorBox, Modal, TabBox, RadioButton, CheckboxButton, ButtonInputGroup, SimpleDateChooser, Drawer, PopSuccessMark, PopFailureMark, PopPendingMark, CopiableBox, ItemPicker, LogReviewer, IntelliTable, CSVDownloadButton, DBEntryManagerPanel, Tooltip, ToggleSwitch, AutoscrollToBottomContainer, MultiSwitch, Dropdown, alert, confirm, showFatalError, ErrorWithCode, MINUTE_IN_MS, HOUR_IN_MS, DAY_IN_MS, 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, initClient, visitServerEndpoint, logClientEvent, addFatalErrorHandler, leaveToURL, combineClassNames, useForceRender, setClientEventMetadataPopulator, initServer, genRouteHandler, handleError, handleSuccess, initLogCollection, addDBEditorEndpoints, visitEndpointOnAnotherServer, ModalButtonType, ModalSize, ModalType, ReactKitErrorCode, Variant, DayOfWeek, Log, LogType, LogSource, LogAction, LogBuiltInMetadata, LogMetadataType, LogFunction, IntelliTableColumn, DropdownItemType, PickableItem, DBEntry, DBEntryField, DBEntryFieldType, ParamType, };
102
+ export { AppWrapper, LoadingSpinner, ErrorBox, Modal, TabBox, RadioButton, CheckboxButton, ButtonInputGroup, SimpleDateChooser, 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, 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, initClient, visitServerEndpoint, logClientEvent, addFatalErrorHandler, leaveToURL, combineClassNames, useForceRender, setClientEventMetadataPopulator, initServer, genRouteHandler, handleError, handleSuccess, initLogCollection, addDBEditorEndpoints, visitEndpointOnAnotherServer, ModalButtonType, ModalSize, ModalType, ReactKitErrorCode, Variant, DayOfWeek, Log, LogType, LogSource, LogAction, LogBuiltInMetadata, LogMetadataType, LogFunction, IntelliTableColumn, DropdownItemType, PickableItem, DBEntry, DBEntryField, DBEntryFieldType, ParamType, };
package/dist/esm/index.js CHANGED
@@ -1060,6 +1060,87 @@ const confirm = (title, text, opts) => __awaiter(void 0, void 0, void 0, functio
1060
1060
  /*----------------------------------------*/
1061
1061
  // Stored copies of setters
1062
1062
  let setPromptInfo;
1063
+ // Function to call when prompt is closed
1064
+ let onPromptClosed;
1065
+ /**
1066
+ * Show a prompt modal asking the user for input
1067
+ * @author Yuen Ler Chow
1068
+ * @param title the title text to display at the top of the prompt
1069
+ * @param [opts={}] additional options for the prompt dialog
1070
+ * @param [opts.textAboveInputField] the text to display in the prompt
1071
+ * @param [opts.defaultText] the default text for the input field
1072
+ * @param [opts.placeholder] the placeholder text for the input field
1073
+ * @param [opts.confirmButtonText=Okay] the text of the confirm button
1074
+ * @param [opts.confirmButtonVariant=Variant.Dark] the variant of the confirm button
1075
+ * @param [opts.cancelButtonText=Cancel] the text of the cancel button
1076
+ * @param [opts.cancelButtonVariant=Variant.Secondary] the variant of the cancel button
1077
+ * @param [opts.minNumChars] the minimum number of characters required for
1078
+ * the input to be valid
1079
+ * @param [opts.findValidationError] a function that takes the input text and
1080
+ * returns an error message if the input is invalid, returns undefined if the
1081
+ * input is valid
1082
+ * @param [opts.ariaLabel] the aria label for the input field
1083
+ * @returns Promise that resolves with the input string or null if canceled
1084
+ */
1085
+ const prompt = (title, opts) => __awaiter(void 0, void 0, void 0, function* () {
1086
+ var _a, _b;
1087
+ // Wait for helper to exist
1088
+ yield waitForHelper(() => {
1089
+ return !!setPromptInfo;
1090
+ });
1091
+ // Fallback if prompt is not available
1092
+ if (!setPromptInfo) {
1093
+ const resultPassesValidation = false;
1094
+ while (!resultPassesValidation) {
1095
+ // eslint-disable-next-line no-alert
1096
+ const result = window.prompt(`${title}\n\n${(_a = opts === null || opts === void 0 ? void 0 : opts.textAboveInputField) !== null && _a !== void 0 ? _a : ''}`, (_b = opts === null || opts === void 0 ? void 0 : opts.defaultText) !== null && _b !== void 0 ? _b : '');
1097
+ // Exit loop if user cancels
1098
+ if (result === null) {
1099
+ return null;
1100
+ }
1101
+ // Validate min num chars
1102
+ const minNumCharsValidationError = (((opts === null || opts === void 0 ? void 0 : opts.minNumChars) && result.length < opts.minNumChars)
1103
+ ? `Please enter at least ${opts.minNumChars} characters.`
1104
+ : undefined);
1105
+ // Run custom validation
1106
+ const customValidationError = ((opts === null || opts === void 0 ? void 0 : opts.findValidationError)
1107
+ && opts.findValidationError(result));
1108
+ // Show validation issue
1109
+ if (minNumCharsValidationError || customValidationError) {
1110
+ // Create error message
1111
+ const errorMessage = ([
1112
+ minNumCharsValidationError,
1113
+ customValidationError,
1114
+ ]
1115
+ // Filter out undefined messages
1116
+ .filter((msg) => {
1117
+ return !!msg;
1118
+ })
1119
+ // Join messages with newlines
1120
+ .join('\n'));
1121
+ // Show alert
1122
+ alert('Invalid Input', errorMessage);
1123
+ }
1124
+ else {
1125
+ return result;
1126
+ }
1127
+ }
1128
+ }
1129
+ // Return promise that resolves with result of prompt
1130
+ return new Promise((resolve) => {
1131
+ var _a;
1132
+ // Setup handler
1133
+ onPromptClosed = (result) => {
1134
+ resolve(result);
1135
+ };
1136
+ // Show the prompt
1137
+ setPromptInfo({
1138
+ title,
1139
+ currentInputFieldText: ((_a = opts === null || opts === void 0 ? void 0 : opts.defaultText) !== null && _a !== void 0 ? _a : ''),
1140
+ opts: (opts !== null && opts !== void 0 ? opts : {}),
1141
+ });
1142
+ });
1143
+ });
1063
1144
  /*----------------------------------------*/
1064
1145
  /* ------------- Fatal Error ------------ */
1065
1146
  /*----------------------------------------*/
@@ -1076,14 +1157,14 @@ const fatalErrorHandlers = [];
1076
1157
  * @param [errorTitle] title of the error box
1077
1158
  */
1078
1159
  const showFatalError = (error, errorTitle = 'An Error Occurred') => __awaiter(void 0, void 0, void 0, function* () {
1079
- var _b, _c;
1160
+ var _c, _d;
1080
1161
  // Determine message and code
1081
1162
  const message = (typeof error === 'string'
1082
1163
  ? error.trim()
1083
- : String((_b = error.message) !== null && _b !== void 0 ? _b : 'An unknown error occurred.'));
1164
+ : String((_c = error.message) !== null && _c !== void 0 ? _c : 'An unknown error occurred.'));
1084
1165
  const code = (typeof error === 'string'
1085
1166
  ? ReactKitErrorCode$1.NoCode
1086
- : String((_c = error.code) !== null && _c !== void 0 ? _c : ReactKitErrorCode$1.NoCode));
1167
+ : String((_d = error.code) !== null && _d !== void 0 ? _d : ReactKitErrorCode$1.NoCode));
1087
1168
  // Call all fatal error listeners
1088
1169
  try {
1089
1170
  fatalErrorHandlers.forEach((handler) => {
@@ -1253,23 +1334,31 @@ const AppWrapper = (props) => {
1253
1334
  // Run custom validation
1254
1335
  const customValidationError = (promptInfo.opts.findValidationError
1255
1336
  && promptInfo.opts.findValidationError(promptInfo.currentInputFieldText));
1256
- modal = (React__default.createElement(Modal, { key: `prompt-${promptInfo.title}-${promptInfo.text}`, title: promptInfo.title,
1257
- // only show the cancel button if there is a validation error
1337
+ modal = (React__default.createElement(Modal, { key: `prompt-${promptInfo.title}`, title: promptInfo.title,
1338
+ // Don't show ok button if there is a validation error
1258
1339
  type: ((customValidationError || minNumCharsValidationError)
1259
1340
  ? ModalType$1.Cancel
1260
1341
  : ModalType$1.OkayCancel), okayLabel: promptInfo.opts.confirmButtonText, okayVariant: promptInfo.opts.confirmButtonVariant, cancelLabel: promptInfo.opts.cancelButtonText, cancelVariant: promptInfo.opts.cancelButtonVariant, onClose: (buttonType) => {
1261
- (buttonType === ModalButtonType$1.Okay
1342
+ // Get result
1343
+ const result = (buttonType === ModalButtonType$1.Okay
1262
1344
  ? promptInfo.currentInputFieldText
1263
1345
  : null);
1346
+ // Close prompt
1264
1347
  setPromptInfo(undefined);
1348
+ // Call handler
1349
+ if (onPromptClosed) {
1350
+ onPromptClosed(result);
1351
+ }
1265
1352
  }, onTopOfOtherModals: true, dontAllowBackdropExit: true },
1266
- React__default.createElement("div", { className: "d-flex flex-column align-items-center" },
1267
- React__default.createElement("p", null, promptInfo.text),
1268
- React__default.createElement("input", { type: "text", placeholder: promptInfo.opts.placeholder, value: promptInfo.currentInputFieldText, onChange: (e) => {
1353
+ React__default.createElement("div", null,
1354
+ promptInfo.opts.textAboveInputField && (React__default.createElement("div", null, promptInfo.opts.textAboveInputField)),
1355
+ React__default.createElement("input", { type: "text", className: "form-control", "aria-label": promptInfo.opts.ariaLabel, placeholder: promptInfo.opts.placeholder, value: promptInfo.currentInputFieldText, onChange: (e) => {
1269
1356
  return setPromptInfo(Object.assign(Object.assign({}, promptInfo), { currentInputFieldText: e.target.value }));
1270
- } }),
1271
- minNumCharsValidationError && (React__default.createElement("div", { className: "text-danger bg-danger bg-opacity-25 p-2 m-1 rounded" }, minNumCharsValidationError)),
1272
- customValidationError && (React__default.createElement("div", { className: "text-danger bg-danger bg-opacity-25 p-2 m-1 rounded" }, customValidationError)))));
1357
+ },
1358
+ // eslint-disable-next-line jsx-a11y/no-autofocus
1359
+ autoFocus: true }),
1360
+ minNumCharsValidationError && (React__default.createElement("div", { className: "text-danger fw-bold mt-2" }, minNumCharsValidationError)),
1361
+ customValidationError && (React__default.createElement("div", { className: "text-danger fw-bold mt-2" }, customValidationError)))));
1273
1362
  }
1274
1363
  /* ------ Custom Modal Portals ------ */
1275
1364
  // Custom modal portals
@@ -3803,10 +3892,21 @@ const LogReviewer = (props) => {
3803
3892
  // Destructure
3804
3893
  const { year, month } = toLoad[i];
3805
3894
  // Load
3806
- const logs = yield visitServerEndpoint({
3807
- path: `${LOG_REVIEW_ROUTE_PATH_PREFIX}/years/${year}/months/${month}`,
3808
- method: 'GET',
3809
- });
3895
+ let logs = [];
3896
+ let pageNumber = 1;
3897
+ let hasAnotherPage = true;
3898
+ while (hasAnotherPage) {
3899
+ const response = yield visitServerEndpoint({
3900
+ path: `${LOG_REVIEW_ROUTE_PATH_PREFIX}/years/${year}/months/${month}`,
3901
+ method: 'GET',
3902
+ params: {
3903
+ pageNumber,
3904
+ },
3905
+ });
3906
+ logs = logs.concat(response.items);
3907
+ hasAnotherPage = response.hasAnotherPage;
3908
+ pageNumber += 1;
3909
+ }
3810
3910
  // Add to map
3811
3911
  if (!logMap[year]) {
3812
3912
  logMap[year] = {};
@@ -14066,22 +14166,27 @@ const initServer = (opts) => {
14066
14166
  paramTypes: {
14067
14167
  year: ParamType$1.Int,
14068
14168
  month: ParamType$1.Int,
14169
+ pageNumber: ParamType$1.Int,
14069
14170
  },
14070
14171
  handler: ({ params }) => __awaiter(void 0, void 0, void 0, function* () {
14071
14172
  // Get user info
14072
- const { year, month, userId, isAdmin, } = params;
14173
+ const { year, month, pageNumber, userId, isAdmin, } = params;
14073
14174
  // Validate user
14074
14175
  const canReview = yield canReviewLogs(userId, isAdmin);
14075
14176
  if (!canReview) {
14076
14177
  throw new ErrorWithCode('You cannot access this resource because you do not have the appropriate permissions.', ReactKitErrorCode$1.NotAllowedToReviewLogs);
14077
14178
  }
14078
14179
  // Query for logs
14079
- const logs = yield _logCollection.find({
14080
- year,
14081
- month,
14180
+ const response = yield _logCollection.findPaged({
14181
+ query: {
14182
+ year,
14183
+ month,
14184
+ },
14185
+ perPage: 1000,
14186
+ pageNumber,
14082
14187
  });
14083
- // Return logs
14084
- return logs;
14188
+ // Return response
14189
+ return response;
14085
14190
  }),
14086
14191
  }));
14087
14192
  };
@@ -15312,6 +15417,11 @@ const initLogCollection = (Collection) => {
15312
15417
  'context',
15313
15418
  'subcontext',
15314
15419
  'tags',
15420
+ 'year',
15421
+ 'month',
15422
+ 'day',
15423
+ 'hour',
15424
+ 'type',
15315
15425
  ],
15316
15426
  });
15317
15427
  };
@@ -16249,5 +16359,5 @@ var DayOfWeek;
16249
16359
  })(DayOfWeek || (DayOfWeek = {}));
16250
16360
  var DayOfWeek$1 = DayOfWeek;
16251
16361
 
16252
- export { AppWrapper, AutoscrollToBottomContainer, ButtonInputGroup, CSVDownloadButton, CheckboxButton, CopiableBox, DAY_IN_MS, DBEntryFieldType$1 as DBEntryFieldType, DBEntryManagerPanel, DayOfWeek$1 as DayOfWeek, Drawer, Dropdown, DropdownItemType$1 as DropdownItemType, DynamicWord, ErrorBox, ErrorWithCode, HOUR_IN_MS, IntelliTable, ItemPicker, LoadingSpinner, LogAction$1 as LogAction, LogBuiltInMetadata, LogReviewer, LogSource$1 as LogSource, LogType$1 as LogType, MINUTE_IN_MS, Modal, ModalButtonType$1 as ModalButtonType, ModalSize$1 as ModalSize, ModalType$1 as ModalType, MultiSwitch, ParamType$1 as ParamType, PopFailureMark, PopPendingMark, PopSuccessMark, RadioButton, ReactKitErrorCode$1 as ReactKitErrorCode, SimpleDateChooser, TabBox, ToggleSwitch, Tooltip, Variant$1 as Variant, abbreviate, addDBEditorEndpoints, addFatalErrorHandler, alert, avg, canReviewLogs, capitalize, ceilToNumDecimals, combineClassNames, compareArraysByProp, confirm, everyAsync, extractProp, filterAsync, floorToNumDecimals, forEachAsync, forceNumIntoBounds, genCSV, genCommaList, genRouteHandler, getHumanReadableDate, getLocalTimeInfo, getMonthName, getOrdinal, getPartOfDay, getTimeInfoInET, handleError, handleSuccess, idify, initClient, initLogCollection, initServer, isMobileOrTablet, leaveToURL, logClientEvent, makeLinksClickable, mapAsync, onlyKeepLetters, padDecimalZeros, padZerosLeft, parallelLimit, prefixWithAOrAn, roundToNumDecimals, setClientEventMetadataPopulator, showFatalError, shuffleArray, someAsync, startMinWait, stringsToHumanReadableList, stubServerEndpoint, sum, useForceRender, validateEmail, validatePhoneNumber, validateString, visitEndpointOnAnotherServer, visitServerEndpoint, waitMs };
16362
+ export { AppWrapper, AutoscrollToBottomContainer, ButtonInputGroup, CSVDownloadButton, CheckboxButton, CopiableBox, DAY_IN_MS, DBEntryFieldType$1 as DBEntryFieldType, DBEntryManagerPanel, DayOfWeek$1 as DayOfWeek, Drawer, Dropdown, DropdownItemType$1 as DropdownItemType, DynamicWord, ErrorBox, ErrorWithCode, HOUR_IN_MS, IntelliTable, ItemPicker, LoadingSpinner, LogAction$1 as LogAction, LogBuiltInMetadata, LogReviewer, LogSource$1 as LogSource, LogType$1 as LogType, MINUTE_IN_MS, Modal, ModalButtonType$1 as ModalButtonType, ModalSize$1 as ModalSize, ModalType$1 as ModalType, MultiSwitch, ParamType$1 as ParamType, PopFailureMark, PopPendingMark, PopSuccessMark, RadioButton, ReactKitErrorCode$1 as ReactKitErrorCode, SimpleDateChooser, TabBox, ToggleSwitch, Tooltip, Variant$1 as Variant, abbreviate, addDBEditorEndpoints, addFatalErrorHandler, alert, avg, canReviewLogs, capitalize, ceilToNumDecimals, combineClassNames, compareArraysByProp, confirm, everyAsync, extractProp, filterAsync, floorToNumDecimals, forEachAsync, forceNumIntoBounds, genCSV, genCommaList, genRouteHandler, getHumanReadableDate, getLocalTimeInfo, getMonthName, getOrdinal, getPartOfDay, getTimeInfoInET, handleError, handleSuccess, idify, initClient, initLogCollection, initServer, isMobileOrTablet, leaveToURL, logClientEvent, makeLinksClickable, mapAsync, onlyKeepLetters, padDecimalZeros, padZerosLeft, parallelLimit, prefixWithAOrAn, prompt, roundToNumDecimals, setClientEventMetadataPopulator, showFatalError, shuffleArray, someAsync, startMinWait, stringsToHumanReadableList, stubServerEndpoint, sum, useForceRender, validateEmail, validatePhoneNumber, validateString, visitEndpointOnAnotherServer, visitServerEndpoint, waitMs };
16253
16363
  //# sourceMappingURL=index.js.map