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.
- package/dist/cjs/index.js +120 -29
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/components/AppWrapper.d.ts +24 -0
- package/dist/cjs/types/index.d.ts +2 -2
- package/dist/cjs/types/types/ModalType.d.ts +1 -0
- package/dist/esm/index.js +120 -30
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/components/AppWrapper.d.ts +24 -0
- package/dist/esm/types/index.d.ts +2 -2
- package/dist/esm/types/types/ModalType.d.ts +1 -0
- package/dist/index.d.ts +26 -1
- package/package.json +1 -1
- package/src/components/AppWrapper.tsx +216 -0
- package/src/components/LogReviewer.tsx +4 -17
- package/src/components/Modal/index.tsx +3 -0
- package/src/index.ts +2 -0
- package/src/server/initServer.ts +5 -11
- package/src/types/ModalType.tsx +1 -0
package/dist/cjs/index.js
CHANGED
|
@@ -186,6 +186,7 @@ var ModalButtonType$1 = ModalButtonType;
|
|
|
186
186
|
var ModalType;
|
|
187
187
|
(function (ModalType) {
|
|
188
188
|
ModalType["Okay"] = "okay";
|
|
189
|
+
ModalType["Cancel"] = "cancel";
|
|
189
190
|
ModalType["OkayCancel"] = "okay-cancel";
|
|
190
191
|
ModalType["YesNo"] = "yes-no";
|
|
191
192
|
ModalType["YesNoCancel"] = "yes-no-cancel";
|
|
@@ -340,6 +341,9 @@ const modalTypeToModalButtonTypes = {
|
|
|
340
341
|
[ModalType$1.Okay]: [
|
|
341
342
|
ModalButtonType$1.Okay,
|
|
342
343
|
],
|
|
344
|
+
[ModalType$1.Cancel]: [
|
|
345
|
+
ModalButtonType$1.Cancel,
|
|
346
|
+
],
|
|
343
347
|
[ModalType$1.OkayCancel]: [
|
|
344
348
|
ModalButtonType$1.Okay,
|
|
345
349
|
ModalButtonType$1.Cancel,
|
|
@@ -1080,6 +1084,74 @@ const confirm = (title, text, opts) => __awaiter(void 0, void 0, void 0, functio
|
|
|
1080
1084
|
});
|
|
1081
1085
|
});
|
|
1082
1086
|
/*----------------------------------------*/
|
|
1087
|
+
/* --------------- Prompt -------------- */
|
|
1088
|
+
/*----------------------------------------*/
|
|
1089
|
+
// Stored copies of setters
|
|
1090
|
+
let setPromptInfo;
|
|
1091
|
+
// Function to call when prompt is closed
|
|
1092
|
+
let onPromptClosed;
|
|
1093
|
+
/**
|
|
1094
|
+
* Show a prompt modal asking the user for input
|
|
1095
|
+
* @author Yuen Ler Chow
|
|
1096
|
+
* @param title the title text to display at the top of the prompt
|
|
1097
|
+
* @param text the text to display in the prompt
|
|
1098
|
+
* @param [opts={}] additional options for the prompt dialog
|
|
1099
|
+
* @param [opts.placeholder] the placeholder text for the input field
|
|
1100
|
+
* @param [opts.defaultText] the default text for the input field
|
|
1101
|
+
* @param [opts.confirmButtonText=Okay] the text of the confirm button
|
|
1102
|
+
* @param [opts.confirmButtonVariant=Variant.Dark] the variant of the confirm button
|
|
1103
|
+
* @param [opts.cancelButtonText=Cancel] the text of the cancel button
|
|
1104
|
+
* @param [opts.cancelButtonVariant=Variant.Secondary] the variant of the cancel button
|
|
1105
|
+
* @returns Promise that resolves with the input string or null if canceled
|
|
1106
|
+
*/
|
|
1107
|
+
const prompt = (title, text, opts) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1108
|
+
var _a;
|
|
1109
|
+
// Wait for helper to exist
|
|
1110
|
+
yield waitForHelper(() => {
|
|
1111
|
+
return !!setPromptInfo;
|
|
1112
|
+
});
|
|
1113
|
+
// Fallback if prompt is not available
|
|
1114
|
+
if (!setPromptInfo) {
|
|
1115
|
+
const resultPassesValidation = false;
|
|
1116
|
+
while (!resultPassesValidation) {
|
|
1117
|
+
// eslint-disable-next-line no-alert
|
|
1118
|
+
const result = window.prompt(`${title}\n\n${text}`, (_a = opts === null || opts === void 0 ? void 0 : opts.defaultText) !== null && _a !== void 0 ? _a : '');
|
|
1119
|
+
if (result === null) {
|
|
1120
|
+
return null;
|
|
1121
|
+
}
|
|
1122
|
+
// Validate min num chars
|
|
1123
|
+
const minNumCharsValidationError = (((opts === null || opts === void 0 ? void 0 : opts.minNumChars) && result.length < opts.minNumChars)
|
|
1124
|
+
? `Please enter at least ${opts.minNumChars} characters.`
|
|
1125
|
+
: undefined);
|
|
1126
|
+
// Run custom validation
|
|
1127
|
+
const customValidationError = ((opts === null || opts === void 0 ? void 0 : opts.findValidationError)
|
|
1128
|
+
&& opts.findValidationError(result));
|
|
1129
|
+
// Show validation issue
|
|
1130
|
+
if (minNumCharsValidationError || customValidationError) {
|
|
1131
|
+
alert('Invalid Input', `${minNumCharsValidationError !== null && minNumCharsValidationError !== void 0 ? minNumCharsValidationError : ''} ${customValidationError !== null && customValidationError !== void 0 ? customValidationError : ''}`);
|
|
1132
|
+
}
|
|
1133
|
+
else {
|
|
1134
|
+
return result;
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
// Return promise that resolves with result of prompt
|
|
1139
|
+
return new Promise((resolve) => {
|
|
1140
|
+
var _a;
|
|
1141
|
+
// Setup handler
|
|
1142
|
+
onPromptClosed = (result) => {
|
|
1143
|
+
resolve(result);
|
|
1144
|
+
};
|
|
1145
|
+
// Show the prompt
|
|
1146
|
+
setPromptInfo({
|
|
1147
|
+
title,
|
|
1148
|
+
text,
|
|
1149
|
+
currentInputFieldText: ((_a = opts === null || opts === void 0 ? void 0 : opts.defaultText) !== null && _a !== void 0 ? _a : ''),
|
|
1150
|
+
opts: (opts !== null && opts !== void 0 ? opts : {}),
|
|
1151
|
+
});
|
|
1152
|
+
});
|
|
1153
|
+
});
|
|
1154
|
+
/*----------------------------------------*/
|
|
1083
1155
|
/* ------------- Fatal Error ------------ */
|
|
1084
1156
|
/*----------------------------------------*/
|
|
1085
1157
|
// Stored copies of setters
|
|
@@ -1095,14 +1167,14 @@ const fatalErrorHandlers = [];
|
|
|
1095
1167
|
* @param [errorTitle] title of the error box
|
|
1096
1168
|
*/
|
|
1097
1169
|
const showFatalError = (error, errorTitle = 'An Error Occurred') => __awaiter(void 0, void 0, void 0, function* () {
|
|
1098
|
-
var
|
|
1170
|
+
var _b, _c;
|
|
1099
1171
|
// Determine message and code
|
|
1100
1172
|
const message = (typeof error === 'string'
|
|
1101
1173
|
? error.trim()
|
|
1102
|
-
: String((
|
|
1174
|
+
: String((_b = error.message) !== null && _b !== void 0 ? _b : 'An unknown error occurred.'));
|
|
1103
1175
|
const code = (typeof error === 'string'
|
|
1104
1176
|
? ReactKitErrorCode$1.NoCode
|
|
1105
|
-
: String((
|
|
1177
|
+
: String((_c = error.code) !== null && _c !== void 0 ? _c : ReactKitErrorCode$1.NoCode));
|
|
1106
1178
|
// Call all fatal error listeners
|
|
1107
1179
|
try {
|
|
1108
1180
|
fatalErrorHandlers.forEach((handler) => {
|
|
@@ -1229,6 +1301,9 @@ const AppWrapper = (props) => {
|
|
|
1229
1301
|
// Confirm
|
|
1230
1302
|
const [confirmInfo, setConfirmInfoInner,] = React.useState(undefined);
|
|
1231
1303
|
setConfirmInfo = setConfirmInfoInner;
|
|
1304
|
+
// Prompt
|
|
1305
|
+
const [promptInfo, setPromptInfoInner] = React.useState(undefined);
|
|
1306
|
+
setPromptInfo = setPromptInfoInner;
|
|
1232
1307
|
// Session expired
|
|
1233
1308
|
const [sessionHasExpired, setSessionHasExpiredInner,] = React.useState(false);
|
|
1234
1309
|
setSessionHasExpired = setSessionHasExpiredInner;
|
|
@@ -1259,6 +1334,37 @@ const AppWrapper = (props) => {
|
|
|
1259
1334
|
}
|
|
1260
1335
|
}, onTopOfOtherModals: true, dontAllowBackdropExit: true }, confirmInfo.text));
|
|
1261
1336
|
}
|
|
1337
|
+
/* ------------- Prompt ------------ */
|
|
1338
|
+
if (promptInfo) {
|
|
1339
|
+
// Run min char validation
|
|
1340
|
+
const minNumCharsValidationError = ((promptInfo.opts.minNumChars
|
|
1341
|
+
&& promptInfo.currentInputFieldText.length < promptInfo.opts.minNumChars)
|
|
1342
|
+
? `Please enter at least ${promptInfo.opts.minNumChars} characters.`
|
|
1343
|
+
: undefined);
|
|
1344
|
+
// Run custom validation
|
|
1345
|
+
const customValidationError = (promptInfo.opts.findValidationError
|
|
1346
|
+
&& promptInfo.opts.findValidationError(promptInfo.currentInputFieldText));
|
|
1347
|
+
modal = (React__default["default"].createElement(Modal, { key: `prompt-${promptInfo.title}-${promptInfo.text}`, title: promptInfo.title,
|
|
1348
|
+
// Don't show ok button if there is a validation error
|
|
1349
|
+
type: ((customValidationError || minNumCharsValidationError)
|
|
1350
|
+
? ModalType$1.Cancel
|
|
1351
|
+
: ModalType$1.OkayCancel), okayLabel: promptInfo.opts.confirmButtonText, okayVariant: promptInfo.opts.confirmButtonVariant, cancelLabel: promptInfo.opts.cancelButtonText, cancelVariant: promptInfo.opts.cancelButtonVariant, onClose: (buttonType) => {
|
|
1352
|
+
const result = (buttonType === ModalButtonType$1.Okay
|
|
1353
|
+
? promptInfo.currentInputFieldText
|
|
1354
|
+
: null);
|
|
1355
|
+
setPromptInfo(undefined);
|
|
1356
|
+
if (onPromptClosed) {
|
|
1357
|
+
onPromptClosed(result);
|
|
1358
|
+
}
|
|
1359
|
+
}, onTopOfOtherModals: true, dontAllowBackdropExit: true },
|
|
1360
|
+
React__default["default"].createElement("div", { className: "p-3" },
|
|
1361
|
+
React__default["default"].createElement("p", null, promptInfo.text),
|
|
1362
|
+
React__default["default"].createElement("input", { type: "text", className: "form-control mb-2", placeholder: promptInfo.opts.placeholder, value: promptInfo.currentInputFieldText, onChange: (e) => {
|
|
1363
|
+
return setPromptInfo(Object.assign(Object.assign({}, promptInfo), { currentInputFieldText: e.target.value }));
|
|
1364
|
+
} }),
|
|
1365
|
+
minNumCharsValidationError && (React__default["default"].createElement("div", { className: "text-danger fw-bold mt-2" }, minNumCharsValidationError)),
|
|
1366
|
+
customValidationError && (React__default["default"].createElement("div", { className: "text-danger fw-bold mt-2" }, customValidationError)))));
|
|
1367
|
+
}
|
|
1262
1368
|
/* ------ Custom Modal Portals ------ */
|
|
1263
1369
|
// Custom modal portals
|
|
1264
1370
|
const customModalPortals = [];
|
|
@@ -3791,21 +3897,10 @@ const LogReviewer = (props) => {
|
|
|
3791
3897
|
// Destructure
|
|
3792
3898
|
const { year, month } = toLoad[i];
|
|
3793
3899
|
// Load
|
|
3794
|
-
|
|
3795
|
-
|
|
3796
|
-
|
|
3797
|
-
|
|
3798
|
-
const response = yield visitServerEndpoint({
|
|
3799
|
-
path: `${LOG_REVIEW_ROUTE_PATH_PREFIX}/years/${year}/months/${month}`,
|
|
3800
|
-
method: 'GET',
|
|
3801
|
-
params: {
|
|
3802
|
-
pageNumber,
|
|
3803
|
-
},
|
|
3804
|
-
});
|
|
3805
|
-
logs = logs.concat(response.items);
|
|
3806
|
-
hasAnotherPage = response.hasAnotherPage;
|
|
3807
|
-
pageNumber += 1;
|
|
3808
|
-
}
|
|
3900
|
+
const logs = yield visitServerEndpoint({
|
|
3901
|
+
path: `${LOG_REVIEW_ROUTE_PATH_PREFIX}/years/${year}/months/${month}`,
|
|
3902
|
+
method: 'GET',
|
|
3903
|
+
});
|
|
3809
3904
|
// Add to map
|
|
3810
3905
|
if (!logMap[year]) {
|
|
3811
3906
|
logMap[year] = {};
|
|
@@ -14065,27 +14160,22 @@ const initServer = (opts) => {
|
|
|
14065
14160
|
paramTypes: {
|
|
14066
14161
|
year: ParamType$1.Int,
|
|
14067
14162
|
month: ParamType$1.Int,
|
|
14068
|
-
pageNumber: ParamType$1.Int,
|
|
14069
14163
|
},
|
|
14070
14164
|
handler: ({ params }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
14071
14165
|
// Get user info
|
|
14072
|
-
const { year, month,
|
|
14166
|
+
const { year, month, userId, isAdmin, } = params;
|
|
14073
14167
|
// Validate user
|
|
14074
14168
|
const canReview = yield canReviewLogs(userId, isAdmin);
|
|
14075
14169
|
if (!canReview) {
|
|
14076
14170
|
throw new ErrorWithCode('You cannot access this resource because you do not have the appropriate permissions.', ReactKitErrorCode$1.NotAllowedToReviewLogs);
|
|
14077
14171
|
}
|
|
14078
14172
|
// Query for logs
|
|
14079
|
-
const
|
|
14080
|
-
|
|
14081
|
-
|
|
14082
|
-
month,
|
|
14083
|
-
},
|
|
14084
|
-
perPage: 1000,
|
|
14085
|
-
pageNumber,
|
|
14173
|
+
const logs = yield _logCollection.find({
|
|
14174
|
+
year,
|
|
14175
|
+
month,
|
|
14086
14176
|
});
|
|
14087
|
-
// Return
|
|
14088
|
-
return
|
|
14177
|
+
// Return logs
|
|
14178
|
+
return logs;
|
|
14089
14179
|
}),
|
|
14090
14180
|
}));
|
|
14091
14181
|
};
|
|
@@ -16337,6 +16427,7 @@ exports.padDecimalZeros = padDecimalZeros;
|
|
|
16337
16427
|
exports.padZerosLeft = padZerosLeft;
|
|
16338
16428
|
exports.parallelLimit = parallelLimit;
|
|
16339
16429
|
exports.prefixWithAOrAn = prefixWithAOrAn;
|
|
16430
|
+
exports.prompt = prompt;
|
|
16340
16431
|
exports.roundToNumDecimals = roundToNumDecimals;
|
|
16341
16432
|
exports.setClientEventMetadataPopulator = setClientEventMetadataPopulator;
|
|
16342
16433
|
exports.showFatalError = showFatalError;
|