-
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.
- Loading branch information
Showing
5 changed files
with
109 additions
and
8 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
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,22 @@ | ||
import React from 'react'; | ||
import { HorizontalGroup, IconButton, Select } from '@grafana/ui'; | ||
import { QueryAttribute } from '../types/queryAttributes'; | ||
import { QueryAdAttribute } from '../types/queryAdAttributes'; | ||
import { SelectableValue } from '@grafana/data'; | ||
|
||
type Props = { | ||
groupBy: SelectableValue<QueryAttribute | QueryAdAttribute>; | ||
selectableGroupBys: Array<SelectableValue<QueryAttribute | QueryAdAttribute>>; | ||
onDelete: () => void; | ||
onChange: (newValue: SelectableValue<QueryAdAttribute | QueryAttribute>) => void; | ||
}; | ||
export function GroupByInput(props: Props) { | ||
//TODOMY delete margin between select and icon | ||
//TODOMY border around the icon | ||
return ( | ||
<HorizontalGroup> | ||
<Select value={props.groupBy} onChange={props.onChange} options={props.selectableGroupBys} width={30} /> | ||
<IconButton tooltip="Delete Group By" name="trash-alt" onClick={() => props.onDelete()} size="lg" /> | ||
</HorizontalGroup> | ||
); | ||
} |
69 changes: 69 additions & 0 deletions
69
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,69 @@ | ||
import React, { useState } from 'react'; | ||
import { SelectableValue } from '@grafana/data'; | ||
import { QueryAdAttribute, SELECTABLE_QUERY_AD_ATTRIBUTES } from '../types/queryAdAttributes'; | ||
import { QueryAttribute, SELECTABLE_QUERY_ATTRIBUTES } from '../types/queryAttributes'; | ||
import { IconButton, Stack } from '@grafana/ui'; | ||
import { GroupByInput } from './GroupByInput'; | ||
import { difference } from 'lodash'; | ||
|
||
type Props = { | ||
readonly isAdAnalytics: boolean; | ||
readonly onChange: (newGroupBys: Array<QueryAdAttribute> | Array<QueryAttribute>) => void; | ||
Check failure on line 11 in bitmovin-analytics-datasource/src/components/GroupByRow.tsx GitHub Actions / build
|
||
}; | ||
|
||
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 Array<QueryAttribute> | Array<QueryAdAttribute>); | ||
Check failure on line 34 in bitmovin-analytics-datasource/src/components/GroupByRow.tsx GitHub Actions / build
|
||
}; | ||
|
||
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 Array<QueryAttribute> | Array<QueryAdAttribute>); | ||
Check failure on line 46 in bitmovin-analytics-datasource/src/components/GroupByRow.tsx GitHub Actions / build
|
||
}; | ||
|
||
const addGroupByInput = () => { | ||
setSelectedGroupBys((prevState) => [...prevState, { name: '', label: '' }]); | ||
}; | ||
|
||
//TODOMY fix the overflowing of a lot of selects are created, make it go to the next row | ||
return ( | ||
<Stack> | ||
{selectedGroupBys?.map((item, index) => ( | ||
<GroupByInput | ||
groupBy={item} | ||
onChange={(newValue: SelectableValue<QueryAdAttribute | QueryAttribute>) => | ||
onSelectedGroupByChange(index, newValue) | ||
} | ||
selectableGroupBys={mapGroupBysToSelectableValue()} | ||
onDelete={() => deleteGroupByInput(index)} | ||
/> | ||
))} | ||
<IconButton name="plus-square" tooltip="Add Group By" onClick={() => addGroupByInput()} size="xxl" /> | ||
</Stack> | ||
); | ||
} |
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