@gravitee/ui-particles-angular 16.2.2-apim-11833-llm-proxy-ui-does-not-match-designs-748e778 → 16.2.2-apim-11833-llm-proxy-ui-does-not-match-designs-cce9907

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.
@@ -3175,64 +3175,32 @@ class GioFormlyJsonSchemaService {
3175
3175
  return mappedField;
3176
3176
  }
3177
3177
  uniqueValueMap(mappedField, mapSource) {
3178
- if (!mapSource.gioConfig?.unique) {
3179
- return mappedField;
3180
- }
3181
- mappedField.asyncValidators = {
3182
- ...mappedField.asyncValidators,
3183
- unique: {
3184
- expression: (control) => {
3185
- if (!control.value || control.value === '') {
3186
- return Promise.resolve(true); // Empty values are valid
3187
- }
3188
- let currentControl = control.parent;
3189
- let parentArrayControl = null;
3190
- while (currentControl) {
3191
- const value = currentControl.value;
3192
- if (isArray(value)) {
3193
- parentArrayControl = currentControl;
3194
- break;
3195
- }
3196
- currentControl = currentControl.parent;
3197
- }
3198
- if (!parentArrayControl) {
3199
- return Promise.resolve(true);
3200
- }
3201
- const controls = parentArrayControl.controls;
3202
- if (!controls || !isArray(controls) || controls.length <= 1) {
3203
- return Promise.resolve(true); // No duplicates possible
3204
- }
3205
- const fieldKey = mappedField.key;
3206
- const currentValue = control.value;
3207
- const occurrences = controls.filter((formGroup) => {
3208
- const siblingControl = fieldKey ? formGroup.get(fieldKey) : formGroup;
3209
- if (!siblingControl) {
3210
- return false;
3211
- }
3212
- const siblingValue = siblingControl.value;
3213
- if (isNil(siblingValue)) {
3214
- return false;
3215
- }
3216
- return siblingValue === currentValue;
3217
- }).length;
3218
- const isValid = occurrences <= 1;
3219
- if (isValid) {
3220
- setTimeout(() => {
3221
- controls.forEach((formGroup) => {
3222
- const siblingControl = fieldKey ? formGroup.get(fieldKey) : formGroup;
3223
- if (siblingControl && siblingControl !== control && siblingControl.hasError('unique')) {
3224
- siblingControl.updateValueAndValidity({ emitEvent: false });
3178
+ let fieldNameWithErrors = undefined;
3179
+ if (mapSource.gioConfig?.uniqueItemProperties) {
3180
+ mappedField = {
3181
+ ...mappedField,
3182
+ validators: {
3183
+ ...mappedField.validators,
3184
+ uniqueFields: {
3185
+ expression: (control) => {
3186
+ const items = control.value;
3187
+ const uniqueProps = mapSource.gioConfig?.uniqueItemProperties ?? [];
3188
+ if (!Array.isArray(items) || !uniqueProps.length)
3189
+ return true;
3190
+ for (const prop of uniqueProps) {
3191
+ const values = items.map(i => i?.[prop]).filter(v => v != null);
3192
+ if (new Set(values).size !== values.length) {
3193
+ fieldNameWithErrors = prop;
3194
+ return false;
3225
3195
  }
3226
- });
3227
- }, 0);
3228
- }
3229
- return Promise.resolve(isValid);
3230
- },
3231
- message: (error, field) => {
3232
- return `${field.props?.label} must be unique`;
3196
+ }
3197
+ return true;
3198
+ },
3199
+ message: (_error, _field) => `${fieldNameWithErrors || 'This field'} must be unique`,
3200
+ },
3233
3201
  },
3234
- },
3235
- };
3202
+ };
3203
+ }
3236
3204
  return mappedField;
3237
3205
  }
3238
3206
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.3", ngImport: i0, type: GioFormlyJsonSchemaService, deps: [{ token: i1$7.FormlyJsonschema }], target: i0.ɵɵFactoryTarget.Injectable }); }