@richardmcquiston01/dashboard-widgets-toolkit 0.4.1 → 0.6.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/dist/react.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ReactNode, RefObject } from 'react';
2
- import { D as DashboardWidget, W as WidgetSize, a as WidgetFill, G as GraphWidgetData, N as NiceDomain, b as WidgetDefinition, c as DetailProviderOptions, d as DetailData, e as DetailQuery, L as Locale, f as DashboardLayout, A as AlertListWidgetData, B as BarListWidgetData, g as GaugeWidgetData, K as KpiWidgetData, T as TableWidgetData, h as TextWidgetData, i as WidgetData, R as ResolveOptions, j as WidgetContext, k as WidgetProviders } from './scale-dWDGE1zW.cjs';
2
+ import { D as DashboardWidget, W as WidgetSize, a as WidgetFill, G as GraphWidgetData, N as NiceDomain, b as WidgetDefinition, c as DetailProviderOptions, d as DetailData, e as DetailQuery, L as Locale, f as DashboardLayout, A as AlertListWidgetData, B as BarListWidgetData, g as GaugeWidgetData, K as KpiWidgetData, T as TableWidgetData, R as ResolvedTableControls, h as TextWidgetData, i as WidgetData, j as ResolveOptions, k as WidgetContext, l as WidgetProviders } from './scale-D51ZGIF4.cjs';
3
3
 
