From 9e211e6968b79dd5979469c03d6d7f7ee897f588 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agn=C3=A8s=20Toulet?= Date: Fri, 2 Oct 2020 11:46:09 +0200 Subject: [PATCH 1/2] Add custom activity type support --- src/components/QueryEditor.tsx | 23 +++++++++++++++++++++-- src/datasource.ts | 22 +++++++++++++++------- src/types.ts | 1 + 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/src/components/QueryEditor.tsx b/src/components/QueryEditor.tsx index 365fc23..88b8e43 100644 --- a/src/components/QueryEditor.tsx +++ b/src/components/QueryEditor.tsx @@ -1,6 +1,6 @@ -import React, { PureComponent } from 'react'; +import React, { ChangeEvent, PureComponent } from 'react'; import { SelectableValue, QueryEditorProps } from '@grafana/data'; -import { InlineFormLabel, Select } from '@grafana/ui'; +import { InlineFormLabel, Input, Select } from '@grafana/ui'; import { StravaQuery, StravaQueryType, @@ -34,6 +34,7 @@ const stravaActivityTypeOptions: Array> = [ { value: 'Run', label: 'Run' }, { value: 'Ride', label: 'Ride' }, { value: 'Other', label: 'Other' }, + { value: 'Custom', label: 'Custom' }, ]; const FORMAT_OPTIONS: Array> = [ @@ -56,6 +57,7 @@ export const DefaultTarget: State = { athlete: {}, queryType: StravaQueryType.Activities, activityType: null, + customActivityType: '', activityStat: StravaActivityStat.Distance, format: StravaQueryFormat.TimeSeries, interval: StravaQueryInterval.Auto, @@ -74,6 +76,7 @@ export class QueryEditor extends PureComponent { format: StravaQueryFormat.TimeSeries, queryType: StravaQueryType.Activities, activityType: null, + customActivityType: '', activityStat: StravaActivityStat.Distance, }; @@ -123,6 +126,13 @@ export class QueryEditor extends PureComponent { } }; + onCustomActivityTypeChanged = (event: ChangeEvent) => { + const { query } = this.props; + if (event.target.value) { + this.onChange({ ...query, customActivityType: event.target.value }) + } + } + onFormatChange = (option: SelectableValue) => { const { query } = this.props; if (option.value) { @@ -145,6 +155,7 @@ export class QueryEditor extends PureComponent { render() { const { athlete } = this.state; + const { query } = this.props; return ( <> @@ -168,6 +179,14 @@ export class QueryEditor extends PureComponent { onChange={this.onActivityTypeChanged} className="gf-form-select" /> + { + this.getSelectedActivityType()?.value == 'Custom' && + () + } Stat