@hmcts/ccd-case-ui-toolkit 7.3.54-pofcc-131 → 7.3.54-polling

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.
@@ -8,11 +8,10 @@ import * as i1$1 from '@angular/router';
8
8
  import { RouterModule, NavigationStart, NavigationEnd } from '@angular/router';
9
9
  import * as i4 from '@angular/forms';
10
10
  import { NG_VALUE_ACCESSOR, NG_VALIDATORS, FormArray, FormGroup, FormControl, Validators, ReactiveFormsModule, FormsModule } from '@angular/forms';
11
- import { BehaviorSubject, throwError, Subject, EMPTY, Observable, skip, of, timer, forkJoin, fromEvent, Subscription, combineLatest } from 'rxjs';
11
+ import { BehaviorSubject, throwError, Subject, EMPTY, concat, defer, timer, Observable, skip, of, forkJoin, fromEvent, Subscription, combineLatest } from 'rxjs';
12
+ import { distinctUntilChanged, catchError, map, switchMap, repeat, retry, publish, refCount, debounceTime, delay, finalize, timeout, mergeMap, retryWhen, tap, delayWhen, publishReplay, take, first, takeUntil, filter } from 'rxjs/operators';
12
13
  import * as i1$2 from '@angular/common/http';
13
14
  import { HttpErrorResponse, HttpHeaders, HttpParams } from '@angular/common/http';
14
- import { distinctUntilChanged, catchError, map, publish, refCount, switchMap, debounceTime, delay, finalize, timeout, mergeMap, retryWhen, tap, delayWhen, publishReplay, take, first, takeUntil, filter } from 'rxjs/operators';
15
- import { polling } from 'rx-polling-hmcts';
16
15
  import { Type, Exclude, Expose, plainToClassFromExist, plainToClass } from 'class-transformer';
17
16
  import moment from 'moment';
18
17
  import { __decorate, __metadata } from 'tslib';
@@ -1264,12 +1263,6 @@ class AbstractAppConfig {
1264
1263
  return 'ithc';
1265
1264
  return 'prod';
1266
1265
  }
1267
- getWASupportedRoleCategories() {
1268
- return [];
1269
- }
1270
- getWASupportedRoleTypes() {
1271
- return [];
1272
- }
1273
1266
  getCamRoleAssignmentsApiUrl() {
1274
1267
  return undefined;
1275
1268
  }
@@ -1326,8 +1319,6 @@ class CaseEditorConfig {
1326
1319
  icp_jurisdictions;
1327
1320
  events_to_hide;
1328
1321
  enable_service_specific_multi_followups;
1329
- wa_supported_role_categories;
1330
- wa_supported_role_types;
1331
1322
  }
1332
1323
 
