Skip to content

Commit fbeaf15

Browse files
fix: preserve quantile level in dashboard UI export (#1735)
Reorder RootValueExpressionSchema Zod union branches so the quantile/histogram branch (with required `level` field) is checked before the general branch. Previously, `aggFn: 'quantile'` matched the general branch first, causing `level` to be stripped during schema parsing. Fixes #1734
1 parent 69f0b48 commit fbeaf15

2 files changed

Lines changed: 61 additions & 7 deletions

File tree

packages/common-utils/src/__tests__/utils.test.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,60 @@ describe('utils', () => {
683683
],
684684
});
685685
});
686+
687+
it('should preserve level property for quantile aggFn in select', () => {
688+
const dashboard: z.infer<typeof DashboardSchema> = {
689+
id: 'dashboard1',
690+
name: 'Quantile Dashboard',
691+
tags: [],
692+
tiles: [
693+
{
694+
id: 'tile1',
695+
config: {
696+
name: 'P95 Latency',
697+
source: 'source1',
698+
select: [
699+
{
700+
aggFn: 'quantile',
701+
level: 0.95,
702+
aggCondition: '',
703+
aggConditionLanguage: 'lucene',
704+
valueExpression: 'Duration',
705+
},
706+
],
707+
where: '',
708+
},
709+
x: 0,
710+
y: 0,
711+
w: 6,
712+
h: 6,
713+
},
714+
],
715+
};
716+
717+
const sources: TSourceUnion[] = [
718+
{
719+
id: 'source1',
720+
name: 'Logs',
721+
connection: 'connection1',
722+
kind: SourceKind.Log,
723+
from: {
724+
databaseName: 'db1',
725+
tableName: 'logs_table',
726+
},
727+
timestampValueExpression: 'Timestamp',
728+
defaultTableSelectExpression: '',
729+
},
730+
];
731+
732+
const template = convertToDashboardTemplate(dashboard, sources);
733+
const selectList = template.tiles[0].config.select;
734+
expect(Array.isArray(selectList)).toBe(true);
735+
expect((selectList as any[])[0]).toMatchObject({
736+
aggFn: 'quantile',
737+
level: 0.95,
738+
});
739+
});
686740
});
687741

688742
describe('isJsonExpression', () => {

packages/common-utils/src/types.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,12 @@ export const AggregateFunctionWithCombinatorsSchema = z
7777
export const RootValueExpressionSchema = z
7878
.object({
7979
aggFn: z.union([
80-
AggregateFunctionSchema,
81-
AggregateFunctionWithCombinatorsSchema,
80+
z.literal('quantile'),
81+
z.literal('quantileMerge'),
82+
z.literal('histogram'),
83+
z.literal('histogramMerge'),
8284
]),
85+
level: z.number(),
8386
aggCondition: SearchConditionSchema,
8487
aggConditionLanguage: SearchConditionLanguageSchema,
8588
valueExpression: z.string(),
@@ -89,12 +92,9 @@ export const RootValueExpressionSchema = z
8992
.or(
9093
z.object({
9194
aggFn: z.union([
92-
z.literal('quantile'),
93-
z.literal('quantileMerge'),
94-
z.literal('histogram'),
95-
z.literal('histogramMerge'),
95+
AggregateFunctionSchema,
96+
AggregateFunctionWithCombinatorsSchema,
9697
]),
97-
level: z.number(),
9898
aggCondition: SearchConditionSchema,
9999
aggConditionLanguage: SearchConditionLanguageSchema,
100100
valueExpression: z.string(),

0 commit comments

Comments
 (0)