@hmcts/ccd-case-ui-toolkit 7.0.3-error-message-fix → 7.0.3-event-before-task-with-logic

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.
Files changed (24) hide show
  1. package/esm2020/lib/shared/components/case-editor/case-edit/case-edit.component.mjs +55 -25
  2. package/esm2020/lib/shared/components/case-editor/case-event-completion/components/case-event-completion-task-reassigned/case-event-completion-task-reassigned.component.mjs +4 -14
  3. package/esm2020/lib/shared/components/case-editor/services/event-completion-state-machine.service.mjs +6 -25
  4. package/esm2020/lib/shared/components/case-editor/services/wizard-page-field-to-case-field.mapper.mjs +4 -3
  5. package/esm2020/lib/shared/components/palette/document/write-document-field.component.mjs +2 -14
  6. package/esm2020/lib/shared/pipes/complex/ccd-read-fields-filter.pipe.mjs +4 -2
  7. package/esm2020/lib/shared/pipes/complex/fields-filter.pipe.mjs +4 -2
  8. package/esm2020/lib/shared/services/fields/fields.utils.mjs +6 -1
  9. package/esm2020/lib/shared/services/form/form-value.service.mjs +2 -2
  10. package/fesm2015/hmcts-ccd-case-ui-toolkit.mjs +75 -75
  11. package/fesm2015/hmcts-ccd-case-ui-toolkit.mjs.map +1 -1
  12. package/fesm2020/hmcts-ccd-case-ui-toolkit.mjs +75 -75
  13. package/fesm2020/hmcts-ccd-case-ui-toolkit.mjs.map +1 -1
  14. package/lib/shared/components/case-editor/case-edit/case-edit.component.d.ts +5 -2
  15. package/lib/shared/components/case-editor/case-edit/case-edit.component.d.ts.map +1 -1
  16. package/lib/shared/components/case-editor/case-event-completion/components/case-event-completion-task-reassigned/case-event-completion-task-reassigned.component.d.ts.map +1 -1
  17. package/lib/shared/components/case-editor/services/event-completion-state-machine.service.d.ts.map +1 -1
  18. package/lib/shared/components/case-editor/services/wizard-page-field-to-case-field.mapper.d.ts.map +1 -1
  19. package/lib/shared/components/palette/document/write-document-field.component.d.ts.map +1 -1
  20. package/lib/shared/pipes/complex/ccd-read-fields-filter.pipe.d.ts.map +1 -1
  21. package/lib/shared/pipes/complex/fields-filter.pipe.d.ts.map +1 -1
  22. package/lib/shared/services/fields/fields.utils.d.ts +1 -0
  23. package/lib/shared/services/fields/fields.utils.d.ts.map +1 -1
  24. package/package.json +1 -1
