@hmcts/ccd-case-ui-toolkit 7.3.74 → 7.3.75-case-search

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.
@@ -8123,6 +8123,9 @@ class RequestOptionsBuilder {
8123
8123
  * @param value The value to be assessed.
8124
8124
  */
8125
8125
  static includeParam(value) {
8126
+ if (Array.isArray(value)) {
8127
+ return value.some(item => RequestOptionsBuilder.includeParam(item));
8128
+ }
8126
8129
  /* istanbul ignore else */
8127
8130
  if (value) {
8128
8131
  /* istanbul ignore else */
@@ -8133,6 +8136,36 @@ class RequestOptionsBuilder {
8133
8136
  }
8134
8137
  return false;
8135
8138
  }
8139
+ static sanitiseValue(value) {
8140
+ const trimmedValue = value.trim ? value.trim() : value;
8141
+ return trimmedValue.replace ? trimmedValue.replace(/’/i, `'`) : trimmedValue;
8142
+ }
8143
+ static getValueByPath(value, path) {
8144
+ return path.split('.').reduce((currentValue, pathPart) => {
8145
+ if (currentValue === undefined || currentValue === null) {
8146
+ return undefined;
8147
+ }
8148
+ return currentValue[pathPart];
8149
+ }, value);
8150
+ }
8151
+ static getCollectionValues(value, criterion) {
8152
+ if (!Array.isArray(value) ||
8153
+ !criterion.includes('.value.') ||
8154
+ value.some(item => item === null || typeof item !== 'object' || !Object.hasOwn(item, 'value'))) {
8155
+ return value;
8156
+ }
8157
+ const valuePath = criterion.substring(criterion.indexOf('.value.') + 1);
8158
+ return value.map(item => RequestOptionsBuilder.getValueByPath(item, valuePath));
8159
+ }
8160
+ static appendParam(params, key, value) {
8161
+ if (Array.isArray(value)) {
8162
+ const values = value
8163
+ .filter(item => RequestOptionsBuilder.includeParam(item))
8164
+ .map(item => RequestOptionsBuilder.sanitiseValue(item));
8165
+ return params.set(key, `[${values.join(', ')}]`);
8166
+ }
8167
+ return params.set(key, RequestOptionsBuilder.sanitiseValue(value));
8168
+ }
8136
8169
  buildOptions(metaCriteria, caseCriteria, view) {
8137
8170
  // TODO: This should probably be the now built-in URLSearchParams but it
8138
8171
  // requires a bigger refactor and there are bigger fish to fry right now.
@@ -8157,8 +8190,7 @@ class RequestOptionsBuilder {
8157
8190
  /* istanbul ignore else */
8158
8191
  if (RequestOptionsBuilder.includeParam(caseCriteria[criterion])) {
8159
8192
  const key = RequestOptionsBuilder.FIELD_PREFIX + criterion;
8160
- const value = caseCriteria[criterion].trim ? caseCriteria[criterion].trim() : caseCriteria[criterion];
8161
- params = params.set(key, value.replace(/’/i, `'`));
8193
+ params = RequestOptionsBuilder.appendParam(params, key, RequestOptionsBuilder.getCollectionValues(caseCriteria[criterion], criterion));
8162
8194
  }
8163
8195
  }
8164
8196
  }