-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat/AN-4110 implement group by selection (#68)
* implements license fetching and interval selection * add tests for intervalUtils * fix ceiling of timestamp for DAY interval * add tests * fix linting * delete unnecessary export of enum * implement metric selection * implement dimension selection * fix linting errors * add metric support * add metric to query and check for null instead of undefined * implements groupBy selection * fix linting * implements reordering of GroupBys and fixes position of Add Button * make props readonly
- Loading branch information
Showing
5 changed files
with
154 additions
and
8 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
bitmovin-analytics-datasource/src/components/GroupByInput.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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import React from 'react'; | ||
import { SelectableValue } from '@grafana/data'; | ||
import { HorizontalGroup, IconButton, Select } from '@grafana/ui'; | ||
|
||
import { QueryAttribute } from '../types/queryAttributes'; | ||
import { QueryAdAttribute } from '../types/queryAdAttributes'; | ||
|
||
export enum REORDER_DIRECTION { | ||
UP, | ||
DOWN, | ||
} | ||
|
||
type Props = { | ||
readonly groupBy: SelectableValue<QueryAttribute | QueryAdAttribute>; | ||
readonly selectableGroupBys: Array<SelectableValue<QueryAttribute | QueryAdAttribute>>; | ||
readonly onDelete: () => void; | ||
readonly onChange: (newValue: SelectableValue<QueryAdAttribute | QueryAttribute>) => void; | ||
readonly isFirst: boolean; | ||
readonly isLast: boolean; | ||
readonly onReorderGroupBy: (direction: REORDER_DIRECTION) => void; | ||
}; | ||
|
||
export function GroupByInput(props: Props) { | ||
return ( | ||
<HorizontalGroup> | ||
<Select value={props.groupBy} onChange={props.onChange} options={props.selectableGroupBys} width={30} /> | ||
<IconButton | ||
tooltip="Move down" | ||
onClick={() => props.onReorderGroupBy(REORDER_DIRECTION.DOWN)} | ||
name="arrow-down" | ||
disabled={props.isLast} | ||
/> | ||
<IconButton | ||
tooltip="Move up" | ||
onClick={() => props.onReorderGroupBy(REORDER_DIRECTION.UP)} | ||
name="arrow-up" | ||
disabled={props.isFirst} | ||
/> | ||
<IconButton | ||
tooltip="Delete Group By" | ||
name="trash-alt" | ||
onClick={() => props.onDelete()} | ||
size="lg" | ||
variant="destructive" | ||
/> | ||
</HorizontalGroup> | ||
); | ||
} |
88 changes: 88 additions & 0 deletions
88
bitmovin-analytics-datasource/src/components/GroupByRow.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 |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import React, { useState } from 'react'; | ||
import { SelectableValue } from '@grafana/data'; | ||
import { Box, IconButton, VerticalGroup } from '@grafana/ui'; | ||
import { difference } from 'lodash'; | ||
|
||
import { QueryAdAttribute, SELECTABLE_QUERY_AD_ATTRIBUTES } from '../types/queryAdAttributes'; | ||
import { QueryAttribute, SELECTABLE_QUERY_ATTRIBUTES } from '../types/queryAttributes'; | ||
import { GroupByInput, REORDER_DIRECTION } from './GroupByInput'; | ||
|
||
type Props = { | ||
readonly isAdAnalytics: boolean; | ||
readonly onChange: (newGroupBys: QueryAdAttribute[] | QueryAttribute[]) => void; | ||
}; | ||
|
||
export function GroupByRow(props: Props) { | ||
const [selectedGroupBys, setSelectedGroupBys] = useState<Array<SelectableValue<QueryAdAttribute | QueryAttribute>>>( | ||
[] | ||
); | ||
|
||
const mapGroupBysToSelectableValue = (): Array<SelectableValue<QueryAttribute | QueryAdAttribute>> => { | ||
if (props.isAdAnalytics) { | ||
return difference(SELECTABLE_QUERY_AD_ATTRIBUTES, selectedGroupBys); | ||
} else { | ||
return difference(SELECTABLE_QUERY_ATTRIBUTES, selectedGroupBys); | ||
} | ||
}; | ||
|
||
const deleteGroupByInput = (index: number) => { | ||
const newSelectedGroupBys = [...selectedGroupBys]; | ||
newSelectedGroupBys.splice(index, 1); | ||
|
||
setSelectedGroupBys(newSelectedGroupBys); | ||
|
||
const groupBys = newSelectedGroupBys.map((groupBy) => groupBy.value); | ||
props.onChange(groupBys as QueryAttribute[] | QueryAdAttribute[]); | ||
}; | ||
|
||
const onSelectedGroupByChange = ( | ||
index: number, | ||
newSelectedGroupBy: SelectableValue<QueryAttribute | QueryAdAttribute> | ||
) => { | ||
const newSelectedGroupBys = [...selectedGroupBys]; | ||
newSelectedGroupBys.splice(index, 1, newSelectedGroupBy); | ||
setSelectedGroupBys(newSelectedGroupBys); | ||
|
||
const groupBys = newSelectedGroupBys.map((groupBy) => groupBy.value); | ||
props.onChange(groupBys as QueryAttribute[] | QueryAdAttribute[]); | ||
}; | ||
|
||
const reorderGroupBy = (direction: REORDER_DIRECTION, index: number) => { | ||
const newSelectedGroupBys = [...selectedGroupBys]; | ||
const groupByToMove = newSelectedGroupBys[index]; | ||
newSelectedGroupBys.splice(index, 1); | ||
|
||
const newIndex = direction === REORDER_DIRECTION.UP ? index - 1 : index + 1; | ||
newSelectedGroupBys.splice(newIndex, 0, groupByToMove); | ||
setSelectedGroupBys(newSelectedGroupBys); | ||
|
||
const groupBys = newSelectedGroupBys.map((groupBy) => groupBy.value); | ||
props.onChange(groupBys as QueryAttribute[] | QueryAdAttribute[]); | ||
}; | ||
|
||
const addGroupByInput = () => { | ||
setSelectedGroupBys((prevState) => [...prevState, { name: '', label: '' }]); | ||
}; | ||
|
||
return ( | ||
<VerticalGroup> | ||
{selectedGroupBys?.map((item, index, groupBys) => ( | ||
<GroupByInput | ||
key={index} | ||
groupBy={item} | ||
onChange={(newValue: SelectableValue<QueryAdAttribute | QueryAttribute>) => | ||
onSelectedGroupByChange(index, newValue) | ||
} | ||
selectableGroupBys={mapGroupBysToSelectableValue()} | ||
onDelete={() => deleteGroupByInput(index)} | ||
isFirst={index === 0} | ||
isLast={index === groupBys.length - 1} | ||
onReorderGroupBy={(direction: REORDER_DIRECTION) => reorderGroupBy(direction, index)} | ||
/> | ||
))} | ||
<Box paddingTop={selectedGroupBys.length === 0 ? 0.5 : 0}> | ||
<IconButton name="plus-square" tooltip="Add Group By" onClick={() => addGroupByInput()} size="xxl" /> | ||
</Box> | ||
</VerticalGroup> | ||
); | ||
} |
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
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