@@ -3239,6 +3239,11 @@ class WorkbasketInput {
3239
3239
 
3240
3240
  // @dynamic
3241
3241
  class FieldsUtils {
3242
+ static isValidDisplayContext(ctx) {
3243
+ return (ctx === 'MANDATORY' || ctx === 'READONLY'
3244
+ || ctx === 'OPTIONAL' || ctx === 'HIDDEN'
3245
+ || ctx === 'COMPLEX');
3246
+ }
3242
3247
  static convertToCaseField(obj) {
3243
3248
  if (!(obj instanceof CaseField)) {
3244
3249
  return plainToClassFromExist(new CaseField(), obj);
@@ -5435,7 +5440,7 @@ class FormValueService {
5435
5440
  // Retain anything that is readonly and not a label.
5436
5441
  continue;
5437
5442
  }
5438
- if (field.hidden === true && field.display_context !== 'HIDDEN' && field.id !== 'caseLinks' && !field.retain_hidden_value) {
5443
+ if (field.hidden === true && field.display_context !== 'HIDDEN' && field.display_context !== 'HIDDEN_TEMP' && field.id !== 'caseLinks' && !field.retain_hidden_value) {
5439
5444
  // Delete anything that is hidden (that is NOT readonly), and that
5440
5445
  // hasn't had its display_context overridden to make it hidden.
5441
5446
  delete data[field.id];
@@ -7269,7 +7274,8 @@ class WizardPageFieldToCaseFieldMapper {
7269
7274
  childrenCaseFields.forEach(e => this.hideParentIfAllChildrenHidden(e));
7270
7275
  if (childrenCaseFields.length > 0 && this.allCaseFieldsHidden(childrenCaseFields)) {
7271
7276
  caseField.hidden = true;
7272
- caseField.display_context = 'HIDDEN';
7277
+ // marking display_context as special hidden so field not being deleted in event submission
7278
+ caseField.display_context = 'HIDDEN_TEMP';
7273
7279
  }
7274
7280
  }
7275
7281
  getCaseFieldChildren(caseField) {
@@ -7283,7 +7289,7 @@ class WizardPageFieldToCaseFieldMapper {
7283
7289
  return childrenCaseFields;
7284
7290
  }
7285
7291
  allCaseFieldsHidden(children) {
7286
- return !children.some(e => e.hidden !== true);
7292
+ return children.every(e => e.display_context === 'HIDDEN' || e.display_context === 'HIDDEN_TEMP');
7287
7293
  }
7288
7294
  }
7289
7295
  WizardPageFieldToCaseFieldMapper.ɵfac = function WizardPageFieldToCaseFieldMapper_Factory(t) { return new (t || WizardPageFieldToCaseFieldMapper)(); };
@@ -8043,18 +8049,9 @@ class EventCompletionStateMachineService {
8043
8049
  state.trigger(EventCompletionStates.Final);
8044
8050
  const taskStr = context.sessionStorageService.getItem('taskToComplete');
8045
8051
  if (taskStr) {
8046
- // Task is in session storage
8047
- const task = JSON.parse(taskStr);
8048
- // Task already assigned to current user, just complete task
8049
- context.workAllocationService.completeTask(task.id).subscribe(response => {
8050
- // Emit event can be completed event
8051
- context.component.eventCanBeCompleted.emit(true);
8052
- }, error => {
8053
- // Emit event cannot be completed event
8054
- context.component.eventCanBeCompleted.emit(false);
8055
- context.alertService.error(error.message);
8056
- return throwError(error);
8057
- });
8052
+ context.sessionStorageService.setItem('assignNeeded', 'false');
8053
+ // just set event can be completed
8054
+ context.component.eventCanBeCompleted.emit(true);
8058
8055
  }
8059
8056
  else {
8060
8057
  // Emit event cannot be completed event
@@ -8073,18 +8070,8 @@ class EventCompletionStateMachineService {
8073
8070
  // Get task details
8074
8071
  const taskStr = context.sessionStorageService.getItem('taskToComplete');
8075
8072
  if (taskStr) {
8076
- // Task is in session storage
8077
- const task = JSON.parse(taskStr);
8078
- // Assign and complete task
8079
- context.workAllocationService.assignAndCompleteTask(task.id).subscribe(response => {
8080
- // Emit event can be completed event
8081
- context.component.eventCanBeCompleted.emit(true);
8082
- }, error => {
8083
- // Emit event cannot be completed event
8084
- context.component.eventCanBeCompleted.emit(false);
8085
- context.alertService.error(error.message);
8086
- return throwError(error);
8087
- });
8073
+ context.sessionStorageService.setItem('assignNeeded', 'true');
8074
+ context.component.eventCanBeCompleted.emit(true);
8088
8075
  }
8089
8076
  else {
8090
8077
  // Emit event cannot be completed event
@@ -8430,7 +8417,7 @@ ValidPageListCaseFieldsService.ɵprov = /*@__PURE__*/ i0.ɵɵdefineInjectable({
8430
8417
  }], function () { return [{ type: FieldsUtils }]; }, null); })();
8431
8418
 
8432
8419
  class CaseEditComponent {
8433
- constructor(fb, caseNotifier, router, route, fieldsUtils, fieldsPurger, registrarService, wizardFactory, sessionStorageService, windowsService, formValueService, formErrorService, loadingService, validPageListCaseFieldsService) {
8420
+ constructor(fb, caseNotifier, router, route, fieldsUtils, fieldsPurger, registrarService, wizardFactory, sessionStorageService, windowsService, formValueService, formErrorService, loadingService, validPageListCaseFieldsService, workAllocationService) {
8434
8421
  this.fb = fb;
8435
8422
  this.caseNotifier = caseNotifier;
8436
8423
  this.router = router;
@@ -8445,6 +8432,7 @@ class CaseEditComponent {
8445
8432
  this.formErrorService = formErrorService;
8446
8433
  this.loadingService = loadingService;
8447
8434
  this.validPageListCaseFieldsService = validPageListCaseFieldsService;
8435
+ this.workAllocationService = workAllocationService;
8448
8436
  this.cancelled = new EventEmitter();
8449
8437
  this.submitted = new EventEmitter();
8450
8438
  this.isEventCompletionChecksRequired = false;
@@ -8731,31 +8719,60 @@ class CaseEditComponent {
8731
8719
  }
8732
8720
  caseSubmit({ form, caseEventData, submit }) {
8733
8721
  const loadingSpinnerToken = this.loadingService.register();
8734
- submit(caseEventData)
8735
- .pipe(finalize(() => {
8722
+ // keep the initial event response to finalise process after task completion
8723
+ let eventResponse;
8724
+ submit(caseEventData).pipe(switchMap((response) => {
8725
+ eventResponse = response;
8726
+ return this.postCompleteTaskIfRequired();
8727
+ }), finalize(() => {
8736
8728
  this.loadingService.unregister(loadingSpinnerToken);
8737
8729
  }))
8738
- .subscribe(response => {
8739
- this.caseNotifier.cachedCaseView = null;
8740
- this.sessionStorageService.removeItem('eventUrl');
8741
- const confirmation = this.buildConfirmation(response);
8742
- if (confirmation && (confirmation.getHeader() || confirmation.getBody())) {
8743
- this.confirm(confirmation);
8730
+ .subscribe(() => {
8731
+ this.finishEventCompletionLogic(eventResponse);
8732
+ }, error => {
8733
+ if (!eventResponse) {
8734
+ // event submission error
8735
+ this.error = error;
8736
+ this.callbackErrorsSubject.next(error);
8737
+ /* istanbul ignore else */
8738
+ if (this.error.details) {
8739
+ this.formErrorService
8740
+ .mapFieldErrors(this.error.details.field_errors, form.controls['data'], 'validation');
8741
+ }
8742
+ this.isSubmitting = false;
8744
8743
  }
8745
8744
  else {
8746
- this.emitSubmitted(response);
8745
+ // task assignment/completion error - handled within workallocation service
8746
+ // could set task to be deleted (or completed later)?
8747
+ // note: think error messages only shown if user is caseworker - might reqauire changing
8748
+ this.finishEventCompletionLogic(eventResponse);
8747
8749
  }
8748
- }, error => {
8749
- this.error = error;
8750
- this.callbackErrorsSubject.next(error);
8751
- /* istanbul ignore else */
8752
- if (this.error.details) {
8753
- this.formErrorService
8754
- .mapFieldErrors(this.error.details.field_errors, form.controls['data'], 'validation');
8755
- }
8756
- this.isSubmitting = false;
8757
8750
  });
8758
8751
  }
8752
+ postCompleteTaskIfRequired() {
8753
+ const taskStr = this.sessionStorageService.getItem('taskToComplete');
8754
+ const assignNeeded = this.sessionStorageService.getItem('assignNeeded') === 'true';
8755
+ if (taskStr && assignNeeded) {
8756
+ const task = JSON.parse(taskStr);
8757
+ return this.workAllocationService.assignAndCompleteTask(task.id);
8758
+ }
8759
+ else if (taskStr) {
8760
+ const task = JSON.parse(taskStr);
8761
+ return this.workAllocationService.completeTask(task.id);
8762
+ }
8763
+ return of(true);
8764
+ }
8765
+ finishEventCompletionLogic(eventResponse) {
8766
+ this.caseNotifier.cachedCaseView = null;
8767
+ this.sessionStorageService.removeItem('eventUrl');
8768
+ const confirmation = this.buildConfirmation(eventResponse);
8769
+ if (confirmation && (confirmation.getHeader() || confirmation.getBody())) {
8770
+ this.confirm(confirmation);
8771
+ }
8772
+ else {
8773
+ this.emitSubmitted(eventResponse);
8774
+ }
8775
+ }
8759
8776
  buildConfirmation(response) {
8760
8777
  if (response['after_submit_callback_response']) {
8761
8778
  return new Confirmation(response['id'], response['callback_response_status'], response['after_submit_callback_response']['confirmation_header'], response['after_submit_callback_response']['confirmation_body']);
@@ -8784,14 +8801,14 @@ class CaseEditComponent {
8784
8801
  }
8785
8802
  CaseEditComponent.ORIGIN_QUERY_PARAM = 'origin';
8786
8803
  CaseEditComponent.ALERT_MESSAGE = 'Page is being refreshed so you will be redirected to the first page of this event.';
8787
- CaseEditComponent.ɵfac = function CaseEditComponent_Factory(t) { return new (t || CaseEditComponent)(i0.ɵɵdirectiveInject(i3.FormBuilder), i0.ɵɵdirectiveInject(CaseNotifier), i0.ɵɵdirectiveInject(i1$2.Router), i0.ɵɵdirectiveInject(i1$2.ActivatedRoute), i0.ɵɵdirectiveInject(FieldsUtils), i0.ɵɵdirectiveInject(FieldsPurger), i0.ɵɵdirectiveInject(ConditionalShowRegistrarService), i0.ɵɵdirectiveInject(WizardFactoryService), i0.ɵɵdirectiveInject(SessionStorageService), i0.ɵɵdirectiveInject(WindowService), i0.ɵɵdirectiveInject(FormValueService), i0.ɵɵdirectiveInject(FormErrorService), i0.ɵɵdirectiveInject(LoadingService), i0.ɵɵdirectiveInject(ValidPageListCaseFieldsService)); };
8804
+ CaseEditComponent.ɵfac = function CaseEditComponent_Factory(t) { return new (t || CaseEditComponent)(i0.ɵɵdirectiveInject(i3.FormBuilder), i0.ɵɵdirectiveInject(CaseNotifier), i0.ɵɵdirectiveInject(i1$2.Router), i0.ɵɵdirectiveInject(i1$2.ActivatedRoute), i0.ɵɵdirectiveInject(FieldsUtils), i0.ɵɵdirectiveInject(FieldsPurger), i0.ɵɵdirectiveInject(ConditionalShowRegistrarService), i0.ɵɵdirectiveInject(WizardFactoryService), i0.ɵɵdirectiveInject(SessionStorageService), i0.ɵɵdirectiveInject(WindowService), i0.ɵɵdirectiveInject(FormValueService), i0.ɵɵdirectiveInject(FormErrorService), i0.ɵɵdirectiveInject(LoadingService), i0.ɵɵdirectiveInject(ValidPageListCaseFieldsService), i0.ɵɵdirectiveInject(WorkAllocationService)); };
8788
8805
  CaseEditComponent.ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: CaseEditComponent, selectors: [["ccd-case-edit"]], inputs: { eventTrigger: "eventTrigger", submit: "submit", validate: "validate", saveDraft: "saveDraft", caseDetails: "caseDetails" }, outputs: { cancelled: "cancelled", submitted: "submitted" }, features: [i0.ɵɵProvidersFeature([GreyBarService])], decls: 1, vars: 0, template: function CaseEditComponent_Template(rf, ctx) { if (rf & 1) {
8789
8806
  i0.ɵɵelement(0, "router-outlet");
8790
8807
  } }, dependencies: [i1$2.RouterOutlet], styles: ["#fieldset-case-data[_ngcontent-%COMP%]{margin-bottom:30px}#fieldset-case-data[_ngcontent-%COMP%] th[_ngcontent-%COMP%]{width:1%;white-space:nowrap;vertical-align:top}.compound-field[_ngcontent-%COMP%] td[_ngcontent-%COMP%]{padding:0}#confirmation-header[_ngcontent-%COMP%]{width:630px;background-color:#17958b;border:solid 1px #979797;color:#fff;text-align:center}#confirmation-body[_ngcontent-%COMP%]{width:630px;background-color:#fff}.valign-top[_ngcontent-%COMP%]{vertical-align:top}.summary-fields[_ngcontent-%COMP%]{margin-bottom:30px}.summary-fields[_ngcontent-%COMP%] tbody[_ngcontent-%COMP%] tr[_ngcontent-%COMP%] th[_ngcontent-%COMP%], .summary-fields[_ngcontent-%COMP%] tbody[_ngcontent-%COMP%] tr[_ngcontent-%COMP%] td[_ngcontent-%COMP%]{border-bottom:0px}a.disabled[_ngcontent-%COMP%]{pointer-events:none;cursor:default}.case-field-label[_ngcontent-%COMP%]{width:45%}.case-field-content[_ngcontent-%COMP%]{width:50%}.case-field-change[_ngcontent-%COMP%]{width:5%}"] });
8791
8808
  (function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(CaseEditComponent, [{
8792
8809
  type: Component,
8793
8810
  args: [{ selector: 'ccd-case-edit', providers: [GreyBarService], template: "<router-outlet></router-outlet>\n", styles: ["#fieldset-case-data{margin-bottom:30px}#fieldset-case-data th{width:1%;white-space:nowrap;vertical-align:top}.compound-field td{padding:0}#confirmation-header{width:630px;background-color:#17958b;border:solid 1px #979797;color:#fff;text-align:center}#confirmation-body{width:630px;background-color:#fff}.valign-top{vertical-align:top}.summary-fields{margin-bottom:30px}.summary-fields tbody tr th,.summary-fields tbody tr td{border-bottom:0px}a.disabled{pointer-events:none;cursor:default}.case-field-label{width:45%}.case-field-content{width:50%}.case-field-change{width:5%}\n"] }]
8794
- }], function () { return [{ type: i3.FormBuilder }, { type: CaseNotifier }, { type: i1$2.Router }, { type: i1$2.ActivatedRoute }, { type: FieldsUtils }, { type: FieldsPurger }, { type: ConditionalShowRegistrarService }, { type: WizardFactoryService }, { type: SessionStorageService }, { type: WindowService }, { type: FormValueService }, { type: FormErrorService }, { type: LoadingService }, { type: ValidPageListCaseFieldsService }]; }, { eventTrigger: [{
8811
+ }], function () { return [{ type: i3.FormBuilder }, { type: CaseNotifier }, { type: i1$2.Router }, { type: i1$2.ActivatedRoute }, { type: FieldsUtils }, { type: FieldsPurger }, { type: ConditionalShowRegistrarService }, { type: WizardFactoryService }, { type: SessionStorageService }, { type: WindowService }, { type: FormValueService }, { type: FormErrorService }, { type: LoadingService }, { type: ValidPageListCaseFieldsService }, { type: WorkAllocationService }]; }, { eventTrigger: [{
8795
8812
  type: Input
8796
8813
  }], submit: [{
8797
8814
  type: Input
@@ -10146,7 +10163,9 @@ class FieldsFilterPipe {
10146
10163
  .filter(f => keepEmpty || FieldsFilterPipe.keepField(f))
10147
10164
  .map(f => {
10148
10165
  if (!f.display_context) {
10149
- f.display_context = complexField.display_context;
10166
+ if (FieldsUtils.isValidDisplayContext(complexField.display_context)) {
10167
+ f.display_context = complexField.display_context;
10168
+ }
10150
10169
  }
10151
10170
  return f;
10152
10171
  });
@@ -12689,19 +12708,7 @@ class WriteDocumentFieldComponent extends AbstractFieldWriteComponent {
12689
12708
  if (0 === error.status || 502 === error.status) {
12690
12709
  return WriteDocumentFieldComponent.UPLOAD_ERROR_NOT_AVAILABLE;
12691
12710
  }
12692
- let errorMsg = 'Error uploading file';
12693
- if (error && error?.error) {
12694
- const fullError = error.error;
12695
- const start = fullError.indexOf('{');
12696
- if (start >= 0) {
12697
- const json = fullError.substring(start, fullError.length - 1).split('<EOL>').join('');
12698
- const obj = JSON.parse(json);
12699
- if (obj && obj?.error) {
12700
- errorMsg = obj.error;
12701
- }
12702
- }
12703
- }
12704
- return errorMsg;
12711
+ return error.error;
12705
12712
  }
12706
12713
  buildDocumentUploadData(selectedFile) {
12707
12714
  const documentUpload = new FormData();
@@ -22005,7 +22012,9 @@ class ReadFieldsFilterPipe {
22005
22012
  })
22006
22013
  .map(f => {
22007
22014
  if (!f.display_context) {
22008
- f.display_context = complexField.display_context;
22015
+ if (FieldsUtils.isValidDisplayContext(complexField.display_context)) {
22016
+ f.display_context = complexField.display_context;
22017
+ }
22009
22018
  }
22010
22019
  if (setupHidden) {
22011
22020
  ReadFieldsFilterPipe.evaluateConditionalShow(f, checkConditionalShowAgainst, path, formGroupAvailable, complexField.id);
@@ -23700,18 +23709,9 @@ class CaseEventCompletionTaskReassignedComponent {
23700
23709
  // Get task details
23701
23710
  const taskStr = this.sessionStorageService.getItem('taskToComplete');
23702
23711
  if (taskStr) {
23703
- // Task is in session storage
23704
- const task = JSON.parse(taskStr);
23705
- // Assign and complete task
23706
- this.subscription = this.workAllocationService.assignAndCompleteTask(task.id).subscribe(response => {
23707
- // Emit event can be completed event
23708
- this.parentComponent.eventCanBeCompleted.emit(true);
23709
- }, error => {
23710
- // Emit event cannot be completed event
23711
- this.parentComponent.eventCanBeCompleted.emit(false);
23712
- this.alertService.error(error.message);
23713
- return throwError(error);
23714
- });
23712
+ this.sessionStorageService.setItem('assignNeeded', 'true');
23713
+ // set event can be completed to true
23714
+ this.parentComponent.eventCanBeCompleted.emit(true);
23715
23715
  }
23716
23716
  else {
23717
23717
  // Emit event cannot be completed event