dce-reactkit 3.9.4-beta-logreviewer.1 → 3.9.4-beta-prompt.2

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.
@@ -44,6 +44,30 @@ export declare const confirm: (title: string, text: string, opts?: {
44
44
  cancelButtonText?: string;
45
45
  cancelButtonVariant?: Variant;
46
46
  }) => Promise<boolean>;
47
+ /**
48
+ * Show a prompt modal asking the user for input
49
+ * @author Yuen Ler Chow
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
+ * @param [opts={}] additional options for the prompt dialog
53
+ * @param [opts.placeholder] the placeholder text for the input field
54
+ * @param [opts.defaultText] the default text for the input field
55
+ * @param [opts.confirmButtonText=Okay] the text of the confirm button
56
+ * @param [opts.confirmButtonVariant=Variant.Dark] the variant of the confirm button
57
+ * @param [opts.cancelButtonText=Cancel] the text of the cancel button
58
+ * @param [opts.cancelButtonVariant=Variant.Secondary] the variant of the cancel button
59
+ * @returns Promise that resolves with the input string or null if canceled
60
+ */
61
+ export declare const prompt: (title: string, text: string, opts?: {
62
+ defaultText?: string | undefined;
63
+ placeholder?: string | undefined;
64
+ confirmButtonText?: string | undefined;
65
+ confirmButtonVariant?: Variant | undefined;
66
+ cancelButtonText?: string | undefined;
67
+ cancelButtonVariant?: Variant | undefined;
68
+ minNumChars?: number | undefined;
69
+ findValidationError?: ((text: string) => string | undefined) | undefined;
70
+ } | undefined) => Promise<string | null>;
47
71
  /**
48
72
  * Show a fatal error message
49
73
  * @author Gabe Abrams
@@ -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, };
@@ -4,6 +4,7 @@
4
4
  */
