@dloizides/ui-feedback 1.18.0 → 1.19.0

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.19.0
4
+
5
+ - Error reference (OBS-1 "Every app ships metrics, production-grade logs and alerts with working links", D-OBS-23 option A): `ErrorState` takes `error` and `AsyncSurface` passes its new `error` prop through; when the error carries a `traceId` (`@dloizides/bff-web-client` >= 1.4.0) a row "Error reference: <id>" + Copy (56x48 hit box, Copied / Copy failed for 1.5 s) sits below Retry / Back. Hidden without an id, so existing callers render the same tree.
6
+ - `ToastHost`: `ToastInput.traceId` adds the same row under an error toast's text; `toastBus.error(text, error)` reads it from the error.
7
+ - New exports `ErrorReferenceRow`, `readTraceId`, `copyText`, `useCopyToClipboard`, `CopyStatus`, `COPY_FEEDBACK_MS`.
8
+ - New translation key the host provides: `common.errorReference` ("Error reference:"); reuses `common.copy`, `common.copied`, `common.copyFailed`, `common.copyHint`.
9
+
3
10
  ## 1.18.0
4
11
 
5
12
  - `ToastHost`: the text and a new type glyph (check / ! / i) use an ink at 4.5:1 or better on the toast fill (`resolveOnBrand`; falls back to the 700 step, then the elevated surface with body text); success and error now differ by shape, not tint alone.
package/dist/index.d.mts CHANGED
@@ -1,4 +1,5 @@
1
1
  import React, { Component, ReactNode, ErrorInfo } from 'react';
2
+ import { StyleProp, ViewStyle } from 'react-native';
2
3
 
3
4
  /**
4
5
  * The minimal theme surface the feedback components read. Each consuming app's
@@ -110,8 +111,10 @@ interface ErrorStateProps {
110
111
  icon?: React.ReactNode;
111
112
  /** Outline button beside retry, e.g. "Back to library". */
112
113
  secondaryAction?: ErrorStateAction;
114
+ /** The failed request's error; its `traceId` shows as "Error reference" + Copy below the actions. */
115
+ error?: unknown;
113
116
  }
114
- declare const ErrorState: ({ message, onRetry, testID, title, icon, secondaryAction, }: ErrorStateProps) => React.ReactElement;
117
+ declare const ErrorState: ({ message, onRetry, testID, title, icon, secondaryAction, error, }: ErrorStateProps) => React.ReactElement;
115
118
 
116
119
  /**
117
120
  * EmptyListState - empty-collection message with an optional call-to-action.
@@ -208,9 +211,11 @@ interface AsyncSurfaceProps {
208
211
  * server's raw text is never shown to a user.
209
212
  */
210
213
  message?: string;
214
+ /** The query's error; its `traceId` shows as "Error reference" on the error card. */
215
+ error?: unknown;
211
216
  children: React.ReactNode;
212
217
  }
213
- declare const AsyncSurface: ({ loading, isError, onRetry, skeletonRows, variant, message, children, }: AsyncSurfaceProps) => React.ReactNode;
218
+ declare const AsyncSurface: ({ loading, isError, onRetry, skeletonRows, variant, message, error, children, }: AsyncSurfaceProps) => React.ReactNode;
214
219
 
215
220
  /**
216
221
  * ConfirmDialog - modal confirm/cancel dialog with optional destructive + loading states.
@@ -252,6 +257,8 @@ type ToastType = 'success' | 'info' | 'error';
252
257
  interface ToastInput {
253
258
  text: string;
254
259
  type?: ToastType;
260
+ /** Trace id of the failed request; an error toast shows it as "Error reference" + Copy. */
261
+ traceId?: string;
255
262
  }
