From 40f0da90db5fe47ba1453a93352ae085d385f2bf Mon Sep 17 00:00:00 2001 From: MGJamJam Date: Fri, 3 May 2024 11:52:07 -0300 Subject: [PATCH] implements groupBy selection --- .../src/components/GroupByInput.tsx | 22 ++++++ .../src/components/GroupByRow.tsx | 69 +++++++++++++++++++ .../src/components/QueryEditor.tsx | 21 ++++-- .../src/datasource.ts | 4 +- bitmovin-analytics-datasource/src/types.ts | 1 + 5 files changed, 109 insertions(+), 8 deletions(-) create mode 100644 bitmovin-analytics-datasource/src/components/GroupByInput.tsx create mode 100644 bitmovin-analytics-datasource/src/components/GroupByRow.tsx diff --git a/bitmovin-analytics-datasource/src/components/GroupByInput.tsx b/bitmovin-analytics-datasource/src/components/GroupByInput.tsx new file mode 100644 index 0000000..b0d3588 --- /dev/null +++ b/bitmovin-analytics-datasource/src/components/GroupByInput.tsx @@ -0,0 +1,22 @@ +import React from 'react'; +import { HorizontalGroup, IconButton, Select } from '@grafana/ui'; +import { QueryAttribute } from '../types/queryAttributes'; +import { QueryAdAttribute } from '../types/queryAdAttributes'; +import { SelectableValue } from '@grafana/data'; + +type Props = { + groupBy: SelectableValue; + selectableGroupBys: Array>; + onDelete: () => void; + onChange: (newValue: SelectableValue) => void; +}; +export function GroupByInput(props: Props) { + //TODOMY delete margin between select and icon + //TODOMY border around the icon + return ( + + onIntervalChange(item)} - width={40} + width={30} options={SELECTABLE_QUERY_INTERVALS} /> @@ -103,7 +109,7 @@ export function QueryEditor({ query, onChange, onRunQuery, datasource }: Props) > + + + diff --git a/bitmovin-analytics-datasource/src/datasource.ts b/bitmovin-analytics-datasource/src/datasource.ts index 54f3027..db37e2d 100644 --- a/bitmovin-analytics-datasource/src/datasource.ts +++ b/bitmovin-analytics-datasource/src/datasource.ts @@ -19,7 +19,7 @@ import { Aggregation } from './types/aggregations'; type AnalyticsQuery = { filters: Array<{ name: string; operator: string; value: number }>; - groupBy: string[]; + groupBy: QueryAttribute[] | QueryAdAttribute[]; orderBy: Array<{ name: string; order: string }>; dimension?: QueryAttribute | QueryAdAttribute; metric?: Metric; @@ -71,7 +71,7 @@ export class DataSource extends DataSourceApi { value: 0, }, ], - groupBy: [], + groupBy: target.groupBy, orderBy: interval ? [ { diff --git a/bitmovin-analytics-datasource/src/types.ts b/bitmovin-analytics-datasource/src/types.ts index d53deec..a25440d 100644 --- a/bitmovin-analytics-datasource/src/types.ts +++ b/bitmovin-analytics-datasource/src/types.ts @@ -12,6 +12,7 @@ export interface MyQuery extends DataQuery { aggregation?: Aggregation; metric?: Metric; dimension?: QueryAttribute | QueryAdAttribute; + groupBy: QueryAttribute[] | QueryAdAttribute[]; } export const DEFAULT_QUERY: Partial = {};