@hmcts/ccd-case-ui-toolkit 6.16.2-ccpay-5.2.8 → 6.16.2-ccpay-upgrade

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.
@@ -4124,18 +4124,39 @@
4124
4124
  }
4125
4125
  return this.isFlagsFieldType(caseField.field_type);
4126
4126
  };
4127
+ /**
4128
+ * @deprecated Use {@link isCaseFieldOfType} instead, passing 'FlagLauncher' as the single type in the `types` array
4129
+ */
4127
4130
  FieldsUtils.isFlagLauncherCaseField = function (caseField) {
4128
4131
  if (!caseField) {
4129
4132
  return false;
4130
4133
  }
4131
4134
  return caseField.field_type.type === 'FlagLauncher';
4132
4135
  };
4136
+ /**
4137
+ * @deprecated Use {@link isCaseFieldOfType} instead, passing 'ComponentLauncher' as the single type in the `types`
4138
+ * array
4139
+ */
4133
4140
  FieldsUtils.isComponentLauncherCaseField = function (caseField) {
4134
4141
  if (!caseField) {
4135
4142
  return false;
4136
4143
  }
4137
4144
  return caseField.field_type.type === 'ComponentLauncher';
4138
4145
  };
4146
+ /**
4147
+ * Checks if a {@link CaseField} is of one of the given field types.
4148
+ *
4149
+ * @param caseField The `CaseField` to check
4150
+ * @param types An array of one or more field types
4151
+ * @returns `true` if the `CaseField` type is one of those in the array of types to check against; `false`
4152
+ * otherwise or if `caseField` or `types` are falsy
4153
+ */
4154
+ FieldsUtils.isCaseFieldOfType = function (caseField, types) {
4155
+ if (!caseField || !types) {
4156
+ return false;
4157
+ }
4158
+ return types.some(function (type) { return type === caseField.field_type.type; });
4159
+ };
4139
4160
  FieldsUtils.isLinkedCasesCaseField = function (caseField) {
4140
4161
  return FieldsUtils.isComponentLauncherCaseField(caseField) &&
4141
4162
  caseField.id === 'LinkedCasesComponentLauncher';
@@ -6323,65 +6344,70 @@
6323
6344
  }
6324
6345
  };
6325
6346
  /**
6326
- * Remove the FlagLauncher case field, which is not intended to be persisted.
6347
+ * Remove from the top level of the form data any case fields of a given type or types that are not intended to be
6348
+ * persisted. This function is intended to remove "special" case field types from the data, such as FlagLauncher or
6349
+ * ComponentLauncher fields.
6327
6350
  *
6328
- * @param data The object tree of form values on which to perform the removal
6351
+ * @param data The object tree of form values on which to perform the removal at the top level only
6329
6352
  * @param caseFields The list of underlying {@link CaseField} domain model objects for each field
6353
+ * @param types An array of one or more field types
6330
6354
  */
