Skip to content

Commit 055d498

Browse files
authored
feat(billing): Allow passing reserved, ondemand to usage chart (#69366)
1 parent 7549cbd commit 055d498

File tree

1 file changed

+26
-13
lines changed
  • static/app/views/organizationStats/usageChart

1 file changed

+26
-13
lines changed

static/app/views/organizationStats/usageChart/index.tsx

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,11 @@ export const CHART_OPTIONS_DATA_TRANSFORM: SelectValue<ChartDataTransform>[] = [
105105
},
106106
];
107107

108-
export enum SeriesTypes {
108+
const enum SeriesTypes {
109109
ACCEPTED = 'Accepted',
110110
DROPPED = 'Dropped',
111111
PROJECTED = 'Projected',
112+
RESERVED = 'Reserved',
112113
FILTERED = 'Filtered',
113114
}
114115

@@ -166,6 +167,7 @@ export type UsageChartProps = {
166167
* Display datetime in UTC
167168
*/
168169
usageDateShowUtc?: boolean;
170+
yAxisFormatter?: (val: number) => string;
169171
};
170172

171173
/**
@@ -181,6 +183,8 @@ const cumulativeTotalDataTransformation: UsageChartProps['handleDataTransformati
181183
dropped: [],
182184
projected: [],
183185
filtered: [],
186+
reserved: [],
187+
onDemand: [],
184188
};
185189
const isCumulative = transform === ChartDataTransform.CUMULATIVE;
186190

@@ -201,11 +205,20 @@ const cumulativeTotalDataTransformation: UsageChartProps['handleDataTransformati
201205
return chartData;
202206
};
203207

208+
const getUnitYaxisFormatter =
209+
(dataCategory: UsageChartProps['dataCategory']) => (val: number) =>
210+
formatUsageWithUnits(val, dataCategory, {
211+
isAbbreviated: true,
212+
useUnitScaling: true,
213+
});
214+
204215
export type ChartStats = {
205216
accepted: NonNullable<BarSeriesOption['data']>;
206217
dropped: NonNullable<BarSeriesOption['data']>;
207218
projected: NonNullable<BarSeriesOption['data']>;
208219
filtered?: NonNullable<BarSeriesOption['data']>;
220+
onDemand?: NonNullable<BarSeriesOption['data']>;
221+
reserved?: NonNullable<BarSeriesOption['data']>;
209222
};
210223

211224
function chartMetadata({
@@ -238,7 +251,6 @@ function chartMetadata({
238251
xAxisData: string[];
239252
xAxisLabelInterval: number;
240253
xAxisTickInterval: number;
241-
yAxisFormatter: (val: number) => string;
242254
yAxisMinInterval: number;
243255
} {
244256
const selectDataCategory = categoryOptions.find(o => o.value === dataCategory);
@@ -299,11 +311,6 @@ function chartMetadata({
299311
xAxisTickInterval,
300312
xAxisLabelInterval,
301313
yAxisMinInterval,
302-
yAxisFormatter: (val: number) =>
303-
formatUsageWithUnits(val, dataCategory, {
304-
isAbbreviated: true,
305-
useUnitScaling: true,
306-
}),
307314
tooltipValueFormatter: getTooltipFormatter(dataCategory),
308315
};
309316
}
@@ -337,6 +344,7 @@ function UsageChartBody({
337344
categoryOptions = CHART_OPTIONS_DATACATEGORY,
338345
usageDateInterval = '1d',
339346
usageDateShowUtc = true,
347+
yAxisFormatter,
340348
handleDataTransformation = cumulativeTotalDataTransformation,
341349
}: UsageChartProps) {
342350
const theme = useTheme();
@@ -361,14 +369,15 @@ function UsageChartBody({
361369
);
362370
}
363371

372+
const yAxisLabelFormatter = yAxisFormatter ?? getUnitYaxisFormatter(dataCategory);
373+
364374
const {
365375
chartData,
366376
tooltipValueFormatter,
367377
xAxisData,
368378
xAxisTickInterval,
369379
xAxisLabelInterval,
370380
yAxisMinInterval,
371-
yAxisFormatter,
372381
} = chartMetadata({
373382
categoryOptions,
374383
dataCategory,
@@ -383,9 +392,13 @@ function UsageChartBody({
383392

384393
function chartLegendData() {
385394
const legend: LegendComponentOption['data'] = [
386-
{
387-
name: SeriesTypes.ACCEPTED,
388-
},
395+
chartData.reserved && chartData.reserved.length > 0
396+
? {
397+
name: SeriesTypes.RESERVED,
398+
}
399+
: {
400+
name: SeriesTypes.ACCEPTED,
401+
},
389402
];
390403

391404
if (chartData.filtered && chartData.filtered.length > 0) {
@@ -454,7 +467,7 @@ function UsageChartBody({
454467
return (
455468
<BaseChart
456469
colors={colors}
457-
grid={{bottom: '3px', left: '0px', right: '10px', top: '40px'}}
470+
grid={{bottom: '3px', left: '3px', right: '10px', top: '40px'}}
458471
xAxis={xAxis({
459472
show: true,
460473
type: 'category',
@@ -474,7 +487,7 @@ function UsageChartBody({
474487
min: 0,
475488
minInterval: yAxisMinInterval,
476489
axisLabel: {
477-
formatter: yAxisFormatter,
490+
formatter: yAxisLabelFormatter,
478491
color: theme.chartLabel,
479492
},
480493
}}

0 commit comments

Comments
 (0)