diff --git a/packages/api/src/clickhouse/index.ts b/packages/api/src/clickhouse/index.ts index 1f0cd38a3..7add58cb4 100644 --- a/packages/api/src/clickhouse/index.ts +++ b/packages/api/src/clickhouse/index.ts @@ -1715,7 +1715,7 @@ export const getMultiSeriesChart = async ({ queries = await Promise.all( series.map(s => { - if (s.type != 'time' && s.type != 'table') { + if (s.type != 'time' && s.type != 'table' && s.type != 'number') { throw new Error(`Unsupported series type: ${s.type}`); } if (s.table != 'logs' && s.table != null) { @@ -1727,7 +1727,7 @@ export const getMultiSeriesChart = async ({ endTime, field: s.field, granularity, - groupBy: s.groupBy, + groupBy: s.type === 'number' ? [] : s.groupBy, propertyTypeMappingsModel, q: s.where, sortOrder: s.type === 'table' ? s.sortOrder : undefined, @@ -1746,7 +1746,7 @@ export const getMultiSeriesChart = async ({ queries = await Promise.all( series.map(s => { - if (s.type != 'time' && s.type != 'table') { + if (s.type != 'time' && s.type != 'table' && s.type != 'number') { throw new Error(`Unsupported series type: ${s.type}`); } if (s.table != 'metrics') { @@ -1764,13 +1764,13 @@ export const getMultiSeriesChart = async ({ endTime, name: s.field, granularity, - groupBy: s.groupBy, sortOrder: s.type === 'table' ? s.sortOrder : undefined, q: s.where, startTime, teamId, dataType: s.metricDataType, propertyTypeMappingsModel, + groupBy: s.type === 'number' ? [] : s.groupBy, }); }), ); diff --git a/packages/app/src/ChartUtils.tsx b/packages/app/src/ChartUtils.tsx index 6604c8703..18b761fb6 100644 --- a/packages/app/src/ChartUtils.tsx +++ b/packages/app/src/ChartUtils.tsx @@ -77,6 +77,23 @@ export enum Granularity { ThirtyDay = '30 day', } +export const GRANULARITY_SECONDS_MAP: Record = { + [Granularity.ThirtySecond]: 30, + [Granularity.OneMinute]: 60, + [Granularity.FiveMinute]: 5 * 60, + [Granularity.TenMinute]: 10 * 60, + [Granularity.FifteenMinute]: 15 * 60, + [Granularity.ThirtyMinute]: 30 * 60, + [Granularity.OneHour]: 60 * 60, + [Granularity.TwoHour]: 2 * 60 * 60, + [Granularity.SixHour]: 6 * 60 * 60, + [Granularity.TwelveHour]: 12 * 60 * 60, + [Granularity.OneDay]: 24 * 60 * 60, + [Granularity.TwoDay]: 2 * 24 * 60 * 60, + [Granularity.SevenDay]: 7 * 24 * 60 * 60, + [Granularity.ThirtyDay]: 30 * 24 * 60 * 60, +}; + export const isGranularity = (value: string): value is Granularity => { return Object.values(Granularity).includes(value as Granularity); }; diff --git a/packages/app/src/DashboardPage.tsx b/packages/app/src/DashboardPage.tsx index 81280b234..2c3458d77 100644 --- a/packages/app/src/DashboardPage.tsx +++ b/packages/app/src/DashboardPage.tsx @@ -189,12 +189,18 @@ const Tile = forwardRef( : type === 'number' ? { type, - table: chart.series[0].table ?? 'logs', - aggFn: chart.series[0].aggFn, field: chart.series[0].field ?? '', // TODO: Fix in definition - where: buildAndWhereClause(query, chart.series[0].where), - dateRange, numberFormat: chart.series[0].numberFormat, + series: chart.series.map(s => ({ + ...s, + where: buildAndWhereClause( + query, + s.type === 'number' ? s.where : '', + ), + })), + dateRange, + granularity: + granularity ?? convertDateRangeToGranularityString(dateRange, 60), } : { type, diff --git a/packages/app/src/EditChartForm.tsx b/packages/app/src/EditChartForm.tsx index 7c618c26a..4b3951535 100644 --- a/packages/app/src/EditChartForm.tsx +++ b/packages/app/src/EditChartForm.tsx @@ -370,12 +370,11 @@ export const EditNumberChartForm = ({ const chartConfig = useMemo(() => { return _editedChart != null && _editedChart.series[0].type === 'number' ? { - aggFn: _editedChart.series[0].aggFn ?? 'count', - table: _editedChart.series[0].table ?? 'logs', field: _editedChart.series[0].field ?? '', // TODO: Fix in definition - where: _editedChart.series[0].where, dateRange, numberFormat: _editedChart.series[0].numberFormat, + series: _editedChart.series, + granularity: convertDateRangeToGranularityString(dateRange, 60), } : null; }, [_editedChart, dateRange]); @@ -393,9 +392,6 @@ export const EditNumberChartForm = ({ return null; } - const labelWidth = 320; - const aggFn = _editedChart.series[0].aggFn ?? 'count'; - return (
{ @@ -419,105 +415,14 @@ export const EditNumberChartForm = ({ placeholder="Chart Name" /> -
-
- Aggregation Function -
-
-