@dashboard-designer/core 0.1.15 → 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/dist/index.d.ts +56 -3
- package/dist/index.js +151 -3
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** Supported database providers (Phase 1 includes SQL Server). */
|
|
2
2
|
type DbProvider = 'sqlite' | 'postgres' | 'mysql' | 'mssql';
|
|
3
|
-
type WidgetType = 'bar' | 'line' | 'pie' | 'table' | 'kpi' | 'listbox' | 'label' | 'labelContainer';
|
|
3
|
+
type WidgetType = 'timeline' | 'bar' | 'line' | 'pie' | 'table' | 'kpi' | 'listbox' | 'label' | 'labelContainer';
|
|
4
4
|
type FilterOperator = 'eq' | 'neq' | 'gt' | 'gte' | 'lt' | 'lte' | 'in' | 'nin' | 'like' | 'between' | 'is_null' | 'not_null';
|
|
5
5
|
type JoinType = 'inner' | 'left' | 'right' | 'full';
|
|
6
6
|
type AuthMode = 'token' | 'anonymous';
|
|
@@ -23,6 +23,8 @@ interface GridItem {
|
|
|
23
23
|
minH?: number;
|
|
24
24
|
}
|
|
25
25
|
interface FilterDef {
|
|
26
|
+
/** Editor control for filter values. Dates are stored as YYYY-MM-DD. */
|
|
27
|
+
dataType?: 'text' | 'date';
|
|
26
28
|
id: string;
|
|
27
29
|
field: string;
|
|
28
30
|
label?: string;
|
|
@@ -39,6 +41,8 @@ interface FilterDef {
|
|
|
39
41
|
* When omitted, inferred from whether the field is an aggregated measure.
|
|
40
42
|
*/
|
|
41
43
|
clause?: 'where' | 'having';
|
|
44
|
+
/** Preserve an explicitly resolved empty variable value in SQL filters. */
|
|
45
|
+
allowEmptyValue?: boolean;
|
|
42
46
|
}
|
|
43
47
|
interface JoinDef {
|
|
44
48
|
id: string;
|
|
@@ -58,6 +62,8 @@ interface QueryDef {
|
|
|
58
62
|
connectionId: string;
|
|
59
63
|
/** When set, runs this SQL (with optional filter injection via {{filters}}) */
|
|
60
64
|
rawSql?: string;
|
|
65
|
+
/** Named inputs for a bare SQL Server EXEC call. Omitted keys use procedure defaults. */
|
|
66
|
+
procedureParameters?: Record<string, string | number | boolean | null | ProcedureWhereClause>;
|
|
61
67
|
tables?: string[];
|
|
62
68
|
joins?: JoinDef[];
|
|
63
69
|
columns?: QueryColumn[];
|
|
@@ -69,6 +75,21 @@ interface QueryDef {
|
|
|
69
75
|
}>;
|
|
70
76
|
limit?: number;
|
|
71
77
|
}
|
|
78
|
+
interface ProcedureParameter {
|
|
79
|
+
name: string;
|
|
80
|
+
type: string;
|
|
81
|
+
isOutput: boolean;
|
|
82
|
+
}
|
|
83
|
+
interface ProcedureWhereClause {
|
|
84
|
+
kind: 'where';
|
|
85
|
+
filters: FilterDef[];
|
|
86
|
+
/** Set false for procedures that expect predicates without the WHERE keyword. */
|
|
87
|
+
includeWhere?: boolean;
|
|
88
|
+
}
|
|
89
|
+
/** Build SQL Server clause text for a procedure's string parameter, not the EXEC statement. */
|
|
90
|
+
declare function buildProcedureWhereClause(value: ProcedureWhereClause): string;
|
|
91
|
+
/** Only a single, bare EXEC call is eligible for the parameter editor. */
|
|
92
|
+
declare function parseStoredProcedureName(sql?: string): string | undefined;
|
|
72
93
|
interface DataBinding {
|
|
73
94
|
dimensions: string[];
|
|
74
95
|
measures: string[];
|
|
@@ -99,6 +120,14 @@ interface ContainerLabelTemplate {
|
|
|
99
120
|
drillTitle?: string;
|
|
100
121
|
}
|
|
101
122
|
type LabelContainerSource = 'static' | 'query';
|
|
123
|
+
interface QueryLabelDrillDown {
|
|
124
|
+
field: string;
|
|
125
|
+
value: string;
|
|
126
|
+
action: 'none' | 'dashboard';
|
|
127
|
+
targetDashboardId?: string;
|
|
128
|
+
drillTitle?: string;
|
|
129
|
+
}
|
|
130
|
+
declare function normalizeQueryLabelDrillDowns(raw: unknown): QueryLabelDrillDown[];
|
|
102
131
|
type ContainerLabelLayout = 'vertical' | 'horizontal';
|
|
103
132
|
type ChartGuidelineAxis = 'x' | 'y';
|
|
104
133
|
/** Reference line on a bar or line chart axis. */
|
|
@@ -118,12 +147,17 @@ interface Widget {
|
|
|
118
147
|
binding: DataBinding;
|
|
119
148
|
chartOptions: Record<string, unknown>;
|
|
120
149
|
filters: FilterDef[];
|
|
150
|
+
/** Applied in the React client to returned rows, never sent as SQL conditions. */
|
|
151
|
+
frontendFilters?: FilterDef[];
|
|
121
152
|
drillDown?: DrillDownDef;
|
|
122
153
|
}
|
|
123
154
|
interface Dashboard {
|
|
124
155
|
id: string;
|
|
125
156
|
title: string;
|
|
126
157
|
description?: string;
|
|
158
|
+
variables?: DashboardVariable[];
|
|
159
|
+
/** Report-specific preview defaults for developer-defined variables. */
|
|
160
|
+
variableDefaults?: Record<string, VariableValue>;
|
|
127
161
|
locale?: string;
|
|
128
162
|
/** ISO 4217 currency code for number formatting (default USD). */
|
|
129
163
|
currency?: string;
|
|
@@ -273,16 +307,35 @@ interface AuthConfig {
|
|
|
273
307
|
token?: string;
|
|
274
308
|
}
|
|
275
309
|
interface QueryResult {
|
|
310
|
+
/** Server timestamp of the database fetch, preserved on cache hits. */
|
|
311
|
+
fetchedAt?: string;
|
|
276
312
|
columns: string[];
|
|
277
313
|
rows: Record<string, unknown>[];
|
|
278
314
|
rowCount: number;
|
|
279
315
|
durationMs: number;
|
|
280
316
|
}
|
|
281
317
|
interface ExecuteQueryRequest {
|
|
318
|
+
/** Bypass and replace the cached result for this query. */
|
|
319
|
+
refresh?: boolean;
|
|
320
|
+
dashboardId?: string;
|
|
282
321
|
query: QueryDef;
|
|
283
322
|
chartFilters?: FilterDef[];
|
|
284
323
|
globalFilters?: FilterDef[];
|
|
324
|
+
variables?: Record<string, VariableValue>;
|
|
325
|
+
}
|
|
326
|
+
type VariableValue = string | number | boolean | null;
|
|
327
|
+
interface DashboardVariable {
|
|
328
|
+
name: string;
|
|
329
|
+
type: 'string' | 'number' | 'boolean';
|
|
330
|
+
description?: string;
|
|
331
|
+
defaultValue?: VariableValue;
|
|
285
332
|
}
|
|
333
|
+
declare function resolveVariableValue(value: unknown, variables?: Record<string, VariableValue>): unknown;
|
|
334
|
+
declare function resolveFilterVariables(filters?: FilterDef[], variables?: Record<string, VariableValue>): FilterDef[];
|
|
335
|
+
/** Preserve ordinary parameter values; quote tokens embedded in SQL WHERE text. */
|
|
336
|
+
declare function resolveProcedureParameterValue(name: string, value: VariableValue, variables: Record<string, VariableValue>): VariableValue;
|
|
337
|
+
declare function resolveRequestVariables(body: ExecuteQueryRequest): ExecuteQueryRequest;
|
|
338
|
+
declare function resolveDashboardVariables(dashboard: Pick<Dashboard, 'variables' | 'variableDefaults'>, predefined?: DashboardVariable[], runtime?: Record<string, VariableValue>): Record<string, VariableValue>;
|
|
286
339
|
declare const WIDGET_TYPES: WidgetType[];
|
|
287
340
|
declare const DB_PROVIDERS: DbProvider[];
|
|
288
341
|
/** Locales that default to RTL when dashboard.dir is unset. */
|
|
@@ -302,7 +355,7 @@ declare function hasContainerLabelTemplateCustomStyles(template: ContainerLabelT
|
|
|
302
355
|
declare function resetContainerLabelTemplateStyles(template: ContainerLabelTemplate): ContainerLabelTemplate;
|
|
303
356
|
declare function resolveLabelContainerSource(chartOptions: Record<string, unknown>): LabelContainerSource;
|
|
304
357
|
/** Build label items from distinct values in a query result column, applying a shared template. */
|
|
305
|
-
declare function buildContainerLabelsFromQuery(rows: Record<string, unknown>[], columns: string[], dimensionField: string | undefined, template: ContainerLabelTemplate): ContainerLabelItem[];
|
|
358
|
+
declare function buildContainerLabelsFromQuery(rows: Record<string, unknown>[], columns: string[], dimensionField: string | undefined, template: ContainerLabelTemplate, drillDowns?: QueryLabelDrillDown[]): ContainerLabelItem[];
|
|
306
359
|
/** Whether label / labelContainer widgets show the widget title bar on the canvas (default true). */
|
|
307
360
|
declare function labelWidgetShowsHeader(chartOptions: Record<string, unknown>): boolean;
|
|
308
361
|
type LabelClickAction = 'none' | 'dashboard' | 'url';
|
|
@@ -319,4 +372,4 @@ declare function createEmptyDashboard(partial?: Partial<Dashboard>): Dashboard;
|
|
|
319
372
|
declare function createEmptyWidget(type?: WidgetType): Widget;
|
|
320
373
|
declare function createId(): string;
|
|
321
374
|
|
|
322
|
-
export { type AuthConfig, type AuthMode, type ChartAxisGuideline, type ChartGuidelineAxis, type ConnectionConfig, type ContainerLabelItem, type ContainerLabelLayout, type ContainerLabelTemplate, DASHBOARD_FILE_FORMAT, DASHBOARD_FILE_VERSION, DB_PROVIDERS, DEFAULT_CHART_COLORS, DEFAULT_THEME_ACCENT, type Dashboard, type DashboardAclEntry, type DashboardDisplayOptions, type DashboardEmailOptions, type DashboardExportOptions, type DashboardFileEnvelope, type DashboardPermission, type DashboardTheme, type DashboardVersion, type DashboardVersionMeta, type DataBinding, type DbProvider, type DrillDownDef, type EmbedTokenRequest, type EmbedTokenResponse, type ExecuteQueryRequest, type FilterDef, type FilterOperator, type GridItem, type JoinDef, type JoinType, LEGACY_LABEL_FOREGROUND, type LabelClickAction, type LabelContainerSource, type QueryColumn, type QueryDef, type QueryResult, RTL_LOCALES, THEME_PRESETS, type User, type UserRole, WIDGET_TYPES, type Widget, type WidgetType, buildContainerLabelsFromQuery, buildDashboardExportFile, cloneDashboardForImport, createChartAxisGuideline, createContainerLabelItem, createEmptyDashboard, createEmptyWidget, createId, getKpiDefaultValue, getLabelClickUrl, hasContainerLabelCustomStyles, hasContainerLabelTemplateCustomStyles, isDefaultDashboardTheme, labelClickOpensNewTab, labelWidgetShowsHeader, matchThemePreset, normalizeChartAxisGuidelines, normalizeContainerLabelTemplate, normalizeContainerLabels, parseDashboardImport, resetContainerLabelItemStyles, resetContainerLabelTemplateStyles, resolveDashboardDir, resolveDashboardTheme, resolveDisplayOptions, resolveEmailOptions, resolveExportOptions, resolveLabelClickAction, resolveLabelContainerSource, sanitizeLabelStyleBackground, sanitizeLabelStyleColor };
|
|
375
|
+
export { type AuthConfig, type AuthMode, type ChartAxisGuideline, type ChartGuidelineAxis, type ConnectionConfig, type ContainerLabelItem, type ContainerLabelLayout, type ContainerLabelTemplate, DASHBOARD_FILE_FORMAT, DASHBOARD_FILE_VERSION, DB_PROVIDERS, DEFAULT_CHART_COLORS, DEFAULT_THEME_ACCENT, type Dashboard, type DashboardAclEntry, type DashboardDisplayOptions, type DashboardEmailOptions, type DashboardExportOptions, type DashboardFileEnvelope, type DashboardPermission, type DashboardTheme, type DashboardVariable, type DashboardVersion, type DashboardVersionMeta, type DataBinding, type DbProvider, type DrillDownDef, type EmbedTokenRequest, type EmbedTokenResponse, type ExecuteQueryRequest, type FilterDef, type FilterOperator, type GridItem, type JoinDef, type JoinType, LEGACY_LABEL_FOREGROUND, type LabelClickAction, type LabelContainerSource, type ProcedureParameter, type ProcedureWhereClause, type QueryColumn, type QueryDef, type QueryLabelDrillDown, type QueryResult, RTL_LOCALES, THEME_PRESETS, type User, type UserRole, type VariableValue, WIDGET_TYPES, type Widget, type WidgetType, buildContainerLabelsFromQuery, buildDashboardExportFile, buildProcedureWhereClause, cloneDashboardForImport, createChartAxisGuideline, createContainerLabelItem, createEmptyDashboard, createEmptyWidget, createId, getKpiDefaultValue, getLabelClickUrl, hasContainerLabelCustomStyles, hasContainerLabelTemplateCustomStyles, isDefaultDashboardTheme, labelClickOpensNewTab, labelWidgetShowsHeader, matchThemePreset, normalizeChartAxisGuidelines, normalizeContainerLabelTemplate, normalizeContainerLabels, normalizeQueryLabelDrillDowns, parseDashboardImport, parseStoredProcedureName, resetContainerLabelItemStyles, resetContainerLabelTemplateStyles, resolveDashboardDir, resolveDashboardTheme, resolveDashboardVariables, resolveDisplayOptions, resolveEmailOptions, resolveExportOptions, resolveFilterVariables, resolveLabelClickAction, resolveLabelContainerSource, resolveProcedureParameterValue, resolveRequestVariables, resolveVariableValue, sanitizeLabelStyleBackground, sanitizeLabelStyleColor };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,57 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
+
function buildProcedureWhereClause(value) {
|
|
3
|
+
if (value.kind !== "where" || !Array.isArray(value.filters) || !value.filters.length) {
|
|
4
|
+
throw new Error("Add at least one condition to the WHERE clause.");
|
|
5
|
+
}
|
|
6
|
+
const literal = (input) => {
|
|
7
|
+
if (typeof input === "string") return `N'${input.replace(/'/g, "''")}'`;
|
|
8
|
+
if (typeof input === "number" && Number.isFinite(input)) return String(input);
|
|
9
|
+
if (typeof input === "boolean") return input ? "1" : "0";
|
|
10
|
+
throw new Error("Enter a value for each WHERE condition.");
|
|
11
|
+
};
|
|
12
|
+
const operators = { eq: "=", neq: "<>", gt: ">", gte: ">=", lt: "<", lte: "<=", like: "LIKE" };
|
|
13
|
+
const conditions = value.filters.map((filter) => {
|
|
14
|
+
if (!filter || typeof filter.field !== "string" || !filter.field.trim()) {
|
|
15
|
+
throw new Error("Select a field for each WHERE condition.");
|
|
16
|
+
}
|
|
17
|
+
const parts = filter.field.split(".");
|
|
18
|
+
if (parts.some((part) => !part.trim())) throw new Error("Invalid WHERE field.");
|
|
19
|
+
const field = parts.map((part) => `[${part.replace(/]/g, "]]")}]`).join(".");
|
|
20
|
+
if (filter.operator === "is_null") return `${field} IS NULL`;
|
|
21
|
+
if (filter.operator === "not_null") return `${field} IS NOT NULL`;
|
|
22
|
+
if (filter.operator === "in" || filter.operator === "nin") {
|
|
23
|
+
const values = Array.isArray(filter.value) ? filter.value : typeof filter.value === "string" ? filter.value.split(",").map((item) => item.trim()) : [];
|
|
24
|
+
if (!values.length || values.some((item) => item === "")) throw new Error("Enter values for the IN condition.");
|
|
25
|
+
return `${field} ${filter.operator === "nin" ? "NOT IN" : "IN"} (${values.map(literal).join(", ")})`;
|
|
26
|
+
}
|
|
27
|
+
if (filter.operator === "between") {
|
|
28
|
+
if (filter.value === "" || filter.valueTo === "") throw new Error("Enter both values for BETWEEN.");
|
|
29
|
+
return `${field} BETWEEN ${literal(filter.value)} AND ${literal(filter.valueTo)}`;
|
|
30
|
+
}
|
|
31
|
+
if (!Object.prototype.hasOwnProperty.call(operators, filter.operator)) throw new Error("Invalid WHERE operator.");
|
|
32
|
+
return `${field} ${operators[filter.operator]} ${literal(filter.value)}`;
|
|
33
|
+
});
|
|
34
|
+
return `${value.includeWhere === false ? "" : "WHERE "}${conditions.map((condition) => `(${condition})`).join(" AND ")}`;
|
|
35
|
+
}
|
|
36
|
+
function parseStoredProcedureName(sql) {
|
|
37
|
+
const identifier = "(?:\\[[^\\]\\r\\n]+\\]|[A-Za-z_][A-Za-z0-9_$#]*)";
|
|
38
|
+
return sql?.match(new RegExp(`^\\s*EXEC(?:UTE)?\\s+(${identifier}(?:\\s*\\.\\s*${identifier})?)\\s*;?\\s*$`, "i"))?.[1];
|
|
39
|
+
}
|
|
40
|
+
function normalizeQueryLabelDrillDowns(raw) {
|
|
41
|
+
if (!Array.isArray(raw)) return [];
|
|
42
|
+
return raw.flatMap((item) => {
|
|
43
|
+
if (!item || typeof item !== "object") return [];
|
|
44
|
+
const rule = item;
|
|
45
|
+
if (typeof rule.field !== "string" || typeof rule.value !== "string" || rule.action !== "none" && rule.action !== "dashboard") return [];
|
|
46
|
+
return [{
|
|
47
|
+
field: rule.field,
|
|
48
|
+
value: rule.value,
|
|
49
|
+
action: rule.action,
|
|
50
|
+
targetDashboardId: typeof rule.targetDashboardId === "string" ? rule.targetDashboardId : void 0,
|
|
51
|
+
drillTitle: typeof rule.drillTitle === "string" ? rule.drillTitle : void 0
|
|
52
|
+
}];
|
|
53
|
+
});
|
|
54
|
+
}
|
|
2
55
|
function resolveDisplayOptions(options) {
|
|
3
56
|
return {
|
|
4
57
|
showWidgetTypeBadge: options?.showWidgetTypeBadge === true
|
|
@@ -72,6 +125,7 @@ function cloneDashboardForImport(source, titleSuffix = " (imported)") {
|
|
|
72
125
|
...w,
|
|
73
126
|
id: nextId,
|
|
74
127
|
filters: remapFilterIds((w.filters ?? []).map((f) => ({ ...f })), idMap),
|
|
128
|
+
frontendFilters: w.frontendFilters?.map((f) => ({ ...f, id: createId() })),
|
|
75
129
|
chartOptions,
|
|
76
130
|
query: {
|
|
77
131
|
...w.query,
|
|
@@ -173,7 +227,90 @@ function matchThemePreset(theme) {
|
|
|
173
227
|
}
|
|
174
228
|
return "custom";
|
|
175
229
|
}
|
|
230
|
+
function resolveVariableValue(value, variables = {}) {
|
|
231
|
+
if (Array.isArray(value)) return value.map((item) => resolveVariableValue(item, variables));
|
|
232
|
+
if (typeof value !== "string") return value;
|
|
233
|
+
const read = (name) => {
|
|
234
|
+
if (!Object.prototype.hasOwnProperty.call(variables, name) || variables[name] === void 0)
|
|
235
|
+
throw new Error(`Variable "${name}" has no value. Set a default or supply it from code.`);
|
|
236
|
+
const resolved = variables[name];
|
|
237
|
+
if (resolved !== null && !["string", "number", "boolean"].includes(typeof resolved)) throw new Error(`Invalid variable value: ${name}`);
|
|
238
|
+
return resolved;
|
|
239
|
+
};
|
|
240
|
+
const exact = value.match(/^\{\{var:([A-Za-z_][A-Za-z0-9_]*)\}\}$/);
|
|
241
|
+
if (exact) return read(exact[1]);
|
|
242
|
+
return value.replace(/\{\{var:([A-Za-z_][A-Za-z0-9_]*)\}\}/g, (_, name) => String(read(name) ?? ""));
|
|
243
|
+
}
|
|
244
|
+
function resolveFilterVariables(filters = [], variables = {}) {
|
|
245
|
+
return filters.map((filter) => {
|
|
246
|
+
if (filter.operator === "is_null" || filter.operator === "not_null") return filter;
|
|
247
|
+
const dynamic = typeof filter.value === "string" && filter.value.includes("{{var:");
|
|
248
|
+
const value = resolveVariableValue(filter.value, variables);
|
|
249
|
+
const valueTo = filter.operator === "between" ? resolveVariableValue(filter.valueTo, variables) : filter.valueTo;
|
|
250
|
+
if (dynamic && value === null) {
|
|
251
|
+
if (filter.operator === "eq" || filter.operator === "neq") return { ...filter, operator: filter.operator === "eq" ? "is_null" : "not_null" };
|
|
252
|
+
throw new Error("NULL variables require an equality or null-check filter.");
|
|
253
|
+
}
|
|
254
|
+
return { ...filter, value, valueTo, ...dynamic ? { allowEmptyValue: true } : {} };
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
function resolveProcedureParameterValue(name, value, variables) {
|
|
258
|
+
if (typeof value !== "string" || /^\{\{var:[A-Za-z_][A-Za-z0-9_]*\}\}$/.test(value) || !/^\s*WHERE\b/i.test(value) && !/^@where(?:clause|condition|filter)?$/i.test(name)) {
|
|
259
|
+
return resolveVariableValue(value, variables);
|
|
260
|
+
}
|
|
261
|
+
const literal = (resolved) => resolved === null ? "NULL" : typeof resolved === "string" ? `N'${resolved.replace(/'/g, "''")}'` : typeof resolved === "boolean" ? resolved ? "1" : "0" : String(resolved);
|
|
262
|
+
return value.replace(/--[^\r\n]*|\/\*[\s\S]*?\*\/|N?'(?:''|[^'])*'|\[(?:\]\]|[^\]])*\]|\{\{var:[A-Za-z_][A-Za-z0-9_]*\}\}/g, (token) => {
|
|
263
|
+
if (token.startsWith("--") || token.startsWith("/*")) return token;
|
|
264
|
+
if (token.startsWith("{{var:")) return literal(resolveVariableValue(token, variables));
|
|
265
|
+
if (token.startsWith("[")) {
|
|
266
|
+
if (token.includes("{{var:")) throw new Error("Variables cannot replace SQL field names.");
|
|
267
|
+
return token;
|
|
268
|
+
}
|
|
269
|
+
return token.replace(/\{\{var:[A-Za-z_][A-Za-z0-9_]*\}\}/g, (reference) => String(resolveVariableValue(reference, variables) ?? "").replace(/'/g, "''"));
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
function resolveRequestVariables(body) {
|
|
273
|
+
const values = body.variables ?? {};
|
|
274
|
+
return {
|
|
275
|
+
...body,
|
|
276
|
+
chartFilters: resolveFilterVariables(body.chartFilters?.map((filter) => {
|
|
277
|
+
const global = filter.bindToGlobalId && body.globalFilters?.find((g) => g.id === filter.bindToGlobalId);
|
|
278
|
+
return global ? { ...filter, value: global.value, valueTo: global.valueTo, operator: global.operator } : filter;
|
|
279
|
+
}), values),
|
|
280
|
+
globalFilters: resolveFilterVariables(body.globalFilters, values),
|
|
281
|
+
query: {
|
|
282
|
+
...body.query,
|
|
283
|
+
where: resolveFilterVariables(body.query.where, values),
|
|
284
|
+
procedureParameters: body.query.procedureParameters && Object.fromEntries(
|
|
285
|
+
Object.entries(body.query.procedureParameters).map(([name, value]) => [
|
|
286
|
+
name,
|
|
287
|
+
value && typeof value === "object" && value.kind === "where" ? { ...value, filters: resolveFilterVariables(value.filters, values) } : resolveProcedureParameterValue(name, value, values)
|
|
288
|
+
])
|
|
289
|
+
)
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
function resolveDashboardVariables(dashboard, predefined = [], runtime = {}) {
|
|
294
|
+
const result = {};
|
|
295
|
+
const definitions = [...(dashboard.variables ?? []).filter((v) => !predefined.some((p) => p.name === v.name)), ...predefined];
|
|
296
|
+
const seen = /* @__PURE__ */ new Set();
|
|
297
|
+
for (const variable of definitions) {
|
|
298
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(variable.name)) throw new Error(`Invalid variable name: ${variable.name}`);
|
|
299
|
+
if (seen.has(variable.name)) throw new Error(`Duplicate variable name: ${variable.name}`);
|
|
300
|
+
seen.add(variable.name);
|
|
301
|
+
let value = variable.defaultValue;
|
|
302
|
+
if (predefined.some((p) => p.name === variable.name) && Object.prototype.hasOwnProperty.call(dashboard.variableDefaults ?? {}, variable.name))
|
|
303
|
+
value = dashboard.variableDefaults[variable.name];
|
|
304
|
+
if (Object.prototype.hasOwnProperty.call(runtime, variable.name)) value = runtime[variable.name];
|
|
305
|
+
if (value === void 0) continue;
|
|
306
|
+
if (value !== null && typeof value !== variable.type) throw new Error(`Variable "${variable.name}" must be ${variable.type}.`);
|
|
307
|
+
if (typeof value === "number" && !Number.isFinite(value)) throw new Error(`Variable "${variable.name}" must be a finite number.`);
|
|
308
|
+
Object.defineProperty(result, variable.name, { value, enumerable: true, configurable: true });
|
|
309
|
+
}
|
|
310
|
+
return result;
|
|
311
|
+
}
|
|
176
312
|
var WIDGET_TYPES = [
|
|
313
|
+
"timeline",
|
|
177
314
|
"bar",
|
|
178
315
|
"line",
|
|
179
316
|
"pie",
|
|
@@ -283,7 +420,7 @@ function resolveLabelColumnKey(field, columns) {
|
|
|
283
420
|
}
|
|
284
421
|
return columns[0] || field || "";
|
|
285
422
|
}
|
|
286
|
-
function buildContainerLabelsFromQuery(rows, columns, dimensionField, template) {
|
|
423
|
+
function buildContainerLabelsFromQuery(rows, columns, dimensionField, template, drillDowns = []) {
|
|
287
424
|
const dim = resolveLabelColumnKey(dimensionField, columns);
|
|
288
425
|
if (!dim) return [];
|
|
289
426
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -294,14 +431,17 @@ function buildContainerLabelsFromQuery(rows, columns, dimensionField, template)
|
|
|
294
431
|
const text = String(raw);
|
|
295
432
|
if (seen.has(text)) continue;
|
|
296
433
|
seen.add(text);
|
|
297
|
-
const
|
|
434
|
+
const override = drillDowns.find((rule) => rule.value === text && (rule.field === dimensionField || rule.field === dim));
|
|
435
|
+
const targetDashboardId = override ? override.action === "dashboard" ? override.targetDashboardId : void 0 : template.targetDashboardId;
|
|
436
|
+
const titleTemplate = override ? override.drillTitle : template.drillTitle;
|
|
437
|
+
const drillTitle = titleTemplate ? titleTemplate.replace(/\{\{value\}\}/g, text) : text;
|
|
298
438
|
labels.push({
|
|
299
439
|
id: `query-${labels.length}-${text}`,
|
|
300
440
|
text,
|
|
301
441
|
color: template.color,
|
|
302
442
|
backgroundColor: template.backgroundColor,
|
|
303
443
|
fontSize: template.fontSize,
|
|
304
|
-
targetDashboardId
|
|
444
|
+
targetDashboardId,
|
|
305
445
|
drillTitle
|
|
306
446
|
});
|
|
307
447
|
}
|
|
@@ -480,6 +620,7 @@ export {
|
|
|
480
620
|
WIDGET_TYPES,
|
|
481
621
|
buildContainerLabelsFromQuery,
|
|
482
622
|
buildDashboardExportFile,
|
|
623
|
+
buildProcedureWhereClause,
|
|
483
624
|
cloneDashboardForImport,
|
|
484
625
|
createChartAxisGuideline,
|
|
485
626
|
createContainerLabelItem,
|
|
@@ -497,16 +638,23 @@ export {
|
|
|
497
638
|
normalizeChartAxisGuidelines,
|
|
498
639
|
normalizeContainerLabelTemplate,
|
|
499
640
|
normalizeContainerLabels,
|
|
641
|
+
normalizeQueryLabelDrillDowns,
|
|
500
642
|
parseDashboardImport,
|
|
643
|
+
parseStoredProcedureName,
|
|
501
644
|
resetContainerLabelItemStyles,
|
|
502
645
|
resetContainerLabelTemplateStyles,
|
|
503
646
|
resolveDashboardDir,
|
|
504
647
|
resolveDashboardTheme,
|
|
648
|
+
resolveDashboardVariables,
|
|
505
649
|
resolveDisplayOptions,
|
|
506
650
|
resolveEmailOptions,
|
|
507
651
|
resolveExportOptions,
|
|
652
|
+
resolveFilterVariables,
|
|
508
653
|
resolveLabelClickAction,
|
|
509
654
|
resolveLabelContainerSource,
|
|
655
|
+
resolveProcedureParameterValue,
|
|
656
|
+
resolveRequestVariables,
|
|
657
|
+
resolveVariableValue,
|
|
510
658
|
sanitizeLabelStyleBackground,
|
|
511
659
|
sanitizeLabelStyleColor
|
|
512
660
|
};
|