5
5
  declare enum ModalType {
6
6
  Okay = "okay",
7
+ Cancel = "cancel",
7
8
  OkayCancel = "okay-cancel",
8
9
  YesNo = "yes-no",
9
10
  YesNoCancel = "yes-no-cancel",
package/dist/esm/index.js CHANGED
@@ -158,6 +158,7 @@ var ModalButtonType$1 = ModalButtonType;
158
158
  var ModalType;
159
159
  (function (ModalType) {
160
160
  ModalType["Okay"] = "okay";
161
+ ModalType["Cancel"] = "cancel";
161
162
  ModalType["OkayCancel"] = "okay-cancel";
162
163
  ModalType["YesNo"] = "yes-no";
163
164
  ModalType["YesNoCancel"] = "yes-no-cancel";
@@ -312,6 +313,9 @@ const modalTypeToModalButtonTypes = {
312
313
  [ModalType$1.Okay]: [
313
314
  ModalButtonType$1.Okay,
314
315
  ],
316
+ [ModalType$1.Cancel]: [
317
+ ModalButtonType$1.Cancel,
318
+ ],
315
319
  [ModalType$1.OkayCancel]: [
316
320
  ModalButtonType$1.Okay,
317
321
  ModalButtonType$1.Cancel,
@@ -1052,6 +1056,74 @@ const confirm = (title, text, opts) => __awaiter(void 0, void 0, void 0, functio
1052
1056
  });
1053
1057
  });
1054
1058
  /*----------------------------------------*/
1059
+ /* --------------- Prompt -------------- */
1060
+ /*----------------------------------------*/
1061
+ // Stored copies of setters
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 text the text to display in the prompt
1070
+ * @param [opts={}] additional options for the prompt dialog
1071
+ * @param [opts.placeholder] the placeholder text for the input field
1072
+ * @param [opts.defaultText] the default 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
+ * @returns Promise that resolves with the input string or null if canceled
1078
+ */
1079
+ const prompt = (title, text, opts) => __awaiter(void 0, void 0, void 0, function* () {
1080
+ var _a;
1081
+ // Wait for helper to exist
1082
+ yield waitForHelper(() => {
1083
+ return !!setPromptInfo;
1084
+ });
1085
+ // Fallback if prompt is not available
1086
+ if (!setPromptInfo) {
1087
+ const resultPassesValidation = false;
1088
+ while (!resultPassesValidation) {
1089
+ // eslint-disable-next-line no-alert
1090
+ const result = window.prompt(`${title}\n\n${text}`, (_a = opts === null || opts === void 0 ? void 0 : opts.defaultText) !== null && _a !== void 0 ? _a : '');
1091
+ if (result === null) {
1092
+ return null;
1093
+ }
1094
+ // Validate min num chars
1095
+ const minNumCharsValidationError = (((opts === null || opts === void 0 ? void 0 : opts.minNumChars) && result.length < opts.minNumChars)
1096
+ ? `Please enter at least ${opts.minNumChars} characters.`
1097
+ : undefined);
1098
+ // Run custom validation
1099
+ const customValidationError = ((opts === null || opts === void 0 ? void 0 : opts.findValidationError)
1100
+ && opts.findValidationError(result));
1101
+ // Show validation issue
1102
+ if (minNumCharsValidationError || customValidationError) {
1103
+ alert('Invalid Input', `${minNumCharsValidationError !== null && minNumCharsValidationError !== void 0 ? minNumCharsValidationError : ''} ${customValidationError !== null && customValidationError !== void 0 ? customValidationError : ''}`);
1104
+ }
1105
+ else {
1106
+ return result;
1107
+ }
1108
+ }
1109
+ }
1110
+ // Return promise that resolves with result of prompt
1111
+ return new Promise((resolve) => {
1112
+ var _a;
1113
+ // Setup handler
1114
+ onPromptClosed = (result) => {
1115
+ resolve(result);
1116
+ };
1117
+ // Show the prompt
1118
+ setPromptInfo({
1119
+ title,
1120
+ text,
1121
+ currentInputFieldText: ((_a = opts === null || opts === void 0 ? void 0 : opts.defaultText) !== null && _a !== void 0 ? _a : ''),
1122
+ opts: (opts !== null && opts !== void 0 ? opts : {}),
1123
+ });
1124
+ });
1125
+ });
1126
+ /*----------------------------------------*/
1055
1127
  /* ------------- Fatal Error ------------ */
1056
1128
  /*----------------------------------------*/
1057
1129
  // Stored copies of setters
@@ -1067,14 +1139,14 @@ const fatalErrorHandlers = [];
1067
1139
  * @param [errorTitle] title of the error box
1068
1140
  */
1069
1141
  const showFatalError = (error, errorTitle = 'An Error Occurred') => __awaiter(void 0, void 0, void 0, function* () {
1070
- var _a, _b;
1142
+ var _b, _c;
1071
1143
  // Determine message and code
1072
1144
  const message = (typeof error === 'string'
1073
1145
  ? error.trim()
1074
- : String((_a = error.message) !== null && _a !== void 0 ? _a : 'An unknown error occurred.'));
1146
+ : String((_b = error.message) !== null && _b !== void 0 ? _b : 'An unknown error occurred.'));
1075
1147
  const code = (typeof error === 'string'
1076
1148
  ? ReactKitErrorCode$1.NoCode
1077
- : String((_b = error.code) !== null && _b !== void 0 ? _b : ReactKitErrorCode$1.NoCode));
1149
+ : String((_c = error.code) !== null && _c !== void 0 ? _c : ReactKitErrorCode$1.NoCode));
1078
1150
  // Call all fatal error listeners
1079
1151
  try {
1080
1152
  fatalErrorHandlers.forEach((handler) => {
@@ -1201,6 +1273,9 @@ const AppWrapper = (props) => {
1201
1273
  // Confirm
1202
1274
  const [confirmInfo, setConfirmInfoInner,] = useState(undefined);
1203
1275
  setConfirmInfo = setConfirmInfoInner;
1276
+ // Prompt
1277
+ const [promptInfo, setPromptInfoInner] = useState(undefined);
1278
+ setPromptInfo = setPromptInfoInner;
1204
1279
  // Session expired
1205
1280
  const [sessionHasExpired, setSessionHasExpiredInner,] = useState(false);
1206
1281
  setSessionHasExpired = setSessionHasExpiredInner;
@@ -1231,6 +1306,37 @@ const AppWrapper = (props) => {
1231
1306
  }
1232
1307
  }, onTopOfOtherModals: true, dontAllowBackdropExit: true }, confirmInfo.text));
1233
1308
  }
1309
+ /* ------------- Prompt ------------ */
1310
+ if (promptInfo) {
1311
+ // Run min char validation
1312
+ const minNumCharsValidationError = ((promptInfo.opts.minNumChars
1313
+ && promptInfo.currentInputFieldText.length < promptInfo.opts.minNumChars)
1314
+ ? `Please enter at least ${promptInfo.opts.minNumChars} characters.`
1315
+ : undefined);
1316
+ // Run custom validation
1317
+ const customValidationError = (promptInfo.opts.findValidationError
1318
+ && promptInfo.opts.findValidationError(promptInfo.currentInputFieldText));
1319
+ modal = (React__default.createElement(Modal, { key: `prompt-${promptInfo.title}-${promptInfo.text}`, title: promptInfo.title,
1320
+ // Don't show ok button if there is a validation error
1321
+ type: ((customValidationError || minNumCharsValidationError)
1322
+ ? ModalType$1.Cancel
1323
+ : ModalType$1.OkayCancel), okayLabel: promptInfo.opts.confirmButtonText, okayVariant: promptInfo.opts.confirmButtonVariant, cancelLabel: promptInfo.opts.cancelButtonText, cancelVariant: promptInfo.opts.cancelButtonVariant, onClose: (buttonType) => {
1324
+ const result = (buttonType === ModalButtonType$1.Okay
1325
+ ? promptInfo.currentInputFieldText
1326
+ : null);
1327
+ setPromptInfo(undefined);
1328
+ if (onPromptClosed) {
1329
+ onPromptClosed(result);
1330
+ }
1331
+ }, onTopOfOtherModals: true, dontAllowBackdropExit: true },
1332
+ React__default.createElement("div", { className: "p-3" },
1333
+ React__default.createElement("p", null, promptInfo.text),
1334
+ React__default.createElement("input", { type: "text", className: "form-control mb-2", placeholder: promptInfo.opts.placeholder, value: promptInfo.currentInputFieldText, onChange: (e) => {
1335
+ return setPromptInfo(Object.assign(Object.assign({}, promptInfo), { currentInputFieldText: e.target.value }));
1336
+ } }),
1337
+ minNumCharsValidationError && (React__default.createElement("div", { className: "text-danger fw-bold mt-2" }, minNumCharsValidationError)),
1338
+ customValidationError && (React__default.createElement("div", { className: "text-danger fw-bold mt-2" }, customValidationError)))));
1339
+ }
1234
1340
  /* ------ Custom Modal Portals ------ */
1235
1341
  // Custom modal portals
1236
1342
  const customModalPortals = [];
@@ -3763,21 +3869,10 @@ const LogReviewer = (props) => {
3763
3869
  // Destructure
3764
3870
  const { year, month } = toLoad[i];
3765
3871
  // Load
3766
- let logs = [];
3767
- let pageNumber = 1;
3768
- let hasAnotherPage = true;
3769
- while (hasAnotherPage) {
3770
- const response = yield visitServerEndpoint({
3771
- path: `${LOG_REVIEW_ROUTE_PATH_PREFIX}/years/${year}/months/${month}`,
3772
- method: 'GET',
3773
- params: {
3774
- pageNumber,
3775
- },
3776
- });
3777
- logs = logs.concat(response.items);
3778
- hasAnotherPage = response.hasAnotherPage;
3779
- pageNumber += 1;
3780
- }
3872
+ const logs = yield visitServerEndpoint({
3873
+ path: `${LOG_REVIEW_ROUTE_PATH_PREFIX}/years/${year}/months/${month}`,
3874
+ method: 'GET',
3875
+ });
3781
3876
  // Add to map
3782
3877
  if (!logMap[year]) {
3783
3878
  logMap[year] = {};
@@ -14037,27 +14132,22 @@ const initServer = (opts) => {
14037
14132
  paramTypes: {
14038
14133
  year: ParamType$1.Int,
14039
14134
  month: ParamType$1.Int,
14040
- pageNumber: ParamType$1.Int,
14041
14135
  },
14042
14136
  handler: ({ params }) => __awaiter(void 0, void 0, void 0, function* () {
14043
14137
  // Get user info
14044
- const { year, month, pageNumber, userId, isAdmin, } = params;
14138
+ const { year, month, userId, isAdmin, } = params;
14045
14139
  // Validate user
14046
14140
  const canReview = yield canReviewLogs(userId, isAdmin);
14047
14141
  if (!canReview) {
14048
14142
  throw new ErrorWithCode('You cannot access this resource because you do not have the appropriate permissions.', ReactKitErrorCode$1.NotAllowedToReviewLogs);
14049
14143
  }
14050
14144
  // Query for logs
14051
- const response = yield _logCollection.findPaged({
14052
- query: {
14053
- year,
14054
- month,
14055
- },
14056
- perPage: 1000,
14057
- pageNumber,
14145
+ const logs = yield _logCollection.find({
14146
+ year,
14147
+ month,
14058
14148
  });
14059
- // Return response
14060
- return response;
14149
+ // Return logs
14150
+ return logs;
14061
14151
  }),
14062
14152
  }));
14063
14153
  };
@@ -16225,5 +16315,5 @@ var DayOfWeek;
16225
16315
  })(DayOfWeek || (DayOfWeek = {}));
16226
16316
  var DayOfWeek$1 = DayOfWeek;
16227
16317
 
16228
- 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 };
16318
+ 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 };
16229
16319
  //# sourceMappingURL=index.js.map