@dashboard-designer/ui 0.2.0 → 0.2.1

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/README.md CHANGED
@@ -172,3 +172,40 @@ To define report variables from configuration:
172
172
  report.variables = [{ name: 'minimumAmount', type: 'number', defaultValue: 100 }];
173
173
  report.variableDefaults = { LoggedInUserDepartment: 'development' };
174
174
  ```
175
+
176
+
177
+ ## Custom report toolbar buttons
178
+
179
+ Both `DashboardDesigner` and `DashboardViewer` accept `toolbarButtons`.
180
+
181
+ ```tsx
182
+ import { DashboardViewer, type DashboardToolbarButton } from '@dashboard-designer/ui';
183
+
184
+ const toolbarButtons: DashboardToolbarButton[] = [{
185
+ id: 'recalculate',
186
+ label: 'Recalculate',
187
+ icon: <span>↻</span>, // Any React node, including your SVG/icon component.
188
+ mode: 'view',
189
+ onClick: async ({ dashboardId, variables, refresh }) => {
190
+ await recalculateReport(dashboardId, variables.loggedInUserId);
191
+ await refresh();
192
+ },
193
+ }];
194
+
195
+ <DashboardViewer dashboard={dashboard} apiBaseUrl={apiBaseUrl} auth={auth}
196
+ toolbarButtons={toolbarButtons} />
197
+ ```
198
+
199
+ Use unique `id` values. `label` and `onClick` are required; `icon` and `title` are
200
+ optional. `mode` can be `view`, `edit`, or `both` (default). `visible` and `disabled`
201
+ accept booleans or side-effect-free predicates receiving the current context.
202
+ Callbacks receive `dashboard`, `dashboardId`, `mode`, resolved `variables`, and
203
+ async `refresh()` which reloads report data bypassing the server cache. Callbacks
204
+ receive snapshots of the dashboard and variables. Drill-down uses the report
205
+ currently displayed; refresh becomes a no-op after navigation to another report.
206
+ Each pending callback displays a spinner and disables repeat clicks on that
207
+ button. Errors appear in the toolbar. Omit the prop or use `[]` to show no custom
208
+ buttons. These application-provided callbacks are not stored in dashboard JSON.
209
+
210
+ The native Angular package exposes the equivalent `[toolbarButtons]` input on
211
+ its designer and viewer, using text or `TemplateRef` icons instead of React nodes.
package/dist/index.d.ts CHANGED
@@ -1,12 +1,36 @@
1
1
  import * as React from 'react';
2
- import React__default from 'react';
3
- import { Widget, DashboardVariable, VariableValue, Dashboard, AuthConfig, User, EmbedTokenRequest, EmbedTokenResponse, ConnectionConfig, ExecuteQueryRequest, QueryResult, ProcedureParameter, DashboardAclEntry, DashboardPermission, DashboardVersionMeta, DashboardVersion, FilterDef, WidgetType } from '@dashboard-designer/core';
2
+ import React__default, { ReactNode } from 'react';
3
+ import { Dashboard, VariableValue, Widget, DashboardVariable, AuthConfig, User, EmbedTokenRequest, EmbedTokenResponse, ConnectionConfig, ExecuteQueryRequest, QueryResult, ProcedureParameter, DashboardAclEntry, DashboardPermission, DashboardVersionMeta, DashboardVersion, FilterDef, WidgetType } from '@dashboard-designer/core';
4
4
  export { AuthConfig, ConnectionConfig, DASHBOARD_FILE_FORMAT, DASHBOARD_FILE_VERSION, Dashboard, DashboardVariable, FilterDef, VariableValue, Widget, buildDashboardExportFile, cloneDashboardForImport, parseDashboardImport } from '@dashboard-designer/core';
5
5
  import * as i18next from 'i18next';
6
6
  export { default as i18n } from 'i18next';
7
7
  import * as lucide_react from 'lucide-react';
8
8
  import { LucideIcon } from 'lucide-react';
9
9
 
10
+ interface DashboardToolbarContext {
11
+ dashboard: Dashboard;
12
+ dashboardId: string;
13
+ mode: 'view' | 'edit';
14
+ variables: Readonly<Record<string, VariableValue>>;
15
+ /** Reload the current report, bypassing the server cache. */
16
+ refresh: () => Promise<void>;
17
+ }
18
+ interface DashboardToolbarButton {
19
+ /** Unique, stable identifier within this toolbar. */
20
+ id: string;
21
+ label: string;
22
+ title?: string;
23
+ icon?: ReactNode;
24
+ /** Defaults to both edit and view modes. */
25
+ mode?: 'view' | 'edit' | 'both';
26
+ visible?: boolean | ((context: DashboardToolbarContext) => boolean);
27
+ disabled?: boolean | ((context: DashboardToolbarContext) => boolean);
28
+ onClick: (context: DashboardToolbarContext) => void | Promise<void>;
29
+ }
30
+ interface DashboardToolbarProps {
31
+ toolbarButtons?: readonly DashboardToolbarButton[];
32
+ }
33
+
10
34
  interface ChartDataRowActionContext {
11
35
  dashboardId: string;
12
36
  widget: Widget;
@@ -34,7 +58,7 @@ interface DashboardVariableProps {
34
58
  resolveVariables?: (dashboard: Dashboard) => Record<string, VariableValue> | Promise<Record<string, VariableValue>>;
35
59
  }
36
60
 
37
- interface DashboardDesignerProps extends DashboardVariableProps, ChartDataActionProps {
61
+ interface DashboardDesignerProps extends DashboardVariableProps, ChartDataActionProps, DashboardToolbarProps {
38
62
  dashboard?: Dashboard;
39
63
  apiBaseUrl: string;
40
64
  auth: AuthConfig;
@@ -45,9 +69,9 @@ interface DashboardDesignerProps extends DashboardVariableProps, ChartDataAction
45
69
  /** When set, shows Edit / Done in the dashboard toolbar. */
46
70
  onToggleEdit?: () => void;
47
71
  }
48
- declare function DashboardDesigner({ dashboard: initial, apiBaseUrl, auth, locale, onChange, onSave, readOnly, onToggleEdit, predefinedVariables, variableValues, variablesReady, resolveVariables, chartDataRowActions, }: DashboardDesignerProps): React__default.JSX.Element;
72
+ declare function DashboardDesigner({ dashboard: initial, apiBaseUrl, auth, locale, onChange, onSave, readOnly, onToggleEdit, predefinedVariables, variableValues, variablesReady, resolveVariables, chartDataRowActions, toolbarButtons, }: DashboardDesignerProps): React__default.JSX.Element;
49
73
 
50
- interface DashboardViewerProps extends DashboardVariableProps, ChartDataActionProps {
74
+ interface DashboardViewerProps extends DashboardVariableProps, ChartDataActionProps, DashboardToolbarProps {
51
75
  dashboard: Dashboard;
52
76
  apiBaseUrl: string;
53
77
  auth: AuthConfig;
@@ -256,4 +280,4 @@ declare function downloadDashboardJson(dashboard: Dashboard): void;
256
280
  /** Read a File as text and return JSON. */
257
281
  declare function readJsonFile(file: File): Promise<unknown>;
258
282
 
259
- export { type ChartDataActionProps, type ChartDataRowAction, type ChartDataRowActionContext, ChartRenderer, DashboardApiClient, DashboardDesigner, type DashboardDesignerProps, type DashboardVariableProps, DashboardViewer, type DashboardViewerProps, FieldHelp, type FieldHelpProps, FieldLabel, type FieldLabelProps, FilterBar, ICON_SIZE, SearchableSelect, type SearchableSelectProps, chartTypeIcon, downloadDashboardJson, ensureI18n, navIcon, readJsonFile };
283
+ export { type ChartDataActionProps, type ChartDataRowAction, type ChartDataRowActionContext, ChartRenderer, DashboardApiClient, DashboardDesigner, type DashboardDesignerProps, type DashboardToolbarButton, type DashboardToolbarContext, type DashboardToolbarProps, type DashboardVariableProps, DashboardViewer, type DashboardViewerProps, FieldHelp, type FieldHelpProps, FieldLabel, type FieldLabelProps, FilterBar, ICON_SIZE, SearchableSelect, type SearchableSelectProps, chartTypeIcon, downloadDashboardJson, ensureI18n, navIcon, readJsonFile };