256
263
  interface ToastHostProps {
257
264
  /**
@@ -359,34 +366,6 @@ declare function subscribeWarming(listener: WarmingListener): () => void;
359
366
  /** Current immutable snapshot. Stable identity until the value changes. */
360
367
  declare function getWarmingSnapshot(): WarmingSnapshot;
361
368
 
362
- /**
363
- * createToastBus — the shared EMIT half of the toast pipeline, promoted from the
364
- * hand-rolled twins in aml-v2 (`components/toast.ts`), agora-web and zygos-web
365
- * (`lib/toastBus.ts`). The RENDERING half is `<ToastHost>`; a bus instance's
366
- * {@link ToastBus.subscribe} IS the `ToastHost` `subscribe` port.
367
- *
368
- * Deliberately FRAMEWORK-AGNOSTIC — no React import, no hook, no provider. Call
369
- * sites are React Query mutation `onSuccess`/`onError` callbacks that have no
370
- * component context in scope, so a hook-based API would break every one of them.
371
- *
372
- * It carries no styling: `<ToastHost>` themes every toast from `UiProvider`.
373
- * Text arriving here is ALREADY localized by the caller (`FM()`); this bus never
374
- * sees a translation key.
375
- *
376
- * Usage — one module-level instance per app:
377
- * ```ts
378
- * // src/lib/toastBus.ts
379
- * import { createToastBus } from '@dloizides/ui-feedback';
380
- * export const toastBus = createToastBus();
381
- *
382
- * // anywhere, no provider needed:
383
- * toastBus.success(FM('menu.saved'));
384
- *
385
- * // once, in the shell:
386
- * <ToastHost subscribe={toastBus.subscribe} />
387
- * ```
388
- */
389
-
390
369
  /** A registered push callback — what `<ToastHost>` hands to {@link ToastBus.subscribe}. */
391
370
  type ToastPush = (toast: ToastInput) => void;
392
371
  interface ToastBus {
@@ -396,8 +375,8 @@ interface ToastBus {
396
375
  emit(text: string, type?: ToastType): void;
397
376
  /** Emit a success toast. */
398
377
  success(text: string): void;
399
- /** Emit an error toast. */
400
- error(text: string): void;
378
+ /** Emit an error toast; pass the failed request's error to show its trace id as "Error reference". */
379
+ error(text: string, cause?: unknown): void;
401
380
  /** Emit an informational toast. */
402
381
  info(text: string): void;
403
382
  }
@@ -545,6 +524,37 @@ declare class AppErrorBoundary extends Component<AppErrorBoundaryProps, AppError
545
524
  render(): ReactNode;
546
525
  }
547
526
 
527
+ interface ErrorReferenceRowProps {
528
+ traceId: string | undefined;
529
+ color: string;
530
+ actionColor: string;
531
+ testID: string;
532
+ style?: StyleProp<ViewStyle>;
533
+ }
534
+ /** "Error reference: <trace id>" + Copy; renders nothing when there is no trace id. */
535
+ declare const ErrorReferenceRow: (props: ErrorReferenceRowProps) => React.ReactElement | null;
536
+
537
+ /** The trace id `@dloizides/bff-web-client` (>= 1.4.0) attaches to a failed request, if any. */
538
+ declare function readTraceId(error: unknown): string | undefined;
539
+
540
+ type ClipboardWriter = (text: string) => void | Promise<void>;
541
+ /** Copy `value`; true only when a write landed (injected writer, async clipboard, then execCommand). */
542
+ declare function copyText(value: string, writer?: ClipboardWriter): Promise<boolean>;
543
+
544
+ declare const enum CopyStatus {
545
+ Idle = "idle",
546
+ Copied = "copied",
547
+ Failed = "failed"
548
+ }
549
+
550
+ declare const COPY_FEEDBACK_MS = 1500;
551
+ interface CopyToClipboard {
552
+ status: CopyStatus;
553
+ copy: () => void;
554
+ }
555
+ /** Copies `value` and reports Copied / Failed for {@link COPY_FEEDBACK_MS} before returning to Idle. */
556
+ declare function useCopyToClipboard(value: string, writer?: (text: string) => void | Promise<void>): CopyToClipboard;
557
+
548
558
  interface ProgressBarProps {
549
559
  percent?: number | null;
550
560
  label?: string;
@@ -646,4 +656,4 @@ declare function LiveRunCard(props: LiveRunCardProps): React.ReactElement;
646
656
  /** The theme colour for a step or group state; falls back to primary/text when a semantic scale is absent. */
647
657
  declare function runToneColor(theme: FeedbackTheme, state: RunStepState): string;
648
658
 
649
- export { AppErrorBoundary, type AppErrorBoundaryProps, AsyncSurface, type AsyncSurfaceProps, ConfirmDialog, type ConfirmDialogProps, DEFAULT_ERROR_BOUNDARY_LABELS, DISABLED_OPACITY, type DoneSummary, EmptyListState, type EmptyListStateProps, type ErrorBoundaryLabels, type ErrorFallbackState, ErrorState, type ErrorStateAction, type ErrorStateProps, FEEDBACK_TEST_IDS, type FeedbackColorScale, type FeedbackNavigate, type FeedbackTheme, type FeedbackThemeColors, type FeedbackThemePalette, type FeedbackThemeSemantic, type FeedbackTranslate, FeedbackUiProvider, type FeedbackUiProviderProps, type FeedbackUiValue, type FlatRunStep, LIVE_RUN_CARD_COMPACT_MAX_PX, LiveRunCard, type LiveRunCardLabels, type LiveRunCardProps, LoadingFallback, type LoadingFallbackProps, MODAL_OVERLAY_COLOR, PageSkeleton, type PageSkeletonProps, ProgressBar, type ProgressBarProps, type RunGroup, type RunStep, type RunStepState, type StepSplit, type ToastBus, ToastHost, type ToastHostProps, type ToastInput, type ToastPush, type ToastType, type FeedbackColorScale as UiColorScale, type FeedbackNavigate as UiNavigate, FeedbackUiProvider as UiProvider, type FeedbackUiProviderProps as UiProviderProps, type FeedbackTheme as UiTheme, type FeedbackThemeColors as UiThemeColors, type FeedbackThemePalette as UiThemePalette, type FeedbackThemeSemantic as UiThemeSemantic, type FeedbackTranslate as UiTranslate, type FeedbackUiValue as UiValue, WARMING_QUIET_PERIOD_MS, type WarmingInfo, WarmingOverlay, type WarmingOverlayLabels, type WarmingOverlayProps, type WarmingSnapshot, barFraction, clampPercent, createToastBus, defaultGroupId, getWarmingSnapshot, mergeRunSteps, notifyWarming, progressPercent, runToneColor, settleWarming, splitShorterSteps, subscribeWarming, summariseDoneGroups, useFeedbackUi, useFeedbackUi as useUi };
659
+ export { AppErrorBoundary, type AppErrorBoundaryProps, AsyncSurface, type AsyncSurfaceProps, COPY_FEEDBACK_MS, ConfirmDialog, type ConfirmDialogProps, CopyStatus, type CopyToClipboard, DEFAULT_ERROR_BOUNDARY_LABELS, DISABLED_OPACITY, type DoneSummary, EmptyListState, type EmptyListStateProps, type ErrorBoundaryLabels, type ErrorFallbackState, ErrorReferenceRow, type ErrorReferenceRowProps, ErrorState, type ErrorStateAction, type ErrorStateProps, FEEDBACK_TEST_IDS, type FeedbackColorScale, type FeedbackNavigate, type FeedbackTheme, type FeedbackThemeColors, type FeedbackThemePalette, type FeedbackThemeSemantic, type FeedbackTranslate, FeedbackUiProvider, type FeedbackUiProviderProps, type FeedbackUiValue, type FlatRunStep, LIVE_RUN_CARD_COMPACT_MAX_PX, LiveRunCard, type LiveRunCardLabels, type LiveRunCardProps, LoadingFallback, type LoadingFallbackProps, MODAL_OVERLAY_COLOR, PageSkeleton, type PageSkeletonProps, ProgressBar, type ProgressBarProps, type RunGroup, type RunStep, type RunStepState, type StepSplit, type ToastBus, ToastHost, type ToastHostProps, type ToastInput, type ToastPush, type ToastType, type FeedbackColorScale as UiColorScale, type FeedbackNavigate as UiNavigate, FeedbackUiProvider as UiProvider, type FeedbackUiProviderProps as UiProviderProps, type FeedbackTheme as UiTheme, type FeedbackThemeColors as UiThemeColors, type FeedbackThemePalette as UiThemePalette, type FeedbackThemeSemantic as UiThemeSemantic, type FeedbackTranslate as UiTranslate, type FeedbackUiValue as UiValue, WARMING_QUIET_PERIOD_MS, type WarmingInfo, WarmingOverlay, type WarmingOverlayLabels, type WarmingOverlayProps, type WarmingSnapshot, barFraction, clampPercent, copyText, createToastBus, defaultGroupId, getWarmingSnapshot, mergeRunSteps, notifyWarming, progressPercent, readTraceId, runToneColor, settleWarming, splitShorterSteps, subscribeWarming, summariseDoneGroups, useCopyToClipboard, useFeedbackUi, useFeedbackUi as useUi };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import React, { Component, ReactNode, ErrorInfo } from 'react';
2
+ import { StyleProp, ViewStyle } from 'react-native';
2
3
 
3
4
  /**
4
5
  * The minimal theme surface the feedback components read. Each consuming app's
@@ -110,8 +111,10 @@ interface ErrorStateProps {
110
111
  icon?: React.ReactNode;
111
112
  /** Outline button beside retry, e.g. "Back to library". */
112
113
  secondaryAction?: ErrorStateAction;
114
+ /** The failed request's error; its `traceId` shows as "Error reference" + Copy below the actions. */
115
+ error?: unknown;
113
116
  }
114
- declare const ErrorState: ({ message, onRetry, testID, title, icon, secondaryAction, }: ErrorStateProps) => React.ReactElement;
117
+ declare const ErrorState: ({ message, onRetry, testID, title, icon, secondaryAction, error, }: ErrorStateProps) => React.ReactElement;
115
118
 
116
119
  /**
117
120
  * EmptyListState - empty-collection message with an optional call-to-action.
@@ -208,9 +211,11 @@ interface AsyncSurfaceProps {
208
211
  * server's raw text is never shown to a user.
209
212
  */
210
213
  message?: string;
214
+ /** The query's error; its `traceId` shows as "Error reference" on the error card. */
215
+ error?: unknown;
211
216
  children: React.ReactNode;
212
217
  }