4
4
  interface WidgetCardProps {
5
5
  readonly title: string;
@@ -88,8 +88,10 @@ declare function GraphWidget({ data, title, }: {
88
88
  /**
89
89
  * Loads a widget's full detail data. Close over your own context (a Prisma
90
90
  * client, a fetch) here; the package never fetches. See `DetailProvider`.
91
+ * Return `undefined` for a widget you have no extra data for: the card's own
92
+ * data is used when it is complete (see `deriveDetailData`).
91
93
  */
92
- type DetailLoader = (definition: WidgetDefinition, options: DetailProviderOptions) => DetailData | Promise<DetailData>;
94
+ type DetailLoader = (definition: WidgetDefinition, options: DetailProviderOptions) => DetailData | undefined | Promise<DetailData | undefined>;
93
95
  interface WidgetDetailProps {
94
96
  /** Table caption: the widget's title. */
95
97
  readonly title: string;
@@ -135,9 +137,12 @@ interface DetailLoadState {
135
137
  /**
136
138
  * Loads a widget's detail data while `enabled`: calls `load` with an abort
137
139
  * signal (aborted on close, retry or unmount), validates the result and
138
- * reports loading, ok or error. `reload` runs it again.
140
+ * reports loading, ok or error. When `load` is missing or returns
141
+ * `undefined`, `fallback` (for example the card's own complete data) is used
142
+ * instead. `reload` runs it again. Keep `load` and `fallback` referentially
143
+ * stable (`useCallback` / `useMemo`): a new value restarts the load.
139
144
  */
140
- declare function useDetailData(definition: WidgetDefinition, load: DetailLoader | undefined, enabled: boolean): {
145
+ declare function useDetailData(definition: WidgetDefinition, load: DetailLoader | undefined, enabled: boolean, fallback?: DetailData): {
141
146
  readonly state: DetailLoadState;
142
147
  readonly reload: () => void;
143
148
  };
@@ -228,9 +233,10 @@ interface DashboardProps extends WidgetSettings {
228
233
  readonly onRetry?: (key: string) => void;
229
234
  /**
230
235
  * Loads the full data for a widget's detail view (widgets whose definition
231
- * sets `detail`). Close over your own context. Without it, TABLE widgets
232
- * with no footer and BAR_LIST widgets show their card data; other widgets
233
- * get no View button.
236
+ * sets `detail`). Close over your own context. Return `undefined` for a
237
+ * widget you have no extra data for: a TABLE with no footer or a BAR_LIST
238
+ * then shows its card data. Without `loadDetail`, those two still work and
239
+ * other widgets get no View button.
234
240
  */
235
241
  readonly loadDetail?: DetailLoader;
236
242
  /**
@@ -292,8 +298,10 @@ declare function GaugeWidget({ data, }: {
292
298
  readonly data: GaugeWidgetData;
293
299
  }): ReactNode;
294
300
  /** TABLE: a data table; cells with a safe `href` become links. */
295
- declare function TableWidget({ data, }: {
301
+ declare function TableWidget({ data, controls, }: {
296
302
  readonly data: TableWidgetData;
303
+ /** Search box and sortable headers; see `WidgetDefinition.tableControls`. */
304
+ readonly controls?: ResolvedTableControls | undefined;
297
305
  }): ReactNode;
298
306
  /**
299
307
  * BAR_LIST: labelled horizontal bars. One series, so one color (slot 1)
@@ -307,8 +315,10 @@ declare function AlertListWidget({ data, }: {
307
315
  readonly data: AlertListWidgetData;
308
316
  }): ReactNode;
309
317
  /** Renders any payload with the renderer for its kind. */
310
- declare function WidgetContent({ data, }: {
318
+ declare function WidgetContent({ data, tableControls, }: {
311
319
  readonly data: WidgetData;
320
+ /** Search and sort for TABLE data; see `resolveTableControls`. */
321
+ readonly tableControls?: ResolvedTableControls | undefined;
312
322
  }): ReactNode;
313
323
 
314
324
  interface UseWidgetsOptions extends ResolveOptions {
package/dist/react.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ReactNode, RefObject } from 'react';
2
- import { D as DashboardWidget, W as WidgetSize, a as WidgetFill, G as GraphWidgetData, N as NiceDomain, b as WidgetDefinition, c as DetailProviderOptions, d as DetailData, e as DetailQuery, L as Locale, f as DashboardLayout, A as AlertListWidgetData, B as BarListWidgetData, g as GaugeWidgetData, K as KpiWidgetData, T as TableWidgetData, h as TextWidgetData, i as WidgetData, R as ResolveOptions, j as WidgetContext, k as WidgetProviders } from './scale-dWDGE1zW.js';
2
+ import { D as DashboardWidget, W as WidgetSize, a as WidgetFill, G as GraphWidgetData, N as NiceDomain, b as WidgetDefinition, c as DetailProviderOptions, d as DetailData, e as DetailQuery, L as Locale, f as DashboardLayout, A as AlertListWidgetData, B as BarListWidgetData, g as GaugeWidgetData, K as KpiWidgetData, T as TableWidgetData, R as ResolvedTableControls, h as TextWidgetData, i as WidgetData, j as ResolveOptions, k as WidgetContext, l as WidgetProviders } from './scale-D51ZGIF4.js';
3
3
 
4
4
  interface WidgetCardProps {
5
5
  readonly title: string;
@@ -88,8 +88,10 @@ declare function GraphWidget({ data, title, }: {
88
88
  /**
89
89
  * Loads a widget's full detail data. Close over your own context (a Prisma
90
90
  * client, a fetch) here; the package never fetches. See `DetailProvider`.
91
+ * Return `undefined` for a widget you have no extra data for: the card's own
92
+ * data is used when it is complete (see `deriveDetailData`).
91
93
  */
92
- type DetailLoader = (definition: WidgetDefinition, options: DetailProviderOptions) => DetailData | Promise<DetailData>;
94
+ type DetailLoader = (definition: WidgetDefinition, options: DetailProviderOptions) => DetailData | undefined | Promise<DetailData | undefined>;
93
95
  interface WidgetDetailProps {
94
96
  /** Table caption: the widget's title. */
95
97
  readonly title: string;
@@ -135,9 +137,12 @@ interface DetailLoadState {
135
137
  /**
136
138
  * Loads a widget's detail data while `enabled`: calls `load` with an abort
137
139
  * signal (aborted on close, retry or unmount), validates the result and
138
- * reports loading, ok or error. `reload` runs it again.
140
+ * reports loading, ok or error. When `load` is missing or returns
141
+ * `undefined`, `fallback` (for example the card's own complete data) is used
142
+ * instead. `reload` runs it again. Keep `load` and `fallback` referentially
143
+ * stable (`useCallback` / `useMemo`): a new value restarts the load.
139
144
  */
140
- declare function useDetailData(definition: WidgetDefinition, load: DetailLoader | undefined, enabled: boolean): {
145
+ declare function useDetailData(definition: WidgetDefinition, load: DetailLoader | undefined, enabled: boolean, fallback?: DetailData): {
141
146
  readonly state: DetailLoadState;
142
147
  readonly reload: () => void;
143
148
  };
@@ -228,9 +233,10 @@ interface DashboardProps extends WidgetSettings {
228
233
  readonly onRetry?: (key: string) => void;
229
234
  /**
230
235
  * Loads the full data for a widget's detail view (widgets whose definition
231
- * sets `detail`). Close over your own context. Without it, TABLE widgets
232
- * with no footer and BAR_LIST widgets show their card data; other widgets
233
- * get no View button.
236
+ * sets `detail`). Close over your own context. Return `undefined` for a
237
+ * widget you have no extra data for: a TABLE with no footer or a BAR_LIST
238
+ * then shows its card data. Without `loadDetail`, those two still work and
239
+ * other widgets get no View button.
234
240
  */
235
241
  readonly loadDetail?: DetailLoader;
236
242
  /**
@@ -292,8 +298,10 @@ declare function GaugeWidget({ data, }: {
292
298
  readonly data: GaugeWidgetData;
293
299
  }): ReactNode;
294
300
  /** TABLE: a data table; cells with a safe `href` become links. */
295
- declare function TableWidget({ data, }: {
301
+ declare function TableWidget({ data, controls, }: {
296
302
  readonly data: TableWidgetData;
303
+ /** Search box and sortable headers; see `WidgetDefinition.tableControls`. */
304
+ readonly controls?: ResolvedTableControls | undefined;
297
305
  }): ReactNode;
298
306
  /**
299
307
  * BAR_LIST: labelled horizontal bars. One series, so one color (slot 1)
@@ -307,8 +315,10 @@ declare function AlertListWidget({ data, }: {
307
315
  readonly data: AlertListWidgetData;
308
316
  }): ReactNode;
309
317
  /** Renders any payload with the renderer for its kind. */
310
- declare function WidgetContent({ data, }: {
318
+ declare function WidgetContent({ data, tableControls, }: {
311
319
  readonly data: WidgetData;
320
+ /** Search and sort for TABLE data; see `resolveTableControls`. */
321
+ readonly tableControls?: ResolvedTableControls | undefined;
312
322
  }): ReactNode;
313
323
 
314
324
  interface UseWidgetsOptions extends ResolveOptions {