@dashboard-designer/ui 0.1.2 → 0.2.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/README.md +132 -0
- package/dist/index.d.ts +61 -20
- package/dist/index.js +4505 -1317
- package/dist/styles.css +468 -4
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -40,3 +40,135 @@ import '@dashboard-designer/ui/styles.css';
|
|
|
40
40
|
```
|
|
41
41
|
|
|
42
42
|
Requires the `@dashboard-designer/server` API for query execution and connection secrets.
|
|
43
|
+
|
|
44
|
+
## Query cache and dashboard refresh
|
|
45
|
+
|
|
46
|
+
Both the Node and .NET servers cache successful query results in memory for five
|
|
47
|
+
minutes by default. Set these server environment variables (or matching .NET
|
|
48
|
+
configuration keys) and restart the server to change the policy:
|
|
49
|
+
|
|
50
|
+
| Setting | Default | Meaning |
|
|
51
|
+
| --- | --- | --- |
|
|
52
|
+
| `DD_QUERY_CACHE_TTL_SECONDS` | `300` | Expiry from completion of the database fetch; `0` disables caching |
|
|
53
|
+
| `DD_QUERY_CACHE_MAX_ENTRIES` | `200` | Maximum cached query results |
|
|
54
|
+
| `DD_QUERY_CACHE_MAX_BYTES` | `67108864` | Maximum serialized result bytes retained; larger individual results are not cached |
|
|
55
|
+
|
|
56
|
+
Normal dashboard loads reuse unexpired results. After expiry, the next request
|
|
57
|
+
queries the database. The toolbar **Refresh dashboard data** icon bypasses the
|
|
58
|
+
cache for every query widget and replaces its entry with fresh results. Widget
|
|
59
|
+
**Run query** also bypasses the cache. There is no automatic background database
|
|
60
|
+
refresh when the dashboard sits idle.
|
|
61
|
+
|
|
62
|
+
**Last data refresh** displays the oldest database-fetch timestamp among the
|
|
63
|
+
current dashboard widget results, so cached data does not look newly fetched.
|
|
64
|
+
It updates after every query widget succeeds. During refresh or on failures, the
|
|
65
|
+
previous successful timestamp remains with a progress/error indicator.
|
|
66
|
+
|
|
67
|
+
Cache keys include the authenticated user, connection configuration, dashboard ID,
|
|
68
|
+
SQL, and resolved parameter values. Authorization is checked on every request,
|
|
69
|
+
including cache hits. Cache entries are local to each server process, are lost on
|
|
70
|
+
restart, and are bounded by count and serialized payload bytes. Multi-instance
|
|
71
|
+
deployments have independent caches. Failed requests are never cached.
|
|
72
|
+
|
|
73
|
+
The execute-query API accepts `dashboardId` and `refresh: true` for a forced fetch.
|
|
74
|
+
Results include `result.fetchedAt` and `cache: { hit, expiresAt }`.
|
|
75
|
+
|
|
76
|
+
## Report variable configuration
|
|
77
|
+
|
|
78
|
+
In edit mode, **Variables** opens the report variable editor. Authors can add text,
|
|
79
|
+
number, and boolean variables and defaults. Definitions supplied by the host app
|
|
80
|
+
appear under **Predefined variables**: their names and types cannot be edited,
|
|
81
|
+
but authors can save report-specific preview defaults. Definitions and defaults
|
|
82
|
+
are included in dashboard saves, history, and JSON exports. Runtime values are not.
|
|
83
|
+
|
|
84
|
+
Both `DashboardDesigner` and `DashboardViewer` accept these props:
|
|
85
|
+
|
|
86
|
+
```tsx
|
|
87
|
+
import { DashboardViewer, type DashboardVariable, type Dashboard } from '@dashboard-designer/ui';
|
|
88
|
+
|
|
89
|
+
const predefinedVariables: DashboardVariable[] = [
|
|
90
|
+
{ name: 'loggedInUserId', type: 'string', defaultValue: 'preview-user' },
|
|
91
|
+
{ name: 'LoggedInUserDepartment', type: 'string', defaultValue: 'development' },
|
|
92
|
+
];
|
|
93
|
+
|
|
94
|
+
// Update these props from React state when the signed-in user changes.
|
|
95
|
+
<DashboardViewer
|
|
96
|
+
dashboard={report}
|
|
97
|
+
apiBaseUrl="/"
|
|
98
|
+
auth={{ mode: 'token', token }}
|
|
99
|
+
predefinedVariables={predefinedVariables}
|
|
100
|
+
variablesReady={userLoaded}
|
|
101
|
+
variableValues={{
|
|
102
|
+
loggedInUserId: user?.id ?? 'admin',
|
|
103
|
+
LoggedInUserDepartment: user?.department ?? 'development',
|
|
104
|
+
}}
|
|
105
|
+
/>
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
With `variablesReady={false}`, no widget queries run and old query results are hidden.
|
|
109
|
+
Set it to true after values are available. Changing values refreshes queries.
|
|
110
|
+
For asynchronous setup after a report is supplied, use a stable callback instead:
|
|
111
|
+
|
|
112
|
+
```tsx
|
|
113
|
+
import { useCallback } from 'react';
|
|
114
|
+
|
|
115
|
+
const resolveVariables = useCallback(async (report: Dashboard) => {
|
|
116
|
+
const user = await loadCurrentUser();
|
|
117
|
+
return { loggedInUserId: user.id, LoggedInUserDepartment: user.department };
|
|
118
|
+
}, []);
|
|
119
|
+
|
|
120
|
+
<DashboardViewer
|
|
121
|
+
dashboard={report}
|
|
122
|
+
apiBaseUrl="/"
|
|
123
|
+
auth={{ mode: 'token', token }}
|
|
124
|
+
predefinedVariables={predefinedVariables}
|
|
125
|
+
resolveVariables={resolveVariables}
|
|
126
|
+
/>
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
The callback finishes before queries start. It reruns when the report ID or variable
|
|
130
|
+
definitions/defaults change, or when the callback changes. Failed callbacks show an
|
|
131
|
+
error and prevent data loading. Memoize the callback with `useCallback`.
|
|
132
|
+
|
|
133
|
+
Precedence, highest first: `variableValues`, values returned by `resolveVariables`,
|
|
134
|
+
report defaults for predefined variables, definition defaults. Runtime overrides can
|
|
135
|
+
also target report-defined variables by name. Names are case-sensitive and must start
|
|
136
|
+
with a letter or underscore and contain only letters, digits, and underscores.
|
|
137
|
+
An unset referenced variable fails the query rather than substituting an empty value.
|
|
138
|
+
Values must match the declared type; explicit NULL is supported.
|
|
139
|
+
|
|
140
|
+
Use the **Use variable** pickers in filter values and the **Variable** stored-procedure
|
|
141
|
+
parameter mode. Variable references also work in the conditions of a parameter's
|
|
142
|
+
**Where clause** mode and in frontend filter values. Use `{{var:name}}` for a typed
|
|
143
|
+
value, or include a token in text such as `%{{var:searchText}}%` for a LIKE filter.
|
|
144
|
+
In Direct SQL, insert an **unquoted value token**:
|
|
145
|
+
|
|
146
|
+
```sql
|
|
147
|
+
SELECT * FROM Employees
|
|
148
|
+
WHERE UserId = {{var:loggedInUserId}}
|
|
149
|
+
AND Department = {{var:LoggedInUserDepartment}}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
SQL values are bound as database parameters. Tokens cannot replace table/column names
|
|
153
|
+
or appear inside SQL quotes. The existing `{{filters}}` token remains supported.
|
|
154
|
+
Use current Node or .NET backend packages for SQL variable binding. Browser-provided
|
|
155
|
+
variables are report inputs; enforce authorization separately on the server.
|
|
156
|
+
|
|
157
|
+
For manually entered stored-procedure parameters containing `WHERE ...` text (or
|
|
158
|
+
parameters named `@WhereClause`), embedded variable tokens are SQL-quoted and escaped.
|
|
159
|
+
For example, `WHERE [Initiated Division] IN ({{var:division}})` with `Hinjewadi Pune`
|
|
160
|
+
becomes `WHERE [Initiated Division] IN (N'Hinjewadi Pune')`. Existing quotes around
|
|
161
|
+
a token are respected. Plain parameter values and exact variable references remain
|
|
162
|
+
ordinary bound values.
|
|
163
|
+
|
|
164
|
+
Run Query displays the full statement with parameter values rendered for inspection.
|
|
165
|
+
The API returns this as `renderedSql`; `sql` remains the parameterized statement.
|
|
166
|
+
Execution continues to use bound parameters. Stored-procedure previews show the
|
|
167
|
+
procedure invocation and argument values, not SQL constructed internally by the procedure.
|
|
168
|
+
|
|
169
|
+
To define report variables from configuration:
|
|
170
|
+
|
|
171
|
+
```ts
|
|
172
|
+
report.variables = [{ name: 'minimumAmount', type: 'number', defaultValue: 100 }];
|
|
173
|
+
report.variableDefaults = { LoggedInUserDepartment: 'development' };
|
|
174
|
+
```
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,40 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import
|
|
3
|
-
import { Dashboard, AuthConfig, User, EmbedTokenRequest, EmbedTokenResponse, ConnectionConfig, ExecuteQueryRequest, QueryResult, DashboardAclEntry, DashboardPermission, DashboardVersionMeta, DashboardVersion,
|
|
4
|
-
export { AuthConfig, ConnectionConfig, Dashboard, FilterDef, Widget } from '@dashboard-designer/core';
|
|
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';
|
|
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
|
|
10
|
+
interface ChartDataRowActionContext {
|
|
11
|
+
dashboardId: string;
|
|
12
|
+
widget: Widget;
|
|
13
|
+
/** Complete returned row, including columns hidden in the popup. */
|
|
14
|
+
row: Record<string, unknown>;
|
|
15
|
+
category: unknown;
|
|
16
|
+
}
|
|
17
|
+
interface ChartDataRowAction {
|
|
18
|
+
id: string;
|
|
19
|
+
label: string;
|
|
20
|
+
icon: React__default.ReactNode;
|
|
21
|
+
onClick: (context: ChartDataRowActionContext) => void | Promise<void>;
|
|
22
|
+
isVisible?: (context: ChartDataRowActionContext) => boolean;
|
|
23
|
+
}
|
|
24
|
+
interface ChartDataActionProps {
|
|
25
|
+
chartDataRowActions?: readonly ChartDataRowAction[];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface DashboardVariableProps {
|
|
29
|
+
predefinedVariables?: DashboardVariable[];
|
|
30
|
+
variableValues?: Record<string, VariableValue>;
|
|
31
|
+
/** Set false until the host application has supplied its runtime values. */
|
|
32
|
+
variablesReady?: boolean;
|
|
33
|
+
/** Runs before queries, and again when the report or variable definitions change. */
|
|
34
|
+
resolveVariables?: (dashboard: Dashboard) => Record<string, VariableValue> | Promise<Record<string, VariableValue>>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
interface DashboardDesignerProps extends DashboardVariableProps, ChartDataActionProps {
|
|
11
38
|
dashboard?: Dashboard;
|
|
12
39
|
apiBaseUrl: string;
|
|
13
40
|
auth: AuthConfig;
|
|
@@ -18,16 +45,16 @@ interface DashboardDesignerProps {
|
|
|
18
45
|
/** When set, shows Edit / Done in the dashboard toolbar. */
|
|
19
46
|
onToggleEdit?: () => void;
|
|
20
47
|
}
|
|
21
|
-
declare function DashboardDesigner({ dashboard: initial, apiBaseUrl, auth, locale, onChange, onSave, readOnly, onToggleEdit, }: DashboardDesignerProps):
|
|
48
|
+
declare function DashboardDesigner({ dashboard: initial, apiBaseUrl, auth, locale, onChange, onSave, readOnly, onToggleEdit, predefinedVariables, variableValues, variablesReady, resolveVariables, chartDataRowActions, }: DashboardDesignerProps): React__default.JSX.Element;
|
|
22
49
|
|
|
23
|
-
interface DashboardViewerProps {
|
|
50
|
+
interface DashboardViewerProps extends DashboardVariableProps, ChartDataActionProps {
|
|
24
51
|
dashboard: Dashboard;
|
|
25
52
|
apiBaseUrl: string;
|
|
26
53
|
auth: AuthConfig;
|
|
27
54
|
locale?: string;
|
|
28
55
|
}
|
|
29
56
|
/** Read-only dashboard renderer for embeds / published views. */
|
|
30
|
-
declare function DashboardViewer({ dashboard, apiBaseUrl, auth, locale }: DashboardViewerProps):
|
|
57
|
+
declare function DashboardViewer({ dashboard, apiBaseUrl, auth, locale, ...variables }: DashboardViewerProps): React__default.JSX.Element;
|
|
31
58
|
|
|
32
59
|
declare class DashboardApiClient {
|
|
33
60
|
apiBaseUrl: string;
|
|
@@ -67,6 +94,14 @@ declare class DashboardApiClient {
|
|
|
67
94
|
executeQuery(body: ExecuteQueryRequest): Promise<{
|
|
68
95
|
result: QueryResult;
|
|
69
96
|
sql: string;
|
|
97
|
+
renderedSql?: string;
|
|
98
|
+
cache?: {
|
|
99
|
+
hit: boolean;
|
|
100
|
+
expiresAt: string;
|
|
101
|
+
};
|
|
102
|
+
}>;
|
|
103
|
+
listProcedureParameters(connectionId: string, name: string): Promise<{
|
|
104
|
+
parameters: ProcedureParameter[];
|
|
70
105
|
}>;
|
|
71
106
|
listDashboards(): Promise<{
|
|
72
107
|
dashboards: Array<{
|
|
@@ -148,12 +183,13 @@ interface ChartRendererProps {
|
|
|
148
183
|
/** Dashboard / theme chart palette (falls back to defaults). */
|
|
149
184
|
chartColors?: string[];
|
|
150
185
|
loading?: boolean;
|
|
186
|
+
onDataClick?: (category: unknown, dimension: string) => void;
|
|
151
187
|
onDrillDown?: (payload: Record<string, unknown>) => void;
|
|
152
188
|
/** Current list-box selection (empty = All). */
|
|
153
189
|
listboxSelection?: Array<string | number>;
|
|
154
190
|
onListboxSelectionChange?: (values: Array<string | number>) => void;
|
|
155
191
|
}
|
|
156
|
-
declare function ChartRenderer({ widget, data, locale, currency, loading, onDrillDown, listboxSelection, onListboxSelectionChange, chartColors, }: ChartRendererProps):
|
|
192
|
+
declare function ChartRenderer({ widget, data, locale, currency, loading, onDrillDown, onDataClick, listboxSelection, onListboxSelectionChange, chartColors, }: ChartRendererProps): React__default.JSX.Element;
|
|
157
193
|
|
|
158
194
|
interface FilterBarProps {
|
|
159
195
|
filters: FilterDef[];
|
|
@@ -171,7 +207,7 @@ interface FilterBarProps {
|
|
|
171
207
|
/** Applied to newly added filters (where = row-level, having = aggregated). */
|
|
172
208
|
defaultClause?: 'where' | 'having';
|
|
173
209
|
}
|
|
174
|
-
declare function FilterBar({ filters, onChange, title, hint, editable, fieldOptions, fieldPlaceholder, fieldEmptyLabel, fieldDisabled, hideHeader, defaultClause, }: FilterBarProps):
|
|
210
|
+
declare function FilterBar({ filters, onChange, title, hint, editable, fieldOptions, fieldPlaceholder, fieldEmptyLabel, fieldDisabled, hideHeader, defaultClause, }: FilterBarProps): React__default.JSX.Element;
|
|
175
211
|
|
|
176
212
|
declare function ensureI18n(locale?: string): i18next.i18n;
|
|
177
213
|
|
|
@@ -185,7 +221,7 @@ interface SearchableSelectProps {
|
|
|
185
221
|
disabled?: boolean;
|
|
186
222
|
emptyLabel?: string;
|
|
187
223
|
}
|
|
188
|
-
declare function SearchableSelect({ id, options, value, onChange, placeholder, multiple, disabled, emptyLabel, }: SearchableSelectProps):
|
|
224
|
+
declare function SearchableSelect({ id, options, value, onChange, placeholder, multiple, disabled, emptyLabel, }: SearchableSelectProps): React__default.JSX.Element;
|
|
189
225
|
|
|
190
226
|
interface FieldHelpProps {
|
|
191
227
|
/** Help text shown in the tooltip. */
|
|
@@ -194,25 +230,30 @@ interface FieldHelpProps {
|
|
|
194
230
|
label?: string;
|
|
195
231
|
}
|
|
196
232
|
/** Compact help icon with a portal tooltip that stays fully on-screen. */
|
|
197
|
-
declare function FieldHelp({ text, label }: FieldHelpProps):
|
|
233
|
+
declare function FieldHelp({ text, label }: FieldHelpProps): React__default.JSX.Element | null;
|
|
198
234
|
interface FieldLabelProps {
|
|
199
235
|
htmlFor?: string;
|
|
200
|
-
children:
|
|
236
|
+
children: React__default.ReactNode;
|
|
201
237
|
/** Help / usage description for this field. */
|
|
202
238
|
help?: string;
|
|
203
239
|
className?: string;
|
|
204
240
|
}
|
|
205
241
|
/** Field label with an optional inline help icon. */
|
|
206
|
-
declare function FieldLabel({ htmlFor, children, help, className }: FieldLabelProps):
|
|
242
|
+
declare function FieldLabel({ htmlFor, children, help, className }: FieldLabelProps): React__default.JSX.Element;
|
|
207
243
|
|
|
208
244
|
declare const ICON_SIZE = 16;
|
|
209
245
|
declare const chartTypeIcon: Record<WidgetType, LucideIcon>;
|
|
210
246
|
declare const navIcon: {
|
|
211
|
-
readonly dashboards:
|
|
212
|
-
readonly designer:
|
|
213
|
-
readonly viewer:
|
|
214
|
-
readonly connections:
|
|
215
|
-
readonly users:
|
|
247
|
+
readonly dashboards: React.ForwardRefExoticComponent<Omit<lucide_react.LucideProps, "ref"> & React.RefAttributes<SVGSVGElement>>;
|
|
248
|
+
readonly designer: React.ForwardRefExoticComponent<Omit<lucide_react.LucideProps, "ref"> & React.RefAttributes<SVGSVGElement>>;
|
|
249
|
+
readonly viewer: React.ForwardRefExoticComponent<Omit<lucide_react.LucideProps, "ref"> & React.RefAttributes<SVGSVGElement>>;
|
|
250
|
+
readonly connections: React.ForwardRefExoticComponent<Omit<lucide_react.LucideProps, "ref"> & React.RefAttributes<SVGSVGElement>>;
|
|
251
|
+
readonly users: React.ForwardRefExoticComponent<Omit<lucide_react.LucideProps, "ref"> & React.RefAttributes<SVGSVGElement>>;
|
|
216
252
|
};
|
|
217
253
|
|
|
218
|
-
|
|
254
|
+
/** Download the dashboard definition as a JSON file. */
|
|
255
|
+
declare function downloadDashboardJson(dashboard: Dashboard): void;
|
|
256
|
+
/** Read a File as text and return JSON. */
|
|
257
|
+
declare function readJsonFile(file: File): Promise<unknown>;
|
|
258
|
+
|
|
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 };
|