dce-reactkit 3.9.4-beta-prompt.2 → 3.9.4-beta-logreviewer.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.
@@ -49,9 +49,6 @@ const modalTypeToModalButtonTypes: {
49
49
  [ModalType.Okay]: [
50
50
  ModalButtonType.Okay,
51
51
  ],
52
- [ModalType.Cancel]: [
53
- ModalButtonType.Cancel,
54
- ],
55
52
  [ModalType.OkayCancel]: [
56
53
  ModalButtonType.Okay,
57
54
  ModalButtonType.Cancel,
package/src/index.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  // Import components
2
2
  import AppWrapper, {
3
3
  alert,
4
- prompt,
5
4
  confirm,
6
5
  showFatalError,
7
6
  addFatalErrorHandler,
@@ -149,7 +148,6 @@ export {
149
148
  Dropdown,
150
149
  // Global functions
151
150
  alert,
152
- prompt,
153
151
  confirm,
154
152
  showFatalError,
155
153
  // Errors
@@ -234,26 +234,24 @@ const initServer = (
234
234
  );
235
235
 
236
236
  /**
237
- * Get all logs for a certain month
238
- * @author Gabe Abrams
239
- * @param {number} year the year to query (e.g. 2022)
240
- * @param {number} month the month to query (e.g. 1 = January)
241
- * @returns {Log[]} list of logs from the given month
242
- */
237
+ * Get filtered logs based on provided filters
238
+ * @author Gabe Abrams, Yuen Ler Chow
239
+ * @returns {Log[]} list of logs that match the filters
240
+ */
243
241
  opts.app.get(
244
- `${LOG_REVIEW_ROUTE_PATH_PREFIX}/years/:year/months/:month`,
242
+ `${LOG_REVIEW_ROUTE_PATH_PREFIX}/logs`,
245
243
  genRouteHandler({
246
244
  paramTypes: {
247
- year: ParamType.Int,
248
- month: ParamType.Int,
245
+ pageNumber: ParamType.Int,
246
+ filters: ParamType.JSON,
249
247
  },
250
248
  handler: async ({ params }) => {
251
- // Get user info
249
+ // Get user info
252
250
  const {
253
- year,
254
- month,
251
+ pageNumber,
255
252
  userId,
256
253
  isAdmin,
254
+ filters,
257
255
  } = params;
258
256
 
259
257
  // Validate user
@@ -265,14 +263,149 @@ const initServer = (
265
263
  );
266
264
  }
267
265
 
266
+ // Build MongoDB query based on filters
267
+ const query: any = {};
268
+
269
+ /* -------------- Date Filter ------------- */
270
+ const { startDate, endDate } = filters.dateFilterState;
271
+ const startTimestamp = new Date(startDate.year, startDate.month - 1, startDate.day).getTime();
272
+ const endTimestamp = new Date(endDate.year, endDate.month - 1, endDate.day + 1).getTime() - 1;
273
+
274
+ query.timestamp = {
275
+ $gte: startTimestamp,
276
+ $lte: endTimestamp,
277
+ };
278
+
279
+ /* ------------ Context Filter ------------ */
280
+ const { contextFilterState } = filters;
281
+ const contextConditions: any[] = [];
282
+
283
+ Object.keys(contextFilterState).forEach((context) => {
284
+ const value = contextFilterState[context];
285
+ if (typeof value === 'boolean') {
286
+ if (value) {
287
+ // The entire context is selected
288
+ contextConditions.push({ context });
289
+ }
290
+ } else {
291
+ // The context has subcontexts
292
+ const subcontexts = Object.keys(value).filter((subcontext) => { return value[subcontext]; });
293
+ if (subcontexts.length > 0) {
294
+ contextConditions.push({
295
+ context,
296
+ subcontext: { $in: subcontexts },
297
+ });
298
+ }
299
+ }
300
+ });
301
+
302
+ if (contextConditions.length > 0) {
303
+ query.$or = contextConditions;
304
+ }
305
+
306
+ /* -------------- Tag Filter -------------- */
307
+ const { tagFilterState } = filters;
308
+ const selectedTags = Object.keys(tagFilterState).filter((tag) => { return tagFilterState[tag]; });
309
+ if (selectedTags.length > 0) {
310
+ query.tags = { $in: selectedTags };
311
+ }
312
+
313
+ /* --------- Action/Error Filter ---------- */
314
+ const { actionErrorFilterState } = filters;
315
+
316
+ if (actionErrorFilterState.type) {
317
+ query.type = actionErrorFilterState.type;
318
+ }
319
+
320
+ if (actionErrorFilterState.type === 'error' && actionErrorFilterState.errorMessage) {
321
+ query.errorMessage = { $regex: actionErrorFilterState.errorMessage, $options: 'i' };
322
+ }
323
+
324
+ if (actionErrorFilterState.type === 'error' && actionErrorFilterState.errorCode) {
325
+ query.errorCode = { $regex: actionErrorFilterState.errorCode, $options: 'i' };
326
+ }
327
+
328
+ if (actionErrorFilterState.type === 'action') {
329
+ const selectedTargets = Object.keys(actionErrorFilterState.target).filter(
330
+ (target) => { return actionErrorFilterState.target[target]; },
331
+ );
332
+ const selectedActions = Object.keys(actionErrorFilterState.action).filter(
333
+ (action) => { return actionErrorFilterState.action[action]; },
334
+ );
335
+ if (selectedTargets.length > 0) {
336
+ query.target = { $in: selectedTargets };
337
+ }
338
+ if (selectedActions.length > 0) {
339
+ query.action = { $in: selectedActions };
340
+ }
341
+ }
342
+
343
+ /* ------------ Advanced Filter ----------- */
344
+ const { advancedFilterState } = filters;
345
+
346
+ if (advancedFilterState.userFirstName) {
347
+ query.userFirstName = { $regex: advancedFilterState.userFirstName, $options: 'i' };
348
+ }
349
+
350
+ if (advancedFilterState.userLastName) {
351
+ query.userLastName = { $regex: advancedFilterState.userLastName, $options: 'i' };
352
+ }
353
+
354
+ if (advancedFilterState.userEmail) {
355
+ query.userEmail = { $regex: advancedFilterState.userEmail, $options: 'i' };
356
+ }
357
+
358
+ if (advancedFilterState.userId) {
359
+ query.userId = parseInt(advancedFilterState.userId, 10);
360
+ }
361
+
362
+ const roles = [];
363
+ if (advancedFilterState.includeLearners) {
364
+ roles.push({ isLearner: true });
365
+ }
366
+ if (advancedFilterState.includeTTMs) {
367
+ roles.push({ isTTM: true });
368
+ }
369
+ if (advancedFilterState.includeAdmins) {
370
+ roles.push({ isAdmin: true });
371
+ }
372
+ if (roles.length > 0) {
373
+ query.$and = [{ $or: roles }];
374
+ }
375
+
376
+ if (advancedFilterState.courseId) {
377
+ query.courseId = parseInt(advancedFilterState.courseId, 10);
378
+ }
379
+
380
+ if (advancedFilterState.courseName) {
381
+ query.courseName = { $regex: advancedFilterState.courseName, $options: 'i' };
382
+ }
383
+
384
+ if (advancedFilterState.isMobile !== undefined) {
385
+ query['device.isMobile'] = advancedFilterState.isMobile;
386
+ }
387
+
388
+ if (advancedFilterState.source) {
389
+ query.source = advancedFilterState.source;
390
+ }
391
+
392
+ if (advancedFilterState.routePath) {
393
+ query.routePath = { $regex: advancedFilterState.routePath, $options: 'i' };
394
+ }
395
+
396
+ if (advancedFilterState.routeTemplate) {
397
+ query.routeTemplate = { $regex: advancedFilterState.routeTemplate, $options: 'i' };
398
+ }
399
+
268
400
  // Query for logs
269
- const logs: Log[] = await _logCollection.find({
270
- year,
271
- month,
401
+ const response = await _logCollection.findPaged({
402
+ query,
403
+ perPage: 50,
404
+ pageNumber,
272
405
  });
273
406
 
274
- // Return logs
275
- return logs;
407
+ // Return response
408
+ return response;
276
409
  },
277
410
  }),
278
411
  );
@@ -4,7 +4,6 @@
4
4
  */
5
5
  enum ModalType {
6
6
  Okay = 'okay', // [Okay]
7
- Cancel = 'cancel', // [Cancel]
8
7
  OkayCancel = 'okay-cancel', // [Okay] [Cancel]
9
8
  YesNo = 'yes-no', // [Yes] [No]
10
9
  YesNoCancel = 'yes-no-cancel', // [Yes] [No] [Cancel]