@dashboard-designer/core 0.1.15 → 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/dist/index.d.ts +53 -2
- package/dist/index.js +150 -3
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -39,6 +39,8 @@ interface FilterDef {
|
|
|
39
39
|
* When omitted, inferred from whether the field is an aggregated measure.
|
|
40
40
|
*/
|
|
41
41
|
clause?: 'where' | 'having';
|
|
42
|
+
/** Preserve an explicitly resolved empty variable value in SQL filters. */
|
|
43
|
+
allowEmptyValue?: boolean;
|
|
42
44
|
}
|
|
43
45
|
interface JoinDef {
|
|
44
46
|
id: string;
|
|
@@ -58,6 +60,8 @@ interface QueryDef {
|
|
|
58
60
|
connectionId: string;
|
|
59
61
|
/** When set, runs this SQL (with optional filter injection via {{filters}}) */
|
|
60
62
|
rawSql?: string;
|
|
63
|
+
/** Named inputs for a bare SQL Server EXEC call. Omitted keys use procedure defaults. */
|
|
64
|
+
procedureParameters?: Record<string, string | number | boolean | null | ProcedureWhereClause>;
|
|
61
65
|
tables?: string[];
|
|
62
66
|
joins?: JoinDef[];
|
|
63
67
|
columns?: QueryColumn[];
|
|
@@ -69,6 +73,21 @@ interface QueryDef {
|
|
|
69
73
|
}>;
|
|
70
74
|
limit?: number;
|
|
71
75
|
}
|
|
76
|
+
interface ProcedureParameter {
|
|
77
|
+
name: string;
|
|
78
|
+
type: string;
|
|
79
|
+
isOutput: boolean;
|
|
80
|
+
}
|
|
81
|
+
interface ProcedureWhereClause {
|
|
82
|
+
kind: 'where';
|
|
83
|
+
filters: FilterDef[];
|
|
84
|
+
/** Set false for procedures that expect predicates without the WHERE keyword. */
|
|
85
|
+
includeWhere?: boolean;
|
|
86
|
+
}
|
|
87
|
+
/** Build SQL Server clause text for a procedure's string parameter, not the EXEC statement. */
|
|
88
|
+
declare function buildProcedureWhereClause(value: ProcedureWhereClause): string;
|
|
89
|
+
/** Only a single, bare EXEC call is eligible for the parameter editor. */
|
|
90
|
+
declare function parseStoredProcedureName(sql?: string): string | undefined;
|
|
72
91
|
interface DataBinding {
|
|
73
92
|
dimensions: string[];
|
|
74
93
|
measures: string[];
|
|
@@ -99,6 +118,14 @@ interface ContainerLabelTemplate {
|
|
|
99
118
|
drillTitle?: string;
|
|
100
119
|
}
|
|
101
120
|
type LabelContainerSource = 'static' | 'query';
|
|
121
|
+
interface QueryLabelDrillDown {
|
|
122
|
+
field: string;
|
|
123
|
+
value: string;
|
|
124
|
+
action: 'none' | 'dashboard';
|
|
125
|
+
targetDashboardId?: string;
|
|
126
|
+
drillTitle?: string;
|
|
127
|
+
}
|
|
128
|
+
declare function normalizeQueryLabelDrillDowns(raw: unknown): QueryLabelDrillDown[];
|
|
102
129
|
type ContainerLabelLayout = 'vertical' | 'horizontal';
|
|
103
130
|
type ChartGuidelineAxis = 'x' | 'y';
|
|
104
131
|
/** Reference line on a bar or line chart axis. */
|
|
@@ -118,12 +145,17 @@ interface Widget {
|
|
|
118
145
|
binding: DataBinding;
|
|
119
146
|
chartOptions: Record<string, unknown>;
|
|
120
147
|
filters: FilterDef[];
|
|
148
|
+
/** Applied in the React client to returned rows, never sent as SQL conditions. */
|
|
149
|
+
frontendFilters?: FilterDef[];
|
|
121
150
|
drillDown?: DrillDownDef;
|
|
122
151
|
}
|
|
123
152
|
interface Dashboard {
|
|
124
153
|
id: string;
|
|
125
154
|
title: string;
|
|
126
155
|
description?: string;
|
|
156
|
+
variables?: DashboardVariable[];
|
|
157
|
+
/** Report-specific preview defaults for developer-defined variables. */
|
|
158
|
+
variableDefaults?: Record<string, VariableValue>;
|
|
127
159
|
locale?: string;
|
|
128
160
|
/** ISO 4217 currency code for number formatting (default USD). */
|
|
129
161
|
currency?: string;
|
|
@@ -273,16 +305,35 @@ interface AuthConfig {
|
|
|
273
305
|
token?: string;
|
|
274
306
|
}
|
|
275
307
|
interface QueryResult {
|
|
308
|
+
/** Server timestamp of the database fetch, preserved on cache hits. */
|
|
309
|
+
fetchedAt?: string;
|
|
276
310
|
columns: string[];
|
|
277
311
|
rows: Record<string, unknown>[];
|
|
278
312
|
rowCount: number;
|
|
279
313
|
durationMs: number;
|
|
280
314
|
}
|
|
281
315
|
interface ExecuteQueryRequest {
|
|
316
|
+
/** Bypass and replace the cached result for this query. */
|
|
317
|
+
refresh?: boolean;
|
|
318
|
+
dashboardId?: string;
|
|
282
319
|
query: QueryDef;
|
|
283
320
|
chartFilters?: FilterDef[];
|
|
284
321
|
globalFilters?: FilterDef[];
|
|
322
|
+
variables?: Record<string, VariableValue>;
|
|
323
|
+
}
|
|
324
|
+
type VariableValue = string | number | boolean | null;
|
|
325
|
+
interface DashboardVariable {
|
|
326
|
+
name: string;
|
|
327
|
+
type: 'string' | 'number' | 'boolean';
|
|
328
|
+
description?: string;
|
|
329
|
+
defaultValue?: VariableValue;
|
|
285
330
|
}
|
|
331
|
+
declare function resolveVariableValue(value: unknown, variables?: Record<string, VariableValue>): unknown;
|
|
332
|
+
declare function resolveFilterVariables(filters?: FilterDef[], variables?: Record<string, VariableValue>): FilterDef[];
|
|
333
|
+
/** Preserve ordinary parameter values; quote tokens embedded in SQL WHERE text. */
|
|
334
|
+
declare function resolveProcedureParameterValue(name: string, value: VariableValue, variables: Record<string, VariableValue>): VariableValue;
|
|
335
|
+
declare function resolveRequestVariables(body: ExecuteQueryRequest): ExecuteQueryRequest;
|
|
336
|
+
declare function resolveDashboardVariables(dashboard: Pick<Dashboard, 'variables' | 'variableDefaults'>, predefined?: DashboardVariable[], runtime?: Record<string, VariableValue>): Record<string, VariableValue>;
|
|
286
337
|
declare const WIDGET_TYPES: WidgetType[];
|
|
287
338
|
declare const DB_PROVIDERS: DbProvider[];
|
|
288
339
|
/** Locales that default to RTL when dashboard.dir is unset. */
|
|
@@ -302,7 +353,7 @@ declare function hasContainerLabelTemplateCustomStyles(template: ContainerLabelT
|
|
|
302
353
|
declare function resetContainerLabelTemplateStyles(template: ContainerLabelTemplate): ContainerLabelTemplate;
|
|
303
354
|
declare function resolveLabelContainerSource(chartOptions: Record<string, unknown>): LabelContainerSource;
|
|
304
355
|
/** 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[];
|
|
356
|
+
declare function buildContainerLabelsFromQuery(rows: Record<string, unknown>[], columns: string[], dimensionField: string | undefined, template: ContainerLabelTemplate, drillDowns?: QueryLabelDrillDown[]): ContainerLabelItem[];
|
|
306
357
|
/** Whether label / labelContainer widgets show the widget title bar on the canvas (default true). */
|
|
307
358
|
declare function labelWidgetShowsHeader(chartOptions: Record<string, unknown>): boolean;
|
|
308
359
|
type LabelClickAction = 'none' | 'dashboard' | 'url';
|
|
@@ -319,4 +370,4 @@ declare function createEmptyDashboard(partial?: Partial<Dashboard>): Dashboard;
|
|
|
319
370
|
declare function createEmptyWidget(type?: WidgetType): Widget;
|
|
320
371
|
declare function createId(): string;
|
|
321
372
|
|
|
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 };
|
|
373
|
+
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,6 +227,88 @@ 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 = [
|
|
177
313
|
"bar",
|
|
178
314
|
"line",
|
|
@@ -283,7 +419,7 @@ function resolveLabelColumnKey(field, columns) {
|
|
|
283
419
|
}
|
|
284
420
|
return columns[0] || field || "";
|
|
285
421
|
}
|
|
286
|
-
function buildContainerLabelsFromQuery(rows, columns, dimensionField, template) {
|
|
422
|
+
function buildContainerLabelsFromQuery(rows, columns, dimensionField, template, drillDowns = []) {
|
|
287
423
|
const dim = resolveLabelColumnKey(dimensionField, columns);
|
|
288
424
|
if (!dim) return [];
|
|
289
425
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -294,14 +430,17 @@ function buildContainerLabelsFromQuery(rows, columns, dimensionField, template)
|
|
|
294
430
|
const text = String(raw);
|
|
295
431
|
if (seen.has(text)) continue;
|
|
296
432
|
seen.add(text);
|
|
297
|
-
const
|
|
433
|
+
const override = drillDowns.find((rule) => rule.value === text && (rule.field === dimensionField || rule.field === dim));
|
|
434
|
+
const targetDashboardId = override ? override.action === "dashboard" ? override.targetDashboardId : void 0 : template.targetDashboardId;
|
|
435
|
+
const titleTemplate = override ? override.drillTitle : template.drillTitle;
|
|
436
|
+
const drillTitle = titleTemplate ? titleTemplate.replace(/\{\{value\}\}/g, text) : text;
|
|
298
437
|
labels.push({
|
|
299
438
|
id: `query-${labels.length}-${text}`,
|
|
300
439
|
text,
|
|
301
440
|
color: template.color,
|
|
302
441
|
backgroundColor: template.backgroundColor,
|
|
303
442
|
fontSize: template.fontSize,
|
|
304
|
-
targetDashboardId
|
|
443
|
+
targetDashboardId,
|
|
305
444
|
drillTitle
|
|
306
445
|
});
|
|
307
446
|
}
|
|
@@ -480,6 +619,7 @@ export {
|
|
|
480
619
|
WIDGET_TYPES,
|
|
481
620
|
buildContainerLabelsFromQuery,
|
|
482
621
|
buildDashboardExportFile,
|
|
622
|
+
buildProcedureWhereClause,
|
|
483
623
|
cloneDashboardForImport,
|
|
484
624
|
createChartAxisGuideline,
|
|
485
625
|
createContainerLabelItem,
|
|
@@ -497,16 +637,23 @@ export {
|
|
|
497
637
|
normalizeChartAxisGuidelines,
|
|
498
638
|
normalizeContainerLabelTemplate,
|
|
499
639
|
normalizeContainerLabels,
|
|
640
|
+
normalizeQueryLabelDrillDowns,
|
|
500
641
|
parseDashboardImport,
|
|
642
|
+
parseStoredProcedureName,
|
|
501
643
|
resetContainerLabelItemStyles,
|
|
502
644
|
resetContainerLabelTemplateStyles,
|
|
503
645
|
resolveDashboardDir,
|
|
504
646
|
resolveDashboardTheme,
|
|
647
|
+
resolveDashboardVariables,
|
|
505
648
|
resolveDisplayOptions,
|
|
506
649
|
resolveEmailOptions,
|
|
507
650
|
resolveExportOptions,
|
|
651
|
+
resolveFilterVariables,
|
|
508
652
|
resolveLabelClickAction,
|
|
509
653
|
resolveLabelContainerSource,
|
|
654
|
+
resolveProcedureParameterValue,
|
|
655
|
+
resolveRequestVariables,
|
|
656
|
+
resolveVariableValue,
|
|
510
657
|
sanitizeLabelStyleBackground,
|
|
511
658
|
sanitizeLabelStyleColor
|
|
512
659
|
};
|