@messaia/cdk 22.0.1-rc.25 → 22.0.1-rc.26

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.
@@ -1,11 +1,11 @@
1
1
  import * as i1$2 from '@angular/common';
2
2
  import { Location, getLocaleNumberSymbol, NumberSymbol, CommonModule, DecimalPipe, NgClass, JsonPipe } from '@angular/common';
3
3
  import * as i1$7 from '@angular/common/http';
4
- import { HttpHeaders, HttpParams, HttpClient, HttpRequest, HttpEventType, HttpResponse } from '@angular/common/http';
4
+ import { HttpErrorResponse, HttpHeaders, HttpParams, HttpClient, HttpRequest, HttpEventType, HttpResponse } from '@angular/common/http';
5
5
  import * as i0 from '@angular/core';
6
- import { Injectable, ChangeDetectionStrategy, Component, Directive, ContentChildren, Optional, SkipSelf, NgZone, InjectionToken, Inject, inject, ChangeDetectorRef, EventEmitter, ElementRef, ViewChildren, Output, Input, HostListener, forwardRef, LOCALE_ID, NgModule, Pipe, input, computed, ViewChild, HostAttributeToken, HostBinding, ContentChild, ViewContainerRef, TemplateRef, Self, SimpleChange, Attribute, SecurityContext } from '@angular/core';
6
+ import { Injectable, ChangeDetectionStrategy, Component, Directive, ContentChildren, Optional, SkipSelf, NgZone, InjectionToken, inject, ChangeDetectorRef, Inject, EventEmitter, ElementRef, ViewChildren, Output, Input, HostListener, forwardRef, LOCALE_ID, NgModule, Pipe, input, computed, ViewChild, HostAttributeToken, HostBinding, ContentChild, ViewContainerRef, TemplateRef, Self, SimpleChange, Attribute, SecurityContext } from '@angular/core';
7
7
  import * as i1 from '@angular/material/dialog';
8
- import { MatDialogModule, MatDialogConfig, MatDialog, MAT_DIALOG_DATA, MatDialogTitle } from '@angular/material/dialog';
8
+ import { MatDialogModule, MatDialogConfig, MatDialog, MatDialogState, MAT_DIALOG_DATA, MatDialogTitle } from '@angular/material/dialog';
9
9
  import * as i6$1 from '@angular/material/expansion';
10
10
  import { MatExpansionPanel, MatExpansionModule } from '@angular/material/expansion';
11
11
  import * as i2$4 from '@angular/material/snack-bar';
