-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/AN-4041 implement license and interval selection #64
Merged
MGJamJam
merged 8 commits into
migrate-to-react
from
feat/AN-4041_implement-license-selection
May 6, 2024
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
33a6c7d
implements license fetching and interval selection
MGJamJam cf28b72
add tests for intervalUtils
MGJamJam b332c7d
fix ceiling of timestamp for DAY interval
MGJamJam 5a52579
add tests
MGJamJam 37423e7
fix linting
MGJamJam af16116
delete unnecessary export of enum
MGJamJam f2661aa
rename MyQuery to BitmovinAnalyticsDataQuery
MGJamJam 21b9e39
add AnalyticsLicenseType
MGJamJam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
99 changes: 83 additions & 16 deletions
99
bitmovin-analytics-datasource/src/components/QueryEditor.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,99 @@ | ||
import React, { ChangeEvent } from 'react'; | ||
import { InlineField, Input } from '@grafana/ui'; | ||
import { QueryEditorProps } from '@grafana/data'; | ||
import React, { ChangeEvent, useEffect, useState } from 'react'; | ||
import { FieldSet, InlineField, InlineSwitch, Select } from '@grafana/ui'; | ||
import { QueryEditorProps, SelectableValue } from '@grafana/data'; | ||
|
||
import { DataSource } from '../datasource'; | ||
import { MyDataSourceOptions, MyQuery } from '../types'; | ||
import { fetchLicenses } from '../utils/licenses'; | ||
import { DEFAULT_SELECTABLE_QUERY_INTERVAL, SELECTABLE_QUERY_INTERVALS } from '../utils/intervalUtils'; | ||
|
||
enum LoadingState { | ||
Default = 'DEFAULT', | ||
Loading = 'LOADING', | ||
Success = 'SUCCESS', | ||
Error = 'ERROR', | ||
} | ||
|
||
type Props = QueryEditorProps<DataSource, MyQuery, MyDataSourceOptions>; | ||
|
||
export function QueryEditor({ query, onChange, onRunQuery }: Props) { | ||
const onQueryTextChange = (event: ChangeEvent<HTMLInputElement>) => { | ||
onChange({ ...query, queryText: event.target.value }); | ||
export function QueryEditor({ query, onChange, onRunQuery, datasource }: Props) { | ||
const [selectableLicenses, setSelectableLicenses] = useState<SelectableValue[]>([]); | ||
const [licenseLoadingState, setLicenseLoadingState] = useState<LoadingState>(LoadingState.Default); | ||
const [licenseErrorMessage, setLicenseErrorMessage] = useState(''); | ||
const [isTimeSeries, setIsTimeSeries] = useState(true); | ||
|
||
useEffect(() => { | ||
setLicenseLoadingState(LoadingState.Loading); | ||
fetchLicenses(datasource.apiKey, datasource.baseUrl) | ||
.then((licenses) => { | ||
setSelectableLicenses(licenses); | ||
setLicenseLoadingState(LoadingState.Success); | ||
}) | ||
.catch((e) => { | ||
setLicenseLoadingState(LoadingState.Error); | ||
setLicenseErrorMessage(e.status + ' ' + e.statusText); | ||
}); | ||
}, [datasource.apiKey, datasource.baseUrl]); | ||
|
||
const onLicenseChange = (item: SelectableValue) => { | ||
onChange({ ...query, licenseKey: item.value }); | ||
onRunQuery(); | ||
}; | ||
|
||
const onConstantChange = (event: ChangeEvent<HTMLInputElement>) => { | ||
onChange({ ...query, constant: parseFloat(event.target.value) }); | ||
// executes the query | ||
const onFormatAsTimeSeriesChange = (event: ChangeEvent<HTMLInputElement>) => { | ||
setIsTimeSeries(event.currentTarget.checked); | ||
if (event.currentTarget.checked) { | ||
onChange({ ...query, interval: 'AUTO' }); | ||
} else { | ||
onChange({ ...query, interval: undefined }); | ||
} | ||
onRunQuery(); | ||
}; | ||
|
||
const { queryText, constant } = query; | ||
const onIntervalChange = (item: SelectableValue) => { | ||
onChange({ ...query, interval: item.value }); | ||
onRunQuery(); | ||
}; | ||
|
||
const renderTimeSeriesOption = () => { | ||
return ( | ||
<> | ||
<InlineField label="Interval" labelWidth={20}> | ||
<Select | ||
defaultValue={DEFAULT_SELECTABLE_QUERY_INTERVAL} | ||
onChange={(item) => onIntervalChange(item)} | ||
width={40} | ||
options={SELECTABLE_QUERY_INTERVALS} | ||
/> | ||
</InlineField> | ||
</> | ||
); | ||
}; | ||
|
||
return ( | ||
<div className="gf-form"> | ||
<InlineField label="Constant"> | ||
<Input onChange={onConstantChange} value={constant} width={8} type="number" step="0.1" /> | ||
</InlineField> | ||
<InlineField label="Query Text" labelWidth={16} tooltip="Not used yet"> | ||
<Input onChange={onQueryTextChange} value={queryText || ''} /> | ||
</InlineField> | ||
<FieldSet> | ||
<InlineField | ||
label="License" | ||
labelWidth={20} | ||
invalid={licenseLoadingState === LoadingState.Error} | ||
error={`Error when fetching Analytics Licenses: ${licenseErrorMessage}`} | ||
disabled={licenseLoadingState === LoadingState.Error} | ||
> | ||
<Select | ||
onChange={onLicenseChange} | ||
width={40} | ||
options={selectableLicenses} | ||
noOptionsMessage="No Analytics Licenses found" | ||
isLoading={licenseLoadingState === LoadingState.Loading} | ||
placeholder={licenseLoadingState === LoadingState.Loading ? 'Loading Licenses' : 'Choose License'} | ||
/> | ||
</InlineField> | ||
<InlineField label="Format as time series" labelWidth={20}> | ||
<InlineSwitch value={isTimeSeries} onChange={onFormatAsTimeSeriesChange}></InlineSwitch> | ||
</InlineField> | ||
{isTimeSeries && renderTimeSeriesOption()} | ||
</FieldSet> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,13 @@ | ||
import { DataSourceJsonData } from '@grafana/data'; | ||
import { DataQuery } from '@grafana/schema'; | ||
import { QueryInterval } from './utils/intervalUtils'; | ||
|
||
export interface MyQuery extends DataQuery { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe instead of name |
||
queryText?: string; | ||
constant: number; | ||
licenseKey: string; | ||
interval?: QueryInterval | 'AUTO'; | ||
} | ||
|
||
export const DEFAULT_QUERY: Partial<MyQuery> = { | ||
constant: 6.5, | ||
}; | ||
export const DEFAULT_QUERY: Partial<MyQuery> = {}; | ||
|
||
/** | ||
* These are options configured for each DataSource instance | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe a comment why is this one filter included always by default ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's just temporary, I put it in for testing the editor. As soon as the filter selection implementation is ready this will be substituted by the filter selection value.