213
- declare const AsyncSurface: ({ loading, isError, onRetry, skeletonRows, variant, message, children, }: AsyncSurfaceProps) => React.ReactNode;
218
+ declare const AsyncSurface: ({ loading, isError, onRetry, skeletonRows, variant, message, error, children, }: AsyncSurfaceProps) => React.ReactNode;
214
219
 
215
220
  /**
216
221
  * ConfirmDialog - modal confirm/cancel dialog with optional destructive + loading states.
@@ -252,6 +257,8 @@ type ToastType = 'success' | 'info' | 'error';
252
257
  interface ToastInput {
253
258
  text: string;
254
259
  type?: ToastType;
260
+ /** Trace id of the failed request; an error toast shows it as "Error reference" + Copy. */
261
+ traceId?: string;
255
262
  }
256
263
  interface ToastHostProps {
257
264
  /**
@@ -359,34 +366,6 @@ declare function subscribeWarming(listener: WarmingListener): () => void;
359
366
  /** Current immutable snapshot. Stable identity until the value changes. */
360
367
  declare function getWarmingSnapshot(): WarmingSnapshot;
361
368
 
362
- /**
363
- * createToastBus — the shared EMIT half of the toast pipeline, promoted from the
364
- * hand-rolled twins in aml-v2 (`components/toast.ts`), agora-web and zygos-web
365
- * (`lib/toastBus.ts`). The RENDERING half is `<ToastHost>`; a bus instance's
366
- * {@link ToastBus.subscribe} IS the `ToastHost` `subscribe` port.
367
- *
368
- * Deliberately FRAMEWORK-AGNOSTIC — no React import, no hook, no provider. Call
369
- * sites are React Query mutation `onSuccess`/`onError` callbacks that have no
370
- * component context in scope, so a hook-based API would break every one of them.
371
- *
372
- * It carries no styling: `<ToastHost>` themes every toast from `UiProvider`.
373
- * Text arriving here is ALREADY localized by the caller (`FM()`); this bus never
374
- * sees a translation key.
375
- *
376
- * Usage — one module-level instance per app:
377
- * ```ts
378
- * // src/lib/toastBus.ts
379
- * import { createToastBus } from '@dloizides/ui-feedback';
380
- * export const toastBus = createToastBus();
381
- *
382
- * // anywhere, no provider needed:
383
- * toastBus.success(FM('menu.saved'));
384
- *
385
- * // once, in the shell:
386
- * <ToastHost subscribe={toastBus.subscribe} />
387
- * ```
388
- */
389
-
390
369
  /** A registered push callback — what `<ToastHost>` hands to {@link ToastBus.subscribe}. */
391
370
  type ToastPush = (toast: ToastInput) => void;
392
371
  interface ToastBus {
@@ -396,8 +375,8 @@ interface ToastBus {
396
375
  emit(text: string, type?: ToastType): void;
397
376
  /** Emit a success toast. */
398
377
  success(text: string): void;
399
- /** Emit an error toast. */
400
- error(text: string): void;
378
+ /** Emit an error toast; pass the failed request's error to show its trace id as "Error reference". */
379
+ error(text: string, cause?: unknown): void;
401
380
  /** Emit an informational toast. */
402
381
  info(text: string): void;
403
382
  }
@@ -545,6 +524,37 @@ declare class AppErrorBoundary extends Component<AppErrorBoundaryProps, AppError
545
524
  render(): ReactNode;
546
525
  }
547
526
 
527
+ interface ErrorReferenceRowProps {
528
+ traceId: string | undefined;
529
+ color: string;
530
+ actionColor: string;
531
+ testID: string;
532
+ style?: StyleProp<ViewStyle>;
533
+ }
534
+ /** "Error reference: <trace id>" + Copy; renders nothing when there is no trace id. */
535
+ declare const ErrorReferenceRow: (props: ErrorReferenceRowProps) => React.ReactElement | null;
536
+
537
+ /** The trace id `@dloizides/bff-web-client` (>= 1.4.0) attaches to a failed request, if any. */
538
+ declare function readTraceId(error: unknown): string | undefined;
539
+
540
+ type ClipboardWriter = (text: string) => void | Promise<void>;
541
+ /** Copy `value`; true only when a write landed (injected writer, async clipboard, then execCommand). */
542
+ declare function copyText(value: string, writer?: ClipboardWriter): Promise<boolean>;
543
+
544
+ declare const enum CopyStatus {
545
+ Idle = "idle",
546
+ Copied = "copied",
547
+ Failed = "failed"
548
+ }
549
+
550
+ declare const COPY_FEEDBACK_MS = 1500;
551
+ interface CopyToClipboard {
552
+ status: CopyStatus;
553
+ copy: () => void;
554
+ }
555
+ /** Copies `value` and reports Copied / Failed for {@link COPY_FEEDBACK_MS} before returning to Idle. */
556
+ declare function useCopyToClipboard(value: string, writer?: (text: string) => void | Promise<void>): CopyToClipboard;
557
+
548
558
  interface ProgressBarProps {
549
559
  percent?: number | null;
550
560
  label?: string;
@@ -646,4 +656,4 @@ declare function LiveRunCard(props: LiveRunCardProps): React.ReactElement;
646
656
  /** The theme colour for a step or group state; falls back to primary/text when a semantic scale is absent. */
647
657
  declare function runToneColor(theme: FeedbackTheme, state: RunStepState): string;
648
658
 
649
- export { AppErrorBoundary, type AppErrorBoundaryProps, AsyncSurface, type AsyncSurfaceProps, ConfirmDialog, type ConfirmDialogProps, DEFAULT_ERROR_BOUNDARY_LABELS, DISABLED_OPACITY, type DoneSummary, EmptyListState, type EmptyListStateProps, type ErrorBoundaryLabels, type ErrorFallbackState, ErrorState, type ErrorStateAction, type ErrorStateProps, FEEDBACK_TEST_IDS, type FeedbackColorScale, type FeedbackNavigate, type FeedbackTheme, type FeedbackThemeColors, type FeedbackThemePalette, type FeedbackThemeSemantic, type FeedbackTranslate, FeedbackUiProvider, type FeedbackUiProviderProps, type FeedbackUiValue, type FlatRunStep, LIVE_RUN_CARD_COMPACT_MAX_PX, LiveRunCard, type LiveRunCardLabels, type LiveRunCardProps, LoadingFallback, type LoadingFallbackProps, MODAL_OVERLAY_COLOR, PageSkeleton, type PageSkeletonProps, ProgressBar, type ProgressBarProps, type RunGroup, type RunStep, type RunStepState, type StepSplit, type ToastBus, ToastHost, type ToastHostProps, type ToastInput, type ToastPush, type ToastType, type FeedbackColorScale as UiColorScale, type FeedbackNavigate as UiNavigate, FeedbackUiProvider as UiProvider, type FeedbackUiProviderProps as UiProviderProps, type FeedbackTheme as UiTheme, type FeedbackThemeColors as UiThemeColors, type FeedbackThemePalette as UiThemePalette, type FeedbackThemeSemantic as UiThemeSemantic, type FeedbackTranslate as UiTranslate, type FeedbackUiValue as UiValue, WARMING_QUIET_PERIOD_MS, type WarmingInfo, WarmingOverlay, type WarmingOverlayLabels, type WarmingOverlayProps, type WarmingSnapshot, barFraction, clampPercent, createToastBus, defaultGroupId, getWarmingSnapshot, mergeRunSteps, notifyWarming, progressPercent, runToneColor, settleWarming, splitShorterSteps, subscribeWarming, summariseDoneGroups, useFeedbackUi, useFeedbackUi as useUi };
659
+ export { AppErrorBoundary, type AppErrorBoundaryProps, AsyncSurface, type AsyncSurfaceProps, COPY_FEEDBACK_MS, ConfirmDialog, type ConfirmDialogProps, CopyStatus, type CopyToClipboard, DEFAULT_ERROR_BOUNDARY_LABELS, DISABLED_OPACITY, type DoneSummary, EmptyListState, type EmptyListStateProps, type ErrorBoundaryLabels, type ErrorFallbackState, ErrorReferenceRow, type ErrorReferenceRowProps, ErrorState, type ErrorStateAction, type ErrorStateProps, FEEDBACK_TEST_IDS, type FeedbackColorScale, type FeedbackNavigate, type FeedbackTheme, type FeedbackThemeColors, type FeedbackThemePalette, type FeedbackThemeSemantic, type FeedbackTranslate, FeedbackUiProvider, type FeedbackUiProviderProps, type FeedbackUiValue, type FlatRunStep, LIVE_RUN_CARD_COMPACT_MAX_PX, LiveRunCard, type LiveRunCardLabels, type LiveRunCardProps, LoadingFallback, type LoadingFallbackProps, MODAL_OVERLAY_COLOR, PageSkeleton, type PageSkeletonProps, ProgressBar, type ProgressBarProps, type RunGroup, type RunStep, type RunStepState, type StepSplit, type ToastBus, ToastHost, type ToastHostProps, type ToastInput, type ToastPush, type ToastType, type FeedbackColorScale as UiColorScale, type FeedbackNavigate as UiNavigate, FeedbackUiProvider as UiProvider, type FeedbackUiProviderProps as UiProviderProps, type FeedbackTheme as UiTheme, type FeedbackThemeColors as UiThemeColors, type FeedbackThemePalette as UiThemePalette, type FeedbackThemeSemantic as UiThemeSemantic, type FeedbackTranslate as UiTranslate, type FeedbackUiValue as UiValue, WARMING_QUIET_PERIOD_MS, type WarmingInfo, WarmingOverlay, type WarmingOverlayLabels, type WarmingOverlayProps, type WarmingSnapshot, barFraction, clampPercent, copyText, createToastBus, defaultGroupId, getWarmingSnapshot, mergeRunSteps, notifyWarming, progressPercent, readTraceId, runToneColor, settleWarming, splitShorterSteps, subscribeWarming, summariseDoneGroups, useCopyToClipboard, useFeedbackUi, useFeedbackUi as useUi };