Skip to content

Commit

Permalink
Replace enums with const array of string (aggregations, metrics, quer…
Browse files Browse the repository at this point in the history
…y (ad) attributes, query filter operators) (#79)
  • Loading branch information
Svarozic authored Jun 20, 2024
1 parent b77e985 commit e612f20
Show file tree
Hide file tree
Showing 7 changed files with 437 additions and 778 deletions.
19 changes: 7 additions & 12 deletions bitmovin-analytics-datasource/src/types/aggregations.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import type { SelectableValue } from '@grafana/data';

export type Aggregation = 'count' | 'sum' | 'avg' | 'min' | 'max' | 'stddev' | 'percentile' | 'variance' | 'median';
const AGGREGATIONS = ['count', 'sum', 'avg', 'min', 'max', 'stddev', 'percentile', 'variance', 'median'] as const;

export const SELECTABLE_AGGREGATIONS: Array<SelectableValue<Aggregation>> = [
{ value: 'count', label: 'Count' },
{ value: 'sum', label: 'Sum' },
{ value: 'avg', label: 'Avg' },
{ value: 'min', label: 'Min' },
{ value: 'max', label: 'Max' },
{ value: 'stddev', label: 'Stddev' },
{ value: 'percentile', label: 'Percentile' },
{ value: 'variance', label: 'Variance' },
{ value: 'median', label: 'Median' },
];
export type Aggregation = (typeof AGGREGATIONS)[number];

export const SELECTABLE_AGGREGATIONS: Array<SelectableValue<Aggregation>> = AGGREGATIONS.map((aggregation) => ({
value: aggregation,
label: aggregation,
}));
21 changes: 8 additions & 13 deletions bitmovin-analytics-datasource/src/types/metric.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
import { SelectableValue } from '@grafana/data';

export enum METRICS {
AVG_CONCURRENTVIEWERS = 'avg-concurrentviewers',
MAX_CONCURRENTVIEWERS = 'max-concurrentviewers',
AVG_DROPPED_FRAMES = 'avg-dropped-frames',
}
const METRICS = ['avg-concurrentviewers', 'max-concurrentviewers', 'avg-dropped-frames'] as const;

export type Metric = (typeof METRICS)[keyof typeof METRICS];
export type Metric = (typeof METRICS)[number];

export const SELECTABLE_METRICS: Array<SelectableValue<Metric>> = [
{ value: METRICS.AVG_CONCURRENTVIEWERS, label: 'Avg Concurrent Viewers' },
{ value: METRICS.MAX_CONCURRENTVIEWERS, label: 'Max Concurrent Viewers' },
{ value: METRICS.AVG_DROPPED_FRAMES, label: 'Avg Dropped Frames' },
];
export const SELECTABLE_METRICS: Array<SelectableValue<Metric>> = METRICS.map((metric) => ({
value: metric,
label: metric,
}));

export const isMetric = (value: string): boolean => {
return Object.values(METRICS).includes(value as Metric);
export const isMetric = (value: string): value is Metric => {
return METRICS.includes(value as Metric);
};
Loading

0 comments on commit e612f20

Please sign in to comment.