Skip to content

Commit

Permalink
rename QueryFilter types
Browse files Browse the repository at this point in the history
  • Loading branch information
MGJamJam committed Jun 26, 2024
1 parent e6926f2 commit 8dcf87c
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 24 deletions.
10 changes: 5 additions & 5 deletions bitmovin-analytics-datasource/src/components/FilterRow.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState } from 'react';
import { Box, HorizontalGroup, IconButton, InlineLabel, VerticalGroup } from '@grafana/ui';

import { InputQueryFilter } from '../types/queryFilter';
import { QueryFilter } from '../types/queryFilter';
import {
ATTRIBUTE_COMPONENT_WIDTH,
OPERATOR_COMPONENT_WIDTH,
Expand All @@ -11,8 +11,8 @@ import {

type Props = {
readonly isAdAnalytics: boolean;
readonly onQueryFilterChange: (newFilters: InputQueryFilter[]) => void;
readonly filters: InputQueryFilter[];
readonly onQueryFilterChange: (newFilters: QueryFilter[]) => void;
readonly filters: QueryFilter[];
};

export function FilterRow(props: Props) {
Expand All @@ -24,13 +24,13 @@ export function FilterRow(props: Props) {
props.onQueryFilterChange(newQueryFilters);
}

function handleQueryFilterChange(queryFilterIndex: number, changedQueryFilter: InputQueryFilter) {
function handleQueryFilterChange(queryFilterIndex: number, changedQueryFilter: QueryFilter) {
const newQueryFilters = [...props.filters];
newQueryFilters.splice(queryFilterIndex, 1, changedQueryFilter);
props.onQueryFilterChange(newQueryFilters);
}

function handleNewQueryFilterChange(newQueryFilter: InputQueryFilter) {
function handleNewQueryFilterChange(newQueryFilter: QueryFilter) {
const newQueryFilters = [...props.filters, newQueryFilter];
props.onQueryFilterChange(newQueryFilters);
setHasNewQueryFilter(false);
Expand Down
4 changes: 2 additions & 2 deletions bitmovin-analytics-datasource/src/components/QueryEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { isMetric, SELECTABLE_METRICS } from '../types/metric';
import { GroupByRow } from './GroupByRow';
import { OrderByRow } from './OrderByRow';
import type { QueryOrderBy } from '../types/queryOrderBy';
import type { InputQueryFilter } from '../types/queryFilter';
import type { QueryFilter } from '../types/queryFilter';
import { FilterRow } from './FilterRow';

enum LoadingState {
Expand Down Expand Up @@ -88,7 +88,7 @@ export function QueryEditor(props: Props) {
props.onRunQuery();
};

const handleQueryFilterChange = (newFilters: InputQueryFilter[]) => {
const handleQueryFilterChange = (newFilters: QueryFilter[]) => {
props.onChange({ ...query, filter: newFilters });
props.onRunQuery();
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useEffect, useMemo, useState } from 'react';
import { HorizontalGroup, IconButton, Input, Select, Tooltip } from '@grafana/ui';

import { InputQueryFilter, QueryFilterOperator, SELECTABLE_QUERY_FILTER_OPERATORS } from '../types/queryFilter';
import { QueryFilter, QueryFilterOperator, SELECTABLE_QUERY_FILTER_OPERATORS } from '../types/queryFilter';
import type { SelectableValue } from '@grafana/data';
import { QueryAttribute, SELECTABLE_QUERY_ATTRIBUTES } from '../types/queryAttributes';
import { QueryAdAttribute, SELECTABLE_QUERY_AD_ATTRIBUTES } from '../types/queryAdAttributes';
Expand All @@ -10,12 +10,12 @@ import { convertFilterValueToProperType } from 'utils/filterUtils';

interface QueryFilterInputProps {
/** `undefined` when component is used to create new filter (no values yet) */
value: undefined | InputQueryFilter;
onChange(queryFilter: InputQueryFilter): void;
value: undefined | QueryFilter;
onChange(queryFilter: QueryFilter): void;
onDelete(): void;
isAdAnalytics: boolean;
/** Selected query filters are used to filter out used values from attribute select options */
selectedQueryFilters: InputQueryFilter[];
selectedQueryFilters: QueryFilter[];
}

export function QueryFilterInput(props: Readonly<QueryFilterInputProps>) {
Expand Down Expand Up @@ -185,18 +185,18 @@ export const OPERATOR_COMPONENT_WIDTH = 15;
export const VALUE_COMPONENT_WIDTH = 30;

type DerivedQueryFilterState = {
attribute: undefined | InputQueryFilter['name'];
attribute: undefined | QueryFilter['name'];
attributeError: undefined | string;
operator: undefined | InputQueryFilter['operator'];
operator: undefined | QueryFilter['operator'];
operatorError: undefined | string;
value: undefined | InputQueryFilter['value'];
value: undefined | QueryFilter['value'];
/** `true` if some values have been changed by inputs */
dirty: boolean;
/** `undefined` when input value is valid */
inputValueError: undefined | string;
};

function buildInitialDerivedQueryFilterState(queryFilter: undefined | InputQueryFilter): DerivedQueryFilterState {
function buildInitialDerivedQueryFilterState(queryFilter: undefined | QueryFilter): DerivedQueryFilterState {
return {
attribute: queryFilter?.name,
attributeError: undefined,
Expand All @@ -209,7 +209,7 @@ function buildInitialDerivedQueryFilterState(queryFilter: undefined | InputQuery
}

function buildAttributeSelectableValues(
usedQueryFilters: InputQueryFilter[],
usedQueryFilters: QueryFilter[],
isAdAnalytics: boolean
): Array<SelectableValue<QueryAttribute | QueryAdAttribute>> {
const ALL_ATTRIBUTES: Array<SelectableValue<QueryAttribute | QueryAdAttribute>> = isAdAnalytics
Expand Down
6 changes: 3 additions & 3 deletions bitmovin-analytics-datasource/src/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
import { calculateQueryInterval, QueryInterval } from './utils/intervalUtils';
import { isMetric, Metric } from './types/metric';
import { AggregationMethod } from './types/aggregationMethod';
import { OutputQueryFilter } from './types/queryFilter';
import { ProperTypedQueryFilter } from './types/queryFilter';
import { QueryAttribute } from './types/queryAttributes';
import { QueryAdAttribute } from './types/queryAdAttributes';
import { QueryOrderBy } from './types/queryOrderBy';
Expand All @@ -38,7 +38,7 @@ type BitmovinAnalyticsRequestQuery = {
licenseKey: string;
start: Date;
end: Date;
filters: OutputQueryFilter[];
filters: ProperTypedQueryFilter[];
groupBy: Array<QueryAttribute | QueryAdAttribute>;
orderBy: QueryOrderBy[];
dimension?: QueryAttribute | QueryAdAttribute;
Expand Down Expand Up @@ -106,7 +106,7 @@ export class DataSource extends DataSourceApi<
}
}

const filters: OutputQueryFilter[] = target.filter.map((filter) => {
const filters: ProperTypedQueryFilter[] = target.filter.map((filter) => {
return {
name: filter.name,
operator: filter.operator,
Expand Down
6 changes: 3 additions & 3 deletions bitmovin-analytics-datasource/src/types/grafanaTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { QueryAttribute } from './queryAttributes';
import { QueryAdAttribute } from './queryAdAttributes';
import { Metric } from './metric';
import { QueryOrderBy } from './queryOrderBy';
import { InputQueryFilter } from './queryFilter';
import { QueryFilter } from './queryFilter';
import { AggregationMethod } from './aggregationMethod';

type ResultFormat = 'table' | 'time_series';
Expand All @@ -21,7 +21,7 @@ export interface BitmovinAnalyticsDataQuery extends DataQuery {
groupBy: Array<QueryAttribute | QueryAdAttribute>;
orderBy: QueryOrderBy[];
limit?: number;
filter: InputQueryFilter[];
filter: QueryFilter[];
alias?: string;
percentileValue?: number;
resultFormat: ResultFormat;
Expand All @@ -39,7 +39,7 @@ export interface OldBitmovinAnalyticsDataQuery extends DataQuery {
groupBy: Array<QueryAttribute | QueryAdAttribute>;
orderBy: QueryOrderBy[];
limit?: string;
filter: InputQueryFilter[];
filter: QueryFilter[];
alias?: string;
percentileValue: number;
resultFormat: ResultFormat;
Expand Down
4 changes: 2 additions & 2 deletions bitmovin-analytics-datasource/src/types/queryFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ export const SELECTABLE_QUERY_FILTER_OPERATORS: Array<SelectableValue<QueryFilte

/** This type is needed because of legacy reasons.
* In the angular plugin the value was saved as a string in a dashboard JSON file. */
export type InputQueryFilter = {
export type QueryFilter = {
name: QueryAdAttribute | QueryAttribute;
operator: QueryFilterOperator;
value: string;
};

/** QueryFilter type with the correct value type that is accepted by the Bitmovin API */
export type OutputQueryFilter = {
export type ProperTypedQueryFilter = {
name: QueryAdAttribute | QueryAttribute;
operator: QueryFilterOperator;
value: OutputQueryFilterValue;
Expand Down

0 comments on commit 8dcf87c

Please sign in to comment.