Skip to content

Commit

Permalink
add migration for filters and table/timeseries options
Browse files Browse the repository at this point in the history
  • Loading branch information
MGJamJam committed Jun 19, 2024
1 parent 19d6ae3 commit f7e65d8
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
39 changes: 39 additions & 0 deletions bitmovin-analytics-datasource/src/components/QueryEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { OrderByRow } from './OrderByRow';
import type { QueryOrderBy } from '../types/queryOrderBy';
import type { QueryFilter } from '../types/queryFilter';
import { FilterRow } from './FilterRow';
import { convertFilterValueToProperType } from '../utils/filterUtils';

enum LoadingState {
Default = 'DEFAULT',
Expand Down Expand Up @@ -49,6 +50,44 @@ export function QueryEditor(props: Props) {
});
}, [props.datasource.apiKey, props.datasource.baseUrl]);

/**
* Ensures that dashboard JSON Models from the old Angular plugin are mapped correctly to the
* current model used by the application. Uses the {@link BitmovinAnalyticsDataQuery.resultFormat}
* as an indicator of whether an old JSON model was loaded.
*/
useEffect(() => {
if (props.query.resultFormat == null) return;
//TODO why is it not working for more than one queries in a dashboard? Why do I need to first reset to the ewnewst graph

// The old Angular plugin did the filter value conversion in the query method before
// sending the request, so the filter values saved in the old JSON model are the "raw"
// input values as strings. The new react plugin, however, saves the converted API conform filter
// values in the JSON model, as it converts the filter values in the `QueryInputFilter` component.
// This allows the new plugin to provide error feedback directly to the user via a tooltip before
// sending the request.
const convertedFilters = query.filter.map((filter) => {
return {
name: filter.name,
operator: filter.operator,
value: convertFilterValueToProperType(
filter.value as string,
filter.name,
filter.operator,
!!props.datasource.adAnalytics
),
} as QueryFilter;
});

let interval = props.query.interval;
if (props.query.resultFormat === 'table') {
setIsTimeSeries(false);
interval = undefined;
}

props.onChange({ ...props.query, filter: convertedFilters, interval: interval, resultFormat: undefined });
props.onRunQuery();
}, []);

const query = defaults(props.query, DEFAULT_QUERY);

const handleLicenseChange = (item: SelectableValue) => {
Expand Down
6 changes: 6 additions & 0 deletions bitmovin-analytics-datasource/src/types/grafanaTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ export interface BitmovinAnalyticsDataQuery extends DataQuery {
limit?: number;
filter: QueryFilter[];
alias?: string;
/**
* @deprecated This option is only used to migrate old Angular dashboards to the new React-based model.
* It serves as an indicator of whether an old Angular-based JSON model was loaded, as this option
* will only be set through the old plugin's logic. In the new React-based plugin, this option will always be undefined.
*/
resultFormat?: string;
}

export const DEFAULT_QUERY: Partial<BitmovinAnalyticsDataQuery> = {
Expand Down

0 comments on commit f7e65d8

Please sign in to comment.