@dashboard-designer/ui 0.2.0 → 0.2.2
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 +63 -0
- package/dist/index.d.ts +34 -6
- package/dist/index.js +5346 -4919
- package/dist/styles.css +165 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -172,3 +172,66 @@ 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.
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
## Hide toolbar controls from application code
|
|
215
|
+
|
|
216
|
+
Use `toolbarVisibility` on the designer or viewer. Set a key to `false` to hide
|
|
217
|
+
that control; omitted keys retain their normal behavior. `true` does not override
|
|
218
|
+
read-only mode, permissions, or the dashboard's export settings.
|
|
219
|
+
|
|
220
|
+
```ts
|
|
221
|
+
const toolbarVisibility = { share: false, settings: false, print: false, pdf: false, json: false, email: false };
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
```tsx
|
|
225
|
+
<DashboardViewer dashboard={dashboard} apiBaseUrl={apiBaseUrl} auth={auth}
|
|
226
|
+
toolbarVisibility={toolbarVisibility} />
|
|
227
|
+
// Use hideToolbar={true} to hide the entire header, including custom buttons.
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
Supported keys: `refresh`, `lastRefresh`, `filters`, `variables`, `print`, `pdf`,
|
|
231
|
+
`json`, `email`, `edit`, `share`, `settings`, `history`, `undo`, `redo`, `reset`,
|
|
232
|
+
`add`, `save`, `drillBack`, and `import` (Angular's built-in import control).
|
|
233
|
+
For custom buttons use their existing `visible: false` or `visible: context =>
|
|
234
|
+
boolean` option. Update the inputs/props to change visibility at runtime. These
|
|
235
|
+
options are application configuration and are not saved in dashboard JSON.
|
|
236
|
+
Hiding a control is presentation only, not an authorization mechanism; keyboard
|
|
237
|
+
shortcuts and other entry points remain subject to their existing permissions.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,40 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import React__default from 'react';
|
|
3
|
-
import {
|
|
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
|
+
hideToolbar?: boolean;
|
|
33
|
+
toolbarVisibility?: DashboardToolbarVisibility;
|
|
34
|
+
}
|
|
35
|
+
/** False hides a built-in control; omitted keys retain normal behavior. */
|
|
36
|
+
type DashboardToolbarVisibility = Partial<Record<'refresh' | 'filters' | 'variables' | 'print' | 'pdf' | 'json' | 'email' | 'edit' | 'share' | 'settings' | 'history' | 'undo' | 'redo' | 'reset' | 'add' | 'save' | 'import' | 'drillBack' | 'lastRefresh', boolean>>;
|
|
37
|
+
|
|
10
38
|
interface ChartDataRowActionContext {
|
|
11
39
|
dashboardId: string;
|
|
12
40
|
widget: Widget;
|
|
@@ -34,7 +62,7 @@ interface DashboardVariableProps {
|
|
|
34
62
|
resolveVariables?: (dashboard: Dashboard) => Record<string, VariableValue> | Promise<Record<string, VariableValue>>;
|
|
35
63
|
}
|
|
36
64
|
|
|
37
|
-
interface DashboardDesignerProps extends DashboardVariableProps, ChartDataActionProps {
|
|
65
|
+
interface DashboardDesignerProps extends DashboardVariableProps, ChartDataActionProps, DashboardToolbarProps {
|
|
38
66
|
dashboard?: Dashboard;
|
|
39
67
|
apiBaseUrl: string;
|
|
40
68
|
auth: AuthConfig;
|
|
@@ -45,9 +73,9 @@ interface DashboardDesignerProps extends DashboardVariableProps, ChartDataAction
|
|
|
45
73
|
/** When set, shows Edit / Done in the dashboard toolbar. */
|
|
46
74
|
onToggleEdit?: () => void;
|
|
47
75
|
}
|
|
48
|
-
declare function DashboardDesigner({ dashboard: initial, apiBaseUrl, auth, locale, onChange, onSave, readOnly, onToggleEdit, predefinedVariables, variableValues, variablesReady, resolveVariables, chartDataRowActions, }: DashboardDesignerProps): React__default.JSX.Element;
|
|
76
|
+
declare function DashboardDesigner({ dashboard: initial, apiBaseUrl, auth, locale, onChange, onSave, readOnly, onToggleEdit, predefinedVariables, variableValues, variablesReady, resolveVariables, chartDataRowActions, toolbarButtons, hideToolbar, toolbarVisibility, }: DashboardDesignerProps): React__default.JSX.Element;
|
|
49
77
|
|
|
50
|
-
interface DashboardViewerProps extends DashboardVariableProps, ChartDataActionProps {
|
|
78
|
+
interface DashboardViewerProps extends DashboardVariableProps, ChartDataActionProps, DashboardToolbarProps {
|
|
51
79
|
dashboard: Dashboard;
|
|
52
80
|
apiBaseUrl: string;
|
|
53
81
|
auth: AuthConfig;
|
|
@@ -256,4 +284,4 @@ declare function downloadDashboardJson(dashboard: Dashboard): void;
|
|
|
256
284
|
/** Read a File as text and return JSON. */
|
|
257
285
|
declare function readJsonFile(file: File): Promise<unknown>;
|
|
258
286
|
|
|
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 };
|
|
287
|
+
export { type ChartDataActionProps, type ChartDataRowAction, type ChartDataRowActionContext, ChartRenderer, DashboardApiClient, DashboardDesigner, type DashboardDesignerProps, type DashboardToolbarButton, type DashboardToolbarContext, type DashboardToolbarProps, type DashboardToolbarVisibility, type DashboardVariableProps, DashboardViewer, type DashboardViewerProps, FieldHelp, type FieldHelpProps, FieldLabel, type FieldLabelProps, FilterBar, ICON_SIZE, SearchableSelect, type SearchableSelectProps, chartTypeIcon, downloadDashboardJson, ensureI18n, navIcon, readJsonFile };
|