dce-reactkit 3.9.4-beta-logreviewer.3 → 3.9.4-beta-logreviewer.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.
package/dist/cjs/index.js CHANGED
@@ -3561,6 +3561,8 @@ var ActionType$6;
3561
3561
  ActionType["DecrementPageNumber"] = "decrement-page-number";
3562
3562
  // Set has another page
3563
3563
  ActionType["SetHasAnotherPage"] = "set-has-another-page";
3564
+ // Set the number of pages
3565
+ ActionType["SetNumPages"] = "set-num-pages";
3564
3566
  })(ActionType$6 || (ActionType$6 = {}));
3565
3567
  /**
3566
3568
  * Reducer that executes actions
@@ -3585,7 +3587,7 @@ const reducer$7 = (state, action) => {
3585
3587
  return Object.assign(Object.assign({}, state), { expandedFilterDrawer: undefined });
3586
3588
  }
3587
3589
  case ActionType$6.ResetFilters: {
3588
- return Object.assign(Object.assign({}, state), { dateFilterState: action.initDateFilterState, contextFilterState: action.initContextFilterState, tagFilterState: action.initTagFilterState, actionErrorFilterState: action.initActionErrorFilterState, advancedFilterState: action.initAdvancedFilterState });
3590
+ return Object.assign(Object.assign({}, state), { dateFilterState: action.initDateFilterState, contextFilterState: action.initContextFilterState, tagFilterState: action.initTagFilterState, actionErrorFilterState: action.initActionErrorFilterState, advancedFilterState: action.initAdvancedFilterState, pageNumber: 1 });
3589
3591
  }
3590
3592
  case ActionType$6.UpdateDateFilterState: {
3591
3593
  return Object.assign(Object.assign({}, state), { dateFilterState: action.dateFilterState });
@@ -3611,6 +3613,9 @@ const reducer$7 = (state, action) => {
3611
3613
  case ActionType$6.SetHasAnotherPage: {
3612
3614
  return Object.assign(Object.assign({}, state), { hasAnotherPage: action.hasAnotherPage });
3613
3615
  }
3616
+ case ActionType$6.SetNumPages: {
3617
+ return Object.assign(Object.assign({}, state), { numPages: action.numPages });
3618
+ }
3614
3619
  default: {
3615
3620
  return state;
3616
3621
  }
@@ -3737,28 +3742,22 @@ const LogReviewer = (props) => {
3737
3742
  advancedFilterState: initAdvancedFilterState,
3738
3743
  pageNumber: 1,
3739
3744
  hasAnotherPage: false,
3745
+ numPages: 1,
3740
3746
  };
3741
3747
  // Initialize state
3742
3748
  const [state, dispatch] = React.useReducer(reducer$7, initialState);
3743
3749
  // Destructure common state
3744
- const { loading, logs, expandedFilterDrawer, dateFilterState, contextFilterState, tagFilterState, actionErrorFilterState, advancedFilterState, pageNumber, hasAnotherPage, } = state;
3750
+ const { loading, logs, expandedFilterDrawer, dateFilterState, contextFilterState, tagFilterState, actionErrorFilterState, advancedFilterState, pageNumber, hasAnotherPage, numPages, } = state;
3745
3751
  /*------------------------------------------------------------------------*/
3746
3752
  /* ------------------------- Component Functions ------------------------ */
3747
3753
  /*------------------------------------------------------------------------*/
3748
3754
  /**
3749
3755
  * Fetch logs from the server based on current filters
3750
3756
  */