6331
- FormValueService.prototype.removeFlagLauncherField = function (data, caseFields) {
6332
- if (data && caseFields && caseFields.length > 0) {
6333
- var flagLauncherCaseField = caseFields.filter(function (caseField) { return FieldsUtils.isFlagLauncherCaseField(caseField); });
6334
- if (flagLauncherCaseField.length > 0) {
6335
- // There should be only one FlagLauncher case field
6336
- delete data[flagLauncherCaseField[0].id];
6355
+ FormValueService.prototype.removeCaseFieldsOfType = function (data, caseFields, types) {
6356
+ var e_12, _a;
6357
+ if (data && caseFields && caseFields.length > 0 && types.length > 0) {
6358
+ var caseFieldsToRemove = caseFields.filter(function (caseField) { return FieldsUtils.isCaseFieldOfType(caseField, types); });
6359
+ try {
6360
+ for (var caseFieldsToRemove_1 = __values(caseFieldsToRemove), caseFieldsToRemove_1_1 = caseFieldsToRemove_1.next(); !caseFieldsToRemove_1_1.done; caseFieldsToRemove_1_1 = caseFieldsToRemove_1.next()) {
6361
+ var caseField = caseFieldsToRemove_1_1.value;
6362
+ delete data[caseField.id];
6363
+ }
6364
+ }
6365
+ catch (e_12_1) { e_12 = { error: e_12_1 }; }
6366
+ finally {
6367
+ try {
6368
+ if (caseFieldsToRemove_1_1 && !caseFieldsToRemove_1_1.done && (_a = caseFieldsToRemove_1.return)) _a.call(caseFieldsToRemove_1);
6369
+ }
6370
+ finally { if (e_12) throw e_12.error; }
6337
6371
  }
6338
6372
  }
6339
6373
  };
6340
6374
  /**
6341
- * Populate the flag data for each Flags field, from the data held in its corresponding CaseField.
6375
+ * Re-populate the form data from the values held in the case fields. This is necessary in order to pick up, for
6376
+ * each `Flags` field, any flag details data not currently present.
6377
+ *
6378
+ * `Flags` fields may be contained in other `CaseField` instances, either as a sub-field of a Complex field, or
6379
+ * fields in a collection (or sub-fields of Complex fields in a collection). Therefore, it is necessary to
6380
+ * iterate through all `CaseField`s.
6342
6381
  *
6343
6382
  * @param data The object tree of form values on which to perform the data population
6344
6383
  * @param caseFields The list of underlying {@link CaseField} domain model objects for each field
6345
6384
  */
6346
- FormValueService.prototype.populateFlagDetailsFromCaseFields = function (data, caseFields) {
6347
- if (data && caseFields && caseFields.length > 0) {
6348
- // Cannot filter out anything other than to remove the FlagLauncher CaseField because Flags fields may be
6349
- // contained in other CaseField instances, either as a sub-field of a Complex field, or fields in a collection
6350
- // (or sub-fields of Complex fields in a collection)
6351
- caseFields.filter(function (caseField) { return !FieldsUtils.isFlagLauncherCaseField(caseField); })
6385
+ FormValueService.prototype.repopulateFormDataFromCaseFieldValues = function (data, caseFields) {
6386
+ if (data && caseFields && caseFields.length > 0 &&
6387
+ caseFields.findIndex(function (caseField) { return FieldsUtils.isCaseFieldOfType(caseField, ['FlagLauncher']); }) > -1) {
6388
+ // Ignore the FlagLauncher CaseField because it does not hold any values
6389
+ caseFields.filter(function (caseField) { return !FieldsUtils.isCaseFieldOfType(caseField, ['FlagLauncher']); })
6352
6390
  .forEach(function (caseField) {
6353
- // Ensure that the data object is populated for all case field IDs it contains, even if there is currently
6354
- // nothing for a given case field ID (hence the use of hasOwnProperty())
6391
+ // Ensure that the data object is populated for all CaseField keys it contains, even if for a given
6392
+ // CaseField key, the data object has a falsy value (hence the use of hasOwnProperty() for the check below)
6393
+ // See https://tools.hmcts.net/jira/browse/EUI-7377
6355
6394
  if (data.hasOwnProperty(caseField.id) && caseField.value) {
6356
- // Create new object for the case field ID within the data object, if necessary
6357
- if (data[caseField.id]) {
6358
- // Copy all values from the corresponding CaseField; this ensures all nested flag data (for example, a
6359
- // Flags field within a Complex field or a collection of Complex fields) is copied across
6360
- Object.keys(data[caseField.id]).forEach(function (key) {
6361
- if (caseField.value.hasOwnProperty(key)) {
6362
- data[caseField.id][key] = caseField.value[key];
6363
- }
6364
- });
6395
+ // Create new object for the CaseField ID within the data object, if necessary (i.e. if the current value
6396
+ // is falsy)
6397
+ if (!data[caseField.id]) {
6398
+ data[caseField.id] = {};
6365
6399
  }
6400
+ // Copy all values from the corresponding CaseField; this ensures all nested flag data (for example, a
6401
+ // Flags field within a Complex field or a collection of Complex fields) is copied across
6402
+ Object.keys(data[caseField.id]).forEach(function (key) {
6403
+ if (caseField.value.hasOwnProperty(key)) {
6404
+ data[caseField.id][key] = caseField.value[key];
6405
+ }
6406
+ });
6366
6407
  }
6367
6408
  });
6368
6409
  }
6369
6410
  };
6370
- /**
6371
- * Remove the ComponentLauncher case field, which is not intended to be persisted.
6372
- *
6373
- * @param data The object tree of form values on which to perform the removal
6374
- * @param caseFields The list of underlying {@link CaseField} domain model objects for each field
6375
- */
6376
- FormValueService.prototype.removeComponentLauncherField = function (data, caseFields) {
6377
- if (data && caseFields && caseFields.length > 0) {
6378
- var componentLauncherCaseField = caseFields.filter(function (caseField) { return FieldsUtils.isComponentLauncherCaseField(caseField); });
6379
- if (componentLauncherCaseField.length > 0) {
6380
- // There should be only one ComponentLauncher case field
6381
- delete data[componentLauncherCaseField[0].id];
6382
- }
6383
- }
6384
- };
6385
6411
  /**
6386
6412
  * Populate the linked cases from the data held in its corresponding CaseField.
6387
6413
  *
@@ -6390,7 +6416,7 @@
6390
6416
  */
6391
6417
  FormValueService.prototype.populateLinkedCasesDetailsFromCaseFields = function (data, caseFields) {
6392
6418
  if (data && caseFields && caseFields.length > 0) {
6393
- caseFields.filter(function (caseField) { return !FieldsUtils.isComponentLauncherCaseField(caseField); })
6419
+ caseFields.filter(function (caseField) { return !FieldsUtils.isCaseFieldOfType(caseField, ['ComponentLauncher']); })
6394
6420
  .forEach(function (caseField) {
6395
6421
  if (data.hasOwnProperty('caseLinks') && caseField.value) {
6396
6422
  data[caseField.id] = caseField.value;
@@ -9614,7 +9640,9 @@
9614
9640
  form: this.form,
9615
9641
  });
9616
9642
  /* istanbul ignore else */
9617
- if (!nextPage && !this.eventTrigger.show_summary && !this.eventTrigger.show_event_notes) {
9643
+ if (!nextPage &&
9644
+ !(this.eventTrigger.show_summary || this.eventTrigger.show_summary === null) &&
9645
+ !this.eventTrigger.show_event_notes) {
9618
9646
  this.submitForm({
9619
9647
  eventTrigger: this.eventTrigger,
9620
9648
  form: this.form,
@@ -9706,16 +9734,13 @@
9706
9734
  // Remove collection fields that have "min" validation of greater than zero set on the FieldType but are empty;
9707
9735
  // these will fail validation
9708
9736
  this.formValueService.removeEmptyCollectionsWithMinValidation(caseEventData.data, eventTrigger.case_fields);
9709
- // If this is a Case Flag submission (and thus a FlagLauncher field is present in the event trigger), the flag
9710
- // details data needs populating for each Flags field, then the FlagLauncher field needs removing
9711
- if (this.isCaseFlagSubmission) {
9712
- this.formValueService.populateFlagDetailsFromCaseFields(caseEventData.data, eventTrigger.case_fields);
9713
- this.formValueService.removeFlagLauncherField(caseEventData.data, eventTrigger.case_fields);
9714
- }
9715
- if (this.isLinkedCasesSubmission) {
9716
- this.formValueService.populateLinkedCasesDetailsFromCaseFields(caseEventData.data, eventTrigger.case_fields);
9717
- this.formValueService.removeComponentLauncherField(caseEventData.data, eventTrigger.case_fields);
9718
- }
9737
+ // For Case Flag submissions (where a FlagLauncher field is present in the event trigger), the flag details data
9738
+ // needs populating for each Flags field, then the FlagLauncher field needs removing
9739
+ this.formValueService.repopulateFormDataFromCaseFieldValues(caseEventData.data, eventTrigger.case_fields);
9740
+ // Data population step required for Linked Cases
9741
+ this.formValueService.populateLinkedCasesDetailsFromCaseFields(caseEventData.data, eventTrigger.case_fields);
9742
+ // Remove "Launcher"-type fields (these have no values and are not intended to be persisted)
9743
+ this.formValueService.removeCaseFieldsOfType(caseEventData.data, eventTrigger.case_fields, ['FlagLauncher', 'ComponentLauncher']);
9719
9744
  caseEventData.event_token = eventTrigger.event_token;
9720
9745
  caseEventData.ignore_warning = this.ignoreWarning;
9721
9746
  if (this.confirmation) {
@@ -9837,8 +9862,7 @@
9837
9862
  _this.sessionStorageService.removeItem('eventUrl');
9838
9863
  var confirmation = _this.buildConfirmation(response);
9839
9864
  if (confirmation && (confirmation.getHeader() || confirmation.getBody())) {
9840
- // Add finally to fix sonar bug
9841
- _this.confirm(confirmation).finally();
9865
+ _this.confirm(confirmation);
9842
9866
  }
9843
9867
  else {
9844
9868
  _this.emitSubmitted(response);
@@ -26788,9 +26812,10 @@
26788
26812
  this.contextFields = this.getCaseFields();
26789
26813
  // Indicates if the submission is for a Case Flag, as opposed to a "regular" form submission, by the presence of
26790
26814
  // a FlagLauncher field in the event trigger
26791
- this.caseEdit.isCaseFlagSubmission = this.eventTrigger.case_fields.some(function (caseField) { return FieldsUtils.isFlagLauncherCaseField(caseField); });
26815
+ this.caseEdit.isCaseFlagSubmission =
26816
+ this.eventTrigger.case_fields.some(function (caseField) { return FieldsUtils.isCaseFieldOfType(caseField, ['FlagLauncher']); });
26792
26817
  this.caseEdit.isLinkedCasesSubmission =
26793
- this.eventTrigger.case_fields.some(function (caseField) { return FieldsUtils.isComponentLauncherCaseField(caseField); });
26818
+ this.eventTrigger.case_fields.some(function (caseField) { return FieldsUtils.isCaseFieldOfType(caseField, ['ComponentLauncher']); });
26794
26819
  this.pageTitle = this.caseEdit.isCaseFlagSubmission ? 'Review flag details' : 'Check your answers';
26795
26820
  };
26796
26821
  CaseEditSubmitComponent.prototype.ngOnDestroy = function () {
@@ -26863,49 +26888,50 @@
26863
26888
  CaseEditSubmitComponent.prototype.checkYourAnswerFieldsToDisplayExists = function () {
26864
26889
  var e_1, _d, e_2, _e;
26865
26890
  /* istanbul ignore else */
26866
- if (!this.eventTrigger.show_summary) {
26867
- return false;
26868
- }
26869
- try {
26870
- for (var _f = __values(this.wizard.pages), _g = _f.next(); !_g.done; _g = _f.next()) {
26871
- var page = _g.value;
26872
- /* istanbul ignore else */
26873
- if (this.isShown(page)) {
26874
- try {
26875
- for (var _h = (e_2 = void 0, __values(page.case_fields)), _j = _h.next(); !_j.done; _j = _h.next()) {
26876
- var field = _j.value;
26877
- /* istanbul ignore else */
26878
- if (this.canShowFieldInCYA(field)) {
26879
- // at least one field needs showing
26880
- return true;
26891
+ if (this.eventTrigger.show_summary || this.eventTrigger.show_summary === null) {
26892
+ try {
26893
+ for (var _f = __values(this.wizard.pages), _g = _f.next(); !_g.done; _g = _f.next()) {
26894
+ var page = _g.value;
26895
+ /* istanbul ignore else */
26896
+ if (page.case_fields && this.isShown(page)) {
26897
+ try {
26898
+ for (var _h = (e_2 = void 0, __values(page.case_fields)), _j = _h.next(); !_j.done; _j = _h.next()) {
26899
+ var field = _j.value;
26900
+ /* istanbul ignore else */
26901
+ if (this.canShowFieldInCYA(field)) {
26902
+ // at least one field needs showing
26903
+ return true;
26904
+ }
26881
26905
  }
26882
26906
  }
26883
- }
26884
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
26885
- finally {
26886
- try {
26887
- if (_j && !_j.done && (_e = _h.return)) _e.call(_h);
26907
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
26908
+ finally {
26909
+ try {
26910
+ if (_j && !_j.done && (_e = _h.return)) _e.call(_h);
26911
+ }
26912
+ finally { if (e_2) throw e_2.error; }
26888
26913
  }
26889
- finally { if (e_2) throw e_2.error; }
26890
26914
  }
26891
26915
  }
26892
26916
  }
26893
- }
26894
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
26895
- finally {
26896
- try {
26897
- if (_g && !_g.done && (_d = _f.return)) _d.call(_f);
26917
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
26918
+ finally {
26919
+ try {
26920
+ if (_g && !_g.done && (_d = _f.return)) _d.call(_f);
26921
+ }
26922
+ finally { if (e_1) throw e_1.error; }
26898
26923
  }
26899
- finally { if (e_1) throw e_1.error; }
26900
26924
  }
26901
- // found no fields to show in CYA summary page
26902
- return false;
26925
+ else {
26926
+ // found no fields to show in CYA summary page
26927
+ return false;
26928
+ }
26903
26929
  };
26904
26930
  CaseEditSubmitComponent.prototype.readOnlySummaryFieldsToDisplayExists = function () {
26905
26931
  return this.eventTrigger.case_fields.some(function (field) { return field.show_summary_content_option >= 0; });
26906
26932
  };
26907
26933
  CaseEditSubmitComponent.prototype.showEventNotes = function () {
26908
- return this.eventTrigger.show_event_notes === true;
26934
+ return !!this.eventTrigger.show_event_notes;
26909
26935
  };
26910
26936
  CaseEditSubmitComponent.prototype.getLastPageShown = function () {
26911
26937
  var _this = this;