@@ -847,6 +847,10 @@ class TaskDialogData {
847
847
  * @type {string}
848
848
  */
849
849
  errorMessage;
850
+ /**
851
+ * Opts in to displaying API error messages alongside the task's failure message.
852
+ */
853
+ showErrorDetails;
850
854
  /**
851
855
  * Content of the dialog, usually descriptive text
852
856
  * @type {string}
@@ -897,6 +901,10 @@ class TaskDialogData {
897
901
  * @type {string}
898
902
  */
899
903
  successButtonText;
904
+ /**
905
+ * Label for the manual retry button shown after failure. The task must support re-subscription.
906
+ */
907
+ retryButtonText;
900
908
  /**
901
909
  * Callback function to execute on success button click
902
910
  * @type {Function}
@@ -916,14 +924,68 @@ class TaskDialogData {
916
924
  }
917
925
  }
918
926
 
927
+ /**
928
+ * Extracts user-facing text from API error bodies without displaying transport metadata.
929
+ *
930
+ * @param body - The API response body, not the HTTP error wrapper.
931
+ * @returns The messages to display, or an empty array if the caller should use its fallback.
932
+ */
933
+ function getApiErrorMessages(body) {
934
+ /* Handle simple string messages or arrays of messages directly. */
935
+ if (typeof body === 'string' || Array.isArray(body)) {
936
+ return distinctMessages([body].flat());
937
+ }
938
+ /* If the body is a primitive type or an array, treat it as a list of messages. */
939
+ if (body === null || typeof body !== 'object') {
940
+ return [];
941
+ }
942
+ /* Extract known error fields from the response body */
943
+ const { title, detail, message, error, errors } = body;
944
+ /* Validation errors may be grouped by field name or returned as a single string or list. */
945
+ const validationMessages = errors && typeof errors === 'object' && !Array.isArray(errors)
946
+ ? Object.values(errors)
947
+ : [errors];
948
+ /* Combine all extracted messages and remove duplicates */
949
+ const messages = distinctMessages([title, detail, message, error, ...validationMessages.flat()]);
950
+ if (messages.length) {
951
+ return messages;
952
+ }
953
+ /* Older validation responses put message arrays directly under field names. */
954
+ return distinctMessages(Object.values(body).filter(Array.isArray).flat());
955
+ }
956
+ /**
957
+ * Normalizes candidate messages without converting non-string values to display text.
958
+ *
959
+ * @param values - Candidate message values extracted from the response.
960
+ * @returns Trimmed, non-empty messages with duplicates removed in first-seen order.
961
+ */
962
+ function distinctMessages(values) {
963
+ /* Normalize candidate messages by filtering out non-string values, trimming, and removing duplicates. */
964
+ const messages = values
965
+ .filter((value) => typeof value === 'string')
966
+ .map(value => value.trim())
967
+ .filter(Boolean);
968
+ return [...new Set(messages)];
969
+ }
970
+
919
971
  class VdTaskDialogComponent {
920
972
  dialogRef;
921
973
  data;
974
+ /**
975
+ * Marks the dialog for a view update when an asynchronous task succeeds or fails.
976
+ * @type {ChangeDetectorRef}
977
+ */
978
+ changeDetector = inject(ChangeDetectorRef);
922
979
  /**
923
980
  * The message content displayed within the dialog.
924
981
  * @type {string | undefined}
925
982
  */
926
983
  content;
984
+ /**
985
+ * User-facing API messages for the current attempt, populated only when enabled.
986
+ * @type {string[]}
987
+ */
988
+ errorDetails = [];
927
989
  /**
928
990
  * The result of the task, if available.
929
991
  * @type {any}
@@ -954,10 +1016,37 @@ class VdTaskDialogComponent {
954
1016
  this.data = data;
955
1017
  }
956
1018
  /**
957
- * Lifecycle hook after view initialization.
958
- * Subscribes to the task observable and handles success or error callbacks.
1019
+ * Starts the first attempt before Angular checks the task state in the view.
959
1020
  */
960
- ngAfterViewInit() {
1021
+ ngOnInit() {
1022
+ this.runTask();
1023
+ }
1024
+ /**
1025
+ * Retry is opt-in and shown only after a failure. Cancel also ends the in-progress state,
1026
+ * so check that the dialog is still open before offering Retry.
1027
+ */
1028
+ get canRetry() {
1029
+ return !!this.data.retryButtonText && this.shouldShow('failed')
1030
+ && this.dialogRef.getState() === MatDialogState.OPEN;
1031
+ }
1032
+ /**
1033
+ * Re-subscribes to the task without reopening the dialog. Recheck eligibility here
1034
+ * so a second click cannot start an overlapping attempt before the button disappears.
1035
+ */
1036
+ retry() {
1037
+ if (this.canRetry) {
1038
+ this.runTask();
1039
+ }
1040
+ }
1041
+ /**
1042
+ * Executes the task and manages its state, including in-progress, success, and error handling.
1043
+ */
1044
+ runTask() {
1045
+ /* Reset before subscribing so retries cannot overlap and old errors do not carry over. */
1046
+ this.inProgress = true;
1047
+ this.succeeded = false;
1048
+ this.result = undefined;
1049
+ this.errorDetails = [];
961
1050
  this.content = this.data.inProgressMessage;
962
1051
  this.data.task
963
1052
  /* Take until unsubscribe signal */
@@ -973,6 +1062,7 @@ class VdTaskDialogComponent {
973
1062
  this.result = result;
974
1063
  /* Update the content with the success message */
975
1064
  this.content = this.data.successMessage;
1065
+ this.changeDetector.markForCheck();
976
1066
  /* If a success callback is provided, invoke it with the result */
977
1067
  if (this.data.successCallback) {
978
1068
  this.data.successCallback(result, this.dialogRef);
@@ -988,6 +1078,11 @@ class VdTaskDialogComponent {
988
1078
  this.result = errors;
989
1079
  /* Update the content with the error message */
990
1080
  this.content = this.data.errorMessage;
1081
+ /* Read the response body instead of the HTTP status message. Keep the dialog's failure message if the body has no usable details. */
1082
+ if (this.data.showErrorDetails) {
1083
+ this.errorDetails = getApiErrorMessages(errors instanceof HttpErrorResponse ? errors.error : errors);
1084
+ }
1085
+ this.changeDetector.markForCheck();
991
1086
  /* If an error callback is provided, invoke it with the errors */
992
1087
  if (this.data.errorCallback) {
993
1088
  this.data.errorCallback(errors, this.dialogRef);
@@ -1073,7 +1168,7 @@ class VdTaskDialogComponent {
1073
1168
  this.unsubscribe.complete();
1074
1169
  }
1075
1170
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.7", ngImport: i0, type: VdTaskDialogComponent, deps: [{ token: i1.MatDialogRef }, { token: MAT_DIALOG_DATA }], target: i0.ɵɵFactoryTarget.Component });
1076
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.7", type: VdTaskDialogComponent, isStandalone: true, selector: "vd-task-dialog", ngImport: i0, template: "<div mat-dialog-title class=\"mat-headline-6\" cdkDragRootElement=\".cdk-overlay-pane\" cdkDrag cdkDragHandle>{{this.data.title}}</div>\r\n@if (inProgress) {\r\n <mat-progress-bar mode=\"indeterminate\"></mat-progress-bar>\r\n}\r\n@if (!inProgress) {\r\n <mat-progress-bar mode=\"determinate\" value=\"100\"></mat-progress-bar>\r\n}\r\n<div mat-dialog-content>{{content}}</div>\r\n<div mat-dialog-actions class=\"pad-top\">\r\n @for (btn of data.buttons; track btn) {\r\n @if (btn.type === 'flat' && shouldShow(btn.showWhen)) {\r\n <button type=\"button\" mat-flat-button [color]=\"btn.color\" (click)=\"onButtonClick(btn)\">{{ btn.text }}</button>\r\n }\r\n @if (btn.type !== 'flat' && shouldShow(btn.showWhen)) {\r\n <button type=\"button\" mat-button [color]=\"btn.color\" (click)=\"onButtonClick(btn)\">{{ btn.text }}</button>\r\n }\r\n }\r\n @if (this.data.successButtonClick && succeeded) {\r\n <button type=\"button\" mat-flat-button (click)=\"success()\" color=\"primary\" (click)=\"null\">{{this.data.successButtonText}}</button>\r\n }\r\n @if (inProgress) {\r\n <button type=\"button\" mat-button (click)=\"cancel()\" autofocus>{{this.data.cancelButtonText}}</button>\r\n }\r\n @if (!inProgress) {\r\n <button type=\"button\" mat-button (click)=\"close()\" autofocus>{{this.data.closeButtonText}}</button>\r\n }\r\n</div>", styles: [""], dependencies: [{ kind: "ngmodule", type: MatButtonModule }, { kind: "component", type: i2.MatButton, selector: " button[matButton], a[matButton], button[mat-button], button[mat-raised-button], button[mat-flat-button], button[mat-stroked-button], a[mat-button], a[mat-raised-button], a[mat-flat-button], a[mat-stroked-button] ", inputs: ["matButton"], exportAs: ["matButton", "matAnchor"] }, { kind: "ngmodule", type: MatDialogModule }, { kind: "directive", type: i1.MatDialogTitle, selector: "[mat-dialog-title], [matDialogTitle]", inputs: ["id"], exportAs: ["matDialogTitle"] }, { kind: "directive", type: i1.MatDialogActions, selector: "[mat-dialog-actions], mat-dialog-actions, [matDialogActions]", inputs: ["align"] }, { kind: "directive", type: i1.MatDialogContent, selector: "[mat-dialog-content], mat-dialog-content, [matDialogContent]" }, { kind: "ngmodule", type: MatProgressBarModule }, { kind: "component", type: i3.MatProgressBar, selector: "mat-progress-bar", inputs: ["color", "value", "bufferValue", "mode"], outputs: ["animationEnd"], exportAs: ["matProgressBar"] }], changeDetection: i0.ChangeDetectionStrategy.Eager });
1171
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.7", type: VdTaskDialogComponent, isStandalone: true, selector: "vd-task-dialog", ngImport: i0, template: "<div mat-dialog-title class=\"mat-headline-6\" cdkDragRootElement=\".cdk-overlay-pane\" cdkDrag cdkDragHandle>{{this.data.title}}</div>\r\n@if (inProgress) {\r\n <mat-progress-bar mode=\"indeterminate\"></mat-progress-bar>\r\n}\r\n@if (!inProgress) {\r\n <mat-progress-bar mode=\"determinate\" value=\"100\"></mat-progress-bar>\r\n}\r\n<div mat-dialog-content aria-live=\"polite\">\r\n {{content}}\r\n @if (errorDetails.length) {\r\n <ul class=\"task-error-details\">\r\n @for (detail of errorDetails; track detail) {\r\n <li>{{detail}}</li>\r\n }\r\n </ul>\r\n }\r\n</div>\r\n<div mat-dialog-actions class=\"pad-top\">\r\n @for (btn of data.buttons; track btn) {\r\n @if (btn.type === 'flat' && shouldShow(btn.showWhen)) {\r\n <button type=\"button\" mat-flat-button [color]=\"btn.color\" (click)=\"onButtonClick(btn)\">{{ btn.text }}</button>\r\n }\r\n @if (btn.type !== 'flat' && shouldShow(btn.showWhen)) {\r\n <button type=\"button\" mat-button [color]=\"btn.color\" (click)=\"onButtonClick(btn)\">{{ btn.text }}</button>\r\n }\r\n }\r\n @if (this.data.successButtonClick && succeeded) {\r\n <button type=\"button\" mat-flat-button (click)=\"success()\" color=\"primary\" (click)=\"null\">{{this.data.successButtonText}}</button>\r\n }\r\n @if (canRetry) {\r\n <button type=\"button\" mat-flat-button color=\"primary\" (click)=\"retry()\">{{data.retryButtonText}}</button>\r\n }\r\n @if (inProgress) {\r\n <button type=\"button\" mat-button (click)=\"cancel()\" autofocus>{{this.data.cancelButtonText}}</button>\r\n }\r\n @if (!inProgress) {\r\n <button type=\"button\" mat-button (click)=\"close()\" autofocus>{{this.data.closeButtonText}}</button>\r\n }\r\n</div>", styles: [".task-error-details{white-space:pre-line;overflow-wrap:anywhere;padding-left:16px;padding-top:8px}\n"], dependencies: [{ kind: "ngmodule", type: MatButtonModule }, { kind: "component", type: i2.MatButton, selector: " button[matButton], a[matButton], button[mat-button], button[mat-raised-button], button[mat-flat-button], button[mat-stroked-button], a[mat-button], a[mat-raised-button], a[mat-flat-button], a[mat-stroked-button] ", inputs: ["matButton"], exportAs: ["matButton", "matAnchor"] }, { kind: "ngmodule", type: MatDialogModule }, { kind: "directive", type: i1.MatDialogTitle, selector: "[mat-dialog-title], [matDialogTitle]", inputs: ["id"], exportAs: ["matDialogTitle"] }, { kind: "directive", type: i1.MatDialogActions, selector: "[mat-dialog-actions], mat-dialog-actions, [matDialogActions]", inputs: ["align"] }, { kind: "directive", type: i1.MatDialogContent, selector: "[mat-dialog-content], mat-dialog-content, [matDialogContent]" }, { kind: "ngmodule", type: MatProgressBarModule }, { kind: "component", type: i3.MatProgressBar, selector: "mat-progress-bar", inputs: ["color", "value", "bufferValue", "mode"], outputs: ["animationEnd"], exportAs: ["matProgressBar"] }], changeDetection: i0.ChangeDetectionStrategy.Eager });
1077
1172
  }
1078
1173
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.7", ngImport: i0, type: VdTaskDialogComponent, decorators: [{
1079
1174
  type: Component,
@@ -1081,7 +1176,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.7", ngImpor
1081
1176
  MatButtonModule,
1082
1177
  MatDialogModule,
1083
1178
  MatProgressBarModule
1084
- ], template: "<div mat-dialog-title class=\"mat-headline-6\" cdkDragRootElement=\".cdk-overlay-pane\" cdkDrag cdkDragHandle>{{this.data.title}}</div>\r\n@if (inProgress) {\r\n <mat-progress-bar mode=\"indeterminate\"></mat-progress-bar>\r\n}\r\n@if (!inProgress) {\r\n <mat-progress-bar mode=\"determinate\" value=\"100\"></mat-progress-bar>\r\n}\r\n<div mat-dialog-content>{{content}}</div>\r\n<div mat-dialog-actions class=\"pad-top\">\r\n @for (btn of data.buttons; track btn) {\r\n @if (btn.type === 'flat' && shouldShow(btn.showWhen)) {\r\n <button type=\"button\" mat-flat-button [color]=\"btn.color\" (click)=\"onButtonClick(btn)\">{{ btn.text }}</button>\r\n }\r\n @if (btn.type !== 'flat' && shouldShow(btn.showWhen)) {\r\n <button type=\"button\" mat-button [color]=\"btn.color\" (click)=\"onButtonClick(btn)\">{{ btn.text }}</button>\r\n }\r\n }\r\n @if (this.data.successButtonClick && succeeded) {\r\n <button type=\"button\" mat-flat-button (click)=\"success()\" color=\"primary\" (click)=\"null\">{{this.data.successButtonText}}</button>\r\n }\r\n @if (inProgress) {\r\n <button type=\"button\" mat-button (click)=\"cancel()\" autofocus>{{this.data.cancelButtonText}}</button>\r\n }\r\n @if (!inProgress) {\r\n <button type=\"button\" mat-button (click)=\"close()\" autofocus>{{this.data.closeButtonText}}</button>\r\n }\r\n</div>" }]
1179
+ ], template: "<div mat-dialog-title class=\"mat-headline-6\" cdkDragRootElement=\".cdk-overlay-pane\" cdkDrag cdkDragHandle>{{this.data.title}}</div>\r\n@if (inProgress) {\r\n <mat-progress-bar mode=\"indeterminate\"></mat-progress-bar>\r\n}\r\n@if (!inProgress) {\r\n <mat-progress-bar mode=\"determinate\" value=\"100\"></mat-progress-bar>\r\n}\r\n<div mat-dialog-content aria-live=\"polite\">\r\n {{content}}\r\n @if (errorDetails.length) {\r\n <ul class=\"task-error-details\">\r\n @for (detail of errorDetails; track detail) {\r\n <li>{{detail}}</li>\r\n }\r\n </ul>\r\n }\r\n</div>\r\n<div mat-dialog-actions class=\"pad-top\">\r\n @for (btn of data.buttons; track btn) {\r\n @if (btn.type === 'flat' && shouldShow(btn.showWhen)) {\r\n <button type=\"button\" mat-flat-button [color]=\"btn.color\" (click)=\"onButtonClick(btn)\">{{ btn.text }}</button>\r\n }\r\n @if (btn.type !== 'flat' && shouldShow(btn.showWhen)) {\r\n <button type=\"button\" mat-button [color]=\"btn.color\" (click)=\"onButtonClick(btn)\">{{ btn.text }}</button>\r\n }\r\n }\r\n @if (this.data.successButtonClick && succeeded) {\r\n <button type=\"button\" mat-flat-button (click)=\"success()\" color=\"primary\" (click)=\"null\">{{this.data.successButtonText}}</button>\r\n }\r\n @if (canRetry) {\r\n <button type=\"button\" mat-flat-button color=\"primary\" (click)=\"retry()\">{{data.retryButtonText}}</button>\r\n }\r\n @if (inProgress) {\r\n <button type=\"button\" mat-button (click)=\"cancel()\" autofocus>{{this.data.cancelButtonText}}</button>\r\n }\r\n @if (!inProgress) {\r\n <button type=\"button\" mat-button (click)=\"close()\" autofocus>{{this.data.closeButtonText}}</button>\r\n }\r\n</div>", styles: [".task-error-details{white-space:pre-line;overflow-wrap:anywhere;padding-left:16px;padding-top:8px}\n"] }]
1085
1180
  }], ctorParameters: () => [{ type: i1.MatDialogRef }, { type: TaskDialogData, decorators: [{
1086
1181
  type: Inject,
1087
1182
  args: [MAT_DIALOG_DATA]
@@ -22500,20 +22595,9 @@ class BaseInterceptor {
22500
22595
  return "Failed to parse error details.";
22501
22596
  }
22502
22597
  }
22503
- /* Keep plain response bodies intact */
22504
- if (typeof error === 'string') {
22505
- return error;
22506
- }
22507
- /* Extract user-facing fields from RFC Problem Details responses */
22508
- const problem = error;
22509
- if (typeof problem.title === 'string' || typeof problem.detail === 'string') {
22510
- if (typeof problem.title === 'string') {
22511
- errors.push(problem.title);
22512
- }
22513
- if (typeof problem.detail === 'string' && problem.detail !== problem.title) {
22514
- errors.push(problem.detail);
22515
- }
22516
- return errors.join('\n');
22598
+ const messages = getApiErrorMessages(error);
22599
+ if (messages.length) {
22600
+ return messages.join('\n');
22517
22601
  }
22518
22602
  /* Ensure the error is an object (for structured error responses) */
22519
22603
  if (typeof error === 'object') {