3751
- const fetchLogs = () => __awaiter(void 0, void 0, void 0, function* () {
3757
+ const fetchLogs = (opts) => __awaiter(void 0, void 0, void 0, function* () {
3758
+ const { filters, pageNum, countDocuments, } = opts;
3752
3759
  dispatch({ type: ActionType$6.StartLoading });
3753
3760
  try {
3754
- // Prepare filter parameters
3755
- const filters = {
3756
- dateFilterState,
3757
- contextFilterState,
3758
- tagFilterState,
3759
- actionErrorFilterState,
3760
- advancedFilterState,
3761
- };
3762
3761
  // Send filters to the server
3763
3762
  let fetchedLogs = [];
3764
3763
  // Get logs from server
@@ -3766,8 +3765,9 @@ const LogReviewer = (props) => {
3766
3765
  path: LOG_REVIEW_GET_LOGS_ROUTE,
3767
3766
  method: 'GET',
3768
3767
  params: {
3769
- pageNumber,
3768
+ pageNumber: pageNum,
3770
3769
  filters,
3770
+ countDocuments,
3771
3771
  },
3772
3772
  });
3773
3773
  fetchedLogs = fetchedLogs.concat(response.items);
@@ -3775,6 +3775,12 @@ const LogReviewer = (props) => {
3775
3775
  type: ActionType$6.SetHasAnotherPage,
3776
3776
  hasAnotherPage: response.hasAnotherPage,
3777
3777
  });
3778
+ if (countDocuments && response.numPages) {
3779
+ dispatch({
3780
+ type: ActionType$6.SetNumPages,
3781
+ numPages: response.numPages,
3782
+ });
3783
+ }
3778
3784
  // Update logs in state
3779
3785
  dispatch({
3780
3786
  type: ActionType$6.FinishLoading,
@@ -3786,17 +3792,6 @@ const LogReviewer = (props) => {
3786
3792
  }
3787
3793
  });
3788
3794
  /*------------------------------------------------------------------------*/
3789
- /* ------------------------- Lifecycle Functions ------------------------ */
3790
- /*------------------------------------------------------------------------*/
3791
- /**
3792
- * Fetch logs whenever page number changes
3793
- */
3794
- React.useEffect(() => {
3795
- fetchLogs();
3796
- }, [
3797
- pageNumber,
3798
- ]);
3799
- /*------------------------------------------------------------------------*/
3800
3795
  /* ------------------------------- Render ------------------------------- */
3801
3796
  /*------------------------------------------------------------------------*/
3802
3797
  /*----------------------------------------*/
@@ -3815,6 +3810,17 @@ const LogReviewer = (props) => {
3815
3810
  /*----------------------------------------*/
3816
3811
  const paginationControls = logs.length > 0 && (React__default["default"].createElement("div", { className: "text-center mt-3" },
3817
3812
  React__default["default"].createElement("button", { type: "button", className: "btn btn-secondary me-2", disabled: pageNumber <= 1, onClick: () => {
3813
+ fetchLogs({
3814
+ filters: {
3815
+ dateFilterState,
3816
+ contextFilterState,
3817
+ tagFilterState,
3818
+ actionErrorFilterState,
3819
+ advancedFilterState,
3820
+ },
3821
+ pageNum: pageNumber - 1,
3822
+ countDocuments: false,
3823
+ });
3818
3824
  dispatch({
3819
3825
  type: ActionType$6.DecrementPageNumber,
3820
3826
  });
@@ -3824,8 +3830,23 @@ const LogReviewer = (props) => {
3824
3830
  React__default["default"].createElement("span", { className: "mx-3" },
3825
3831
  "Page",
3826
3832
  ' ',
3827
- pageNumber),
3833
+ pageNumber,
3834
+ ' ',
3835
+ "of",
3836
+ ' ',
3837
+ numPages),
3828
3838
  React__default["default"].createElement("button", { type: "button", className: "btn btn-secondary ms-2", disabled: !hasAnotherPage, onClick: () => {
3839
+ fetchLogs({
3840
+ filters: {
3841
+ dateFilterState,
3842
+ contextFilterState,
3843
+ tagFilterState,
3844
+ actionErrorFilterState,
3845
+ advancedFilterState,
3846
+ },
3847
+ pageNum: pageNumber + 1,
3848
+ countDocuments: false,
3849
+ });
3829
3850
  dispatch({
3830
3851
  type: ActionType$6.IncrementPageNumber,
3831
3852
  });
@@ -3880,6 +3901,17 @@ const LogReviewer = (props) => {
3880
3901
  React__default["default"].createElement(reactFontawesome.FontAwesomeIcon, { icon: freeSolidSvgIcons.faList, className: "me-2" }),
3881
3902
  "Advanced"),
3882
3903
  React__default["default"].createElement("button", { type: "button", id: "LogReviewer-reset-filters-button", className: "btn btn-light", "aria-label": "reset filters", onClick: () => {
3904
+ fetchLogs({
3905
+ filters: {
3906
+ dateFilterState: initDateFilterState,
3907
+ contextFilterState: initContextFilterState,
3908
+ tagFilterState: initTagFilterState,
3909
+ actionErrorFilterState: initActionErrorFilterState,
3910
+ advancedFilterState: initAdvancedFilterState,
3911
+ },
3912
+ pageNum: 1,
3913
+ countDocuments: true,
3914
+ });
3883
3915
  dispatch({
3884
3916
  type: ActionType$6.ResetFilters,
3885
3917
  initActionErrorFilterState,
@@ -3888,6 +3920,9 @@ const LogReviewer = (props) => {
3888
3920
  initDateFilterState,
3889
3921
  initTagFilterState,
3890
3922
  });
3923
+ dispatch({
3924
+ type: ActionType$6.HideFilterDrawer,
3925
+ });
3891
3926
  } },
3892
3927
  React__default["default"].createElement(reactFontawesome.FontAwesomeIcon, { icon: freeSolidSvgIcons.faTimes }),
3893
3928
  ' ',
@@ -3896,7 +3931,17 @@ const LogReviewer = (props) => {
3896
3931
  dispatch({
3897
3932
  type: ActionType$6.HideFilterDrawer,
3898
3933
  });
3899
- fetchLogs();
3934
+ fetchLogs({
3935
+ filters: {
3936
+ dateFilterState,
3937
+ contextFilterState,
3938
+ tagFilterState,
3939
+ actionErrorFilterState,
3940
+ advancedFilterState,
3941
+ },
3942
+ pageNum: 1,
3943
+ countDocuments: true,
3944
+ });
3900
3945
  } },
3901
3946
  React__default["default"].createElement(reactFontawesome.FontAwesomeIcon, { icon: freeSolidSvgIcons.faSearch }),
3902
3947
  ' ',
@@ -4148,7 +4193,7 @@ const LogReviewer = (props) => {
4148
4193
  React__default["default"].createElement("input", { type: "text", className: "form-control", "aria-label": "query for user canvas id", value: advancedFilterState.userId, placeholder: "e.g. 104985", onChange: (e) => {
4149
4194
  const { value } = e.target;
4150
4195
  // Only update if value contains only numbers
4151
- if (/^\d+$/.test(value)) {
4196
+ if (/^\d+$/.test(value) || value === '') {
4152
4197
  advancedFilterState.userId = ((e.target.value)
4153
4198
  .trim());
4154
4199
  }
@@ -13802,14 +13847,15 @@ const initServer = (opts) => {
13802
13847
  * @param filters the filters to apply to the logs
13803
13848
  * @returns {Log[]} list of logs that match the filters
13804
13849
  */
13805
- opts.app.get(`${LOG_REVIEW_GET_LOGS_ROUTE}`, genRouteHandler({
13850
+ opts.app.get(LOG_REVIEW_GET_LOGS_ROUTE, genRouteHandler({
13806
13851
  paramTypes: {
13807
13852
  pageNumber: ParamType$1.Int,
13808
13853
  filters: ParamType$1.JSON,
13854
+ countDocuments: ParamType$1.Boolean,
13809
13855
  },
13810
13856
  handler: ({ params }) => __awaiter(void 0, void 0, void 0, function* () {
13811
13857
  // Get user info
13812
- const { pageNumber, userId, isAdmin, filters, } = params;
13858
+ const { pageNumber, userId, isAdmin, filters, countDocuments, } = params;
13813
13859
  const { dateFilterState, contextFilterState, tagFilterState, actionErrorFilterState, advancedFilterState, } = filters;
13814
13860
  // Validate user
13815
13861
  const canReview = yield canReviewLogs(userId, isAdmin);
@@ -13976,6 +14022,10 @@ const initServer = (opts) => {
13976
14022
  perPage: 50,
13977
14023
  pageNumber,
13978
14024
  });
14025
+ // Count documents if requested
14026
+ if (countDocuments) {
14027
+ response.numPages = Math.ceil((yield _logCollection.count(query)) / 50);
14028
+ }
13979
14029
  // Return response
13980
14030
  return response;
13981
14031
  }),