1333
1324
  class HttpError {
@@ -1837,8 +1828,7 @@ class ActivityPollingService {
1837
1828
  this.config = config;
1838
1829
  this.pollConfig = {
1839
1830
  interval: config.getActivityNexPollRequestMs(),
1840
- attempts: config.getActivityRetry(),
1841
- backgroundPolling: true
1831
+ attempts: config.getActivityRetry()
1842
1832
  };
1843
1833
  this.batchCollectionDelayMs = config.getActivityBatchCollectionDelayMs();
1844
1834
  this.maxRequestsPerBatch = config.getActivityMaxRequestPerBatch();
@@ -1855,17 +1845,18 @@ class ActivityPollingService {
1855
1845
  subject.subscribe(done);
1856
1846
  }
1857
1847
  else {
1848
+ // Only the first pending request should start the batch collection timer.
1849
+ const wasEmpty = this.pendingRequests.size === 0;
1858
1850
  subject = new Subject();
1859
1851
  subject.subscribe(done);
1860
- this.pendingRequests.set(caseId, subject);
1861
- }
1862
- if (this.pendingRequests.size === 1) {
1863
- this.ngZone.runOutsideAngular(() => {
1864
- this.currentTimeoutHandle = setTimeout(() => this.ngZone.run(() => {
1865
- // console.log('timeout: flushing requests')
1866
- this.flushRequests();
1867
- }), this.batchCollectionDelayMs);
1868
- });
1852
+ this.addPendingRequest(caseId, subject);
1853
+ if (wasEmpty) {
1854
+ this.ngZone.runOutsideAngular(() => {
1855
+ this.currentTimeoutHandle = setTimeout(() => this.ngZone.run(() => {
1856
+ this.flushRequests();
1857
+ }), this.batchCollectionDelayMs);
1858
+ });
1859
+ }
1869
1860
  }
1870
1861
  if (this.pendingRequests.size >= this.maxRequestsPerBatch) {
1871
1862
  // console.log('max pending hit: flushing requests');
@@ -1883,6 +1874,9 @@ class ActivityPollingService {
1883
1874
  clearTimeout(this.currentTimeoutHandle);
1884
1875
  this.currentTimeoutHandle = undefined;
1885
1876
  }
1877
+ if (!this.pendingRequests.size) {
1878
+ return;
1879
+ }
1886
1880
  const requests = new Map(this.pendingRequests);
1887
1881
  this.pendingRequests.clear();
1888
1882
  this.performBatchRequest(requests);
@@ -1891,7 +1885,7 @@ class ActivityPollingService {
1891
1885
  if (!this.isEnabled) {
1892
1886
  return EMPTY;
1893
1887
  }
1894
- return polling(this.activityService.getActivities(...caseIds), this.pollConfig);
1888
+ return this.polling(this.activityService.getActivities(...caseIds), this.pollConfig);
1895
1889
  }
1896
1890
  postViewActivity(caseId) {
1897
1891
  return this.postActivity(caseId, ActivityService.ACTIVITY_VIEW);
@@ -1904,17 +1898,19 @@ class ActivityPollingService {
1904
1898
  // console.log('issuing batch request for cases: ' + caseIds);
1905
1899
  this.ngZone.runOutsideAngular(() => {
1906
1900
  // run polling outside angular zone so it does not trigger change detection
1907
- this.pollActivitiesSubscription = this.pollActivities(caseIds).subscribe(
1908
- // process activity inside zone so it triggers change detection for activity.component.ts
1909
- (activities) => this.ngZone.run(() => {
1910
- activities.forEach((activity) => {
1911
- // console.log('pushing activity: ' + activity.caseId);
1912
- requests.get(activity.caseId).next(activity);
1913
- });
1914
- }, (err) => {
1915
- console.log(`error: ${err}`);
1916
- Array.from(requests.values()).forEach((subject) => subject.error(err));
1917
- }));
1901
+ this.pollActivitiesSubscription = this.pollActivities(caseIds).subscribe({
1902
+ // process activity inside zone so it triggers change detection for activity.component.ts
1903
+ next: (activities) => this.ngZone.run(() => {
1904
+ activities.forEach((activity) => {
1905
+ // Ignore activities returned for cases outside this local batch.
1906
+ requests.get(activity.caseId)?.next(activity);
1907
+ });
1908
+ }),
1909
+ error: (err) => this.ngZone.run(() => {
1910
+ console.log(`error: ${err}`);
1911
+ Array.from(requests.values()).forEach((subject) => subject.error(err));
1912
+ })
1913
+ });
1918
1914
  });
1919
1915
  }
1920
1916
  postActivity(caseId, activityType) {
@@ -1925,7 +1921,42 @@ class ActivityPollingService {
1925
1921
  ...this.pollConfig,
1926
1922
  interval: 5000 // inline with CCD Backend
1927
1923
  };
1928
- return polling(this.activityService.postActivity(caseId, activityType), pollingConfig);
1924
+ return this.polling(this.activityService.postActivity(caseId, activityType), pollingConfig);
1925
+ }
1926
+ addPendingRequest(caseId, subject) {
1927
+ this.pendingRequests.set(caseId, subject);
1928
+ // Components complete their returned Subject on destroy; remove it so a later same-case subscription gets a fresh Subject.
1929
+ subject.subscribe({
1930
+ complete: () => this.removePendingRequest(caseId, subject),
1931
+ error: () => this.removePendingRequest(caseId, subject)
1932
+ });
1933
+ }
1934
+ removePendingRequest(caseId, subject) {
1935
+ if (this.pendingRequests.get(caseId) !== subject) {
1936
+ return;
1937
+ }
1938
+ this.pendingRequests.delete(caseId);
1939
+ if (!this.pendingRequests.size && this.currentTimeoutHandle) {
1940
+ clearTimeout(this.currentTimeoutHandle);
1941
+ this.currentTimeoutHandle = undefined;
1942
+ }
1943
+ }
1944
+ polling(request$, options) {
1945
+ const pollingOptions = {
1946
+ interval: options.interval,
1947
+ attempts: options.attempts ?? 9,
1948
+ exponentialUnit: options.exponentialUnit ?? 1000
1949
+ };
1950
+ return concat(request$, defer(() => timer(pollingOptions.interval).pipe(switchMap(() => request$))).pipe(repeat())).pipe(
1951
+ // Preserve consecutive-failure retry behaviour using the current RxJS retry config.
1952
+ retry({
1953
+ count: pollingOptions.attempts,
1954
+ delay: (_error, retryCount) => timer(this.getExponentialRetryDelay(retryCount, pollingOptions.exponentialUnit)),
1955
+ resetOnSuccess: true
1956
+ }));
1957
+ }
1958
+ getExponentialRetryDelay(consecutiveErrorsCount, exponentialUnit) {
1959
+ return Math.pow(2, consecutiveErrorsCount - 1) * exponentialUnit;
1929
1960
  }
1930
1961
  static ɵfac = function ActivityPollingService_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || ActivityPollingService)(i0.ɵɵinject(ActivityService), i0.ɵɵinject(i0.NgZone), i0.ɵɵinject(AbstractAppConfig)); };
1931
1962
  static ɵprov = /*@__PURE__*/ i0.ɵɵdefineInjectable({ token: ActivityPollingService, factory: ActivityPollingService